Skip to content

Commit 1dee0cf

Browse files
authored
Merge pull request #160 from Alphix/ci-test-pr-148
CI: update tests to also check basic auth fallback
2 parents 6bae9ec + d455988 commit 1dee0cf

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

scripts/kerberos_ldap

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ LDAP_KADMIN_DN="uid=kadmin,${LDAP_KRB_DN}"
3131
LDAP_KADMIN_PW="kadmintest"
3232
LDAP_ADMIN_DN="cn=admin,${LDAP_BASE_DN}"
3333
LDAP_ADMIN_PW="test"
34+
KRB_BOB_PW="bob@BOB@123"
3435
KERBEROS_REALM="$(echo "${DOMAIN}" | tr "[:lower:]" "[:upper:]")"
3536
export LC_ALL=C
3637
export DEBIAN_FRONTEND=noninteractive
@@ -68,6 +69,7 @@ LDAP kadmin DN : ${LDAP_KADMIN_DN}
6869
LDAP kadmin PW : ${LDAP_KADMIN_PW}
6970
LDAP admin DN : ${LDAP_ADMIN_DN}
7071
LDAP admin PW : ${LDAP_ADMIN_PW}
72+
KRB bob PW : ${KRB_BOB_PW}
7173
==============================================================================
7274
EOF
7375

@@ -326,6 +328,7 @@ echo "OK"
326328
printf "Creating test user principals ... "
327329
kadmin.local -q "addprinc -randkey -policy defaultpol alice" > /dev/null || die
328330
kadmin.local -q "ktadd -k krb5.alice.keytab alice" > /dev/null || die
331+
kadmin.local -q "addprinc -pw ${KRB_BOB_PW} -policy defaultpol bob" > /dev/null || die
329332
kadmin.local -q "addprinc -randkey -policy defaultpol mallory" > /dev/null || die
330333
kadmin.local -q "ktadd -k krb5.mallory.keytab mallory" > /dev/null || die
331334
echo "OK"
@@ -416,6 +419,21 @@ server {
416419
auth_gss_service_ccache /tmp/krb5cc_nginx;
417420
}
418421
422+
location /fallback.php {
423+
include snippets/fastcgi-php.conf;
424+
fastcgi_pass unix:/run/php/php-fpm.sock;
425+
auth_gss on;
426+
auth_gss_realm ${KERBEROS_REALM};
427+
auth_gss_keytab /etc/krb5.http.keytab;
428+
auth_gss_service_name HTTP/${TEST_HOST_FQDN};
429+
auth_gss_allow_basic_fallback on;
430+
auth_gss_authorized_principal bob@${KERBEROS_REALM};
431+
auth_gss_format_full on;
432+
fastcgi_param HTTP_AUTHORIZATION "";
433+
fastcgi_param KRB5CCNAME \$krb5_cc_name;
434+
auth_gss_service_ccache /tmp/krb5cc_nginx;
435+
}
436+
419437
location /delegate.php {
420438
include snippets/fastcgi-php.conf;
421439
fastcgi_pass unix:/run/php/php-fpm.sock;
@@ -471,6 +489,23 @@ fi
471489
echo "OK"
472490

473491

492+
printf "Writing fallback.php ... "
493+
if ! cat <<'EOF' > /var/www/kerberos/fallback.php
494+
<?php
495+
if (!isset($_SERVER["REMOTE_USER"]) || $_SERVER["REMOTE_USER"] == "") {
496+
http_response_code(500);
497+
echo("REMOTE_USER not set");
498+
exit();
499+
}
500+
echo("Authenticated as " . $_SERVER["REMOTE_USER"]);
501+
?>
502+
EOF
503+
then
504+
die
505+
fi
506+
echo "OK"
507+
508+
474509
printf "Writing delegate.php ... "
475510
if ! cat <<EOF > /var/www/kerberos/delegate.php
476511
<?php
@@ -581,6 +616,46 @@ test_path()
581616
fi
582617
}
583618

619+
test_basic()
620+
{
621+
SUBURL="$1"
622+
EXPECT1="$2"
623+
EXPECT2="$3"
624+
625+
printf "curl %s, incorrect basic auth: http status (expect %s)=" "${SUBURL}" "${EXPECT1}"
626+
rm -f "${CURL_OUTPUT}"
627+
CODE="$($CURL_NONEGOTIATE -u "bob:InVaLiD" -w "%{http_code}" "http://${TEST_HOST_FQDN}:8080/${SUBURL}")" || true
628+
printf "%s ... " "${CODE}"
629+
if [ "$CODE" = "${EXPECT1}" ]; then
630+
echo "OK"
631+
else
632+
EX=1
633+
echo "FAILED"
634+
if [ -e "${CURL_OUTPUT}" ]; then
635+
echo "HTTP body:"
636+
cat "${CURL_OUTPUT}"
637+
echo ""
638+
fi
639+
fi
640+
641+
printf "curl %s, basic auth: http status (expect %s)=" "${SUBURL}" "${EXPECT2}"
642+
rm -f "${CURL_OUTPUT}"
643+
CODE="$($CURL_NONEGOTIATE -u "bob:${KRB_BOB_PW}" -w "%{http_code}" "http://${TEST_HOST_FQDN}:8080/${SUBURL}")" || true
644+
printf "%s ... " "${CODE}"
645+
if [ "$CODE" = "${EXPECT2}" ]; then
646+
echo "OK"
647+
else
648+
EX=1
649+
echo "FAILED"
650+
if [ -e "${CURL_OUTPUT}" ]; then
651+
echo "HTTP body:"
652+
cat "${CURL_OUTPUT}"
653+
echo ""
654+
fi
655+
fi
656+
657+
}
658+
584659
test_ldapwhoami()
585660
{
586661
LDAP_EXPECTED="dn:uid=${1},cn=gss-spnego,cn=auth"
@@ -606,6 +681,8 @@ test_ldapwhoami()
606681
printf "Destroying Kerberos tickets ... "
607682
kdestroy -q > /dev/null 2>&1 || true
608683
echo "OK"
684+
test_basic "fallback.php" 401 200
685+
test_path "fallback.php" 401 401
609686
test_path "noauth.php" 200 200
610687
test_path "auth.php" 401 401
611688
test_path "delegate.php" 401 401
@@ -619,6 +696,8 @@ else
619696
EX=1
620697
echo "FAILED"
621698
fi
699+
test_basic "fallback.php" 401 200
700+
test_path "fallback.php" 401 403
622701
test_path "noauth.php" 200 200
623702
test_path "auth.php" 401 200
624703
test_path "delegate.php" 401 200
@@ -634,6 +713,24 @@ else
634713
EX=1
635714
echo "FAILED"
636715
fi
716+
test_basic "fallback.php" 401 200
717+
test_path "fallback.php" 401 403
718+
test_path "noauth.php" 200 200
719+
test_path "auth.php" 401 403
720+
test_path "delegate.php" 401 403
721+
722+
723+
echo ""
724+
printf "Obtaining Kerberos ticket for bob ... "
725+
kdestroy -q > /dev/null 2>&1 || true
726+
if echo "${KRB_BOB_PW}" | kinit bob > /dev/null 2>&1; then
727+
echo "OK"
728+
else
729+
EX=1
730+
echo "FAILED"
731+
fi
732+
test_basic "fallback.php" 401 200
733+
test_path "fallback.php" 401 200
637734
test_path "noauth.php" 200 200
638735
test_path "auth.php" 401 403
639736
test_path "delegate.php" 401 403

0 commit comments

Comments
 (0)