@@ -719,4 +719,107 @@ test_expect_success 'access using three-legged auth' '
719719 EOF
720720'
721721
722+ test_lazy_prereq NTLM ' curl --version | grep -q NTLM'
723+
724+ test_expect_success NTLM ' access using NTLM auth' '
725+ test_when_finished "per_test_cleanup" &&
726+
727+ set_credential_reply get <<-EOF &&
728+ username=user
729+ password=pwd
730+ EOF
731+
732+ test_config_global credential.helper test-helper &&
733+ test_must_fail env GIT_TRACE_CURL=1 git \
734+ ls-remote "$HTTPD_URL/ntlm_auth/repo.git" 2>err &&
735+ test_grep "allowNTLMAuth" err &&
736+
737+ # Can be enabled via config
738+ GIT_TRACE_CURL=1 git -c http.$HTTPD_URL.allowNTLMAuth=true \
739+ ls-remote "$HTTPD_URL/ntlm_auth/repo.git" &&
740+
741+ # Or via credential helper responding with ntlm=allow
742+ set_credential_reply get <<-EOF &&
743+ username=user
744+ password=pwd
745+ ntlm=allow
746+ EOF
747+
748+ git ls-remote "$HTTPD_URL/ntlm_auth/repo.git"
749+ '
750+
751+ test_lazy_prereq SPNEGO ' curl --version | grep -qi "SPNEGO\|GSS-API\|Kerberos\|negotiate"'
752+
753+ test_expect_success SPNEGO ' http.emptyAuth=auto attempts Negotiate before credential_fill' '
754+ test_when_finished "per_test_cleanup" &&
755+
756+ set_credential_reply get <<-EOF &&
757+ username=alice
758+ password=secret-passwd
759+ EOF
760+
761+ # Basic base64(alice:secret-passwd)
762+ cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
763+ id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
764+ EOF
765+
766+ cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
767+ id=1 status=200
768+ id=default response=WWW-Authenticate: Negotiate
769+ id=default response=WWW-Authenticate: Basic realm="example.com"
770+ EOF
771+
772+ test_config_global credential.helper test-helper &&
773+ GIT_TRACE_CURL="$TRASH_DIRECTORY/trace-auto" \
774+ git -c http.emptyAuth=auto \
775+ ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
776+
777+ # In auto mode with a Negotiate+Basic server, there should be
778+ # three 401 responses: (1) initial no-auth request, (2) empty-auth
779+ # retry where Negotiate fails (no Kerberos ticket), (3) libcurl
780+ # internal Negotiate retry. The fourth attempt uses Basic
781+ # credentials from credential_fill and succeeds.
782+ grep "HTTP/[0-9.]* 401" "$TRASH_DIRECTORY/trace-auto" >actual_401s &&
783+ test_line_count = 3 actual_401s &&
784+
785+ expect_credential_query get <<-EOF
786+ capability[]=authtype
787+ capability[]=state
788+ protocol=http
789+ host=$HTTPD_DEST
790+ wwwauth[]=Negotiate
791+ wwwauth[]=Basic realm="example.com"
792+ EOF
793+ '
794+
795+ test_expect_success SPNEGO ' http.emptyAuth=false skips Negotiate' '
796+ test_when_finished "per_test_cleanup" &&
797+
798+ set_credential_reply get <<-EOF &&
799+ username=alice
800+ password=secret-passwd
801+ EOF
802+
803+ # Basic base64(alice:secret-passwd)
804+ cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
805+ id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
806+ EOF
807+
808+ cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
809+ id=1 status=200
810+ id=default response=WWW-Authenticate: Negotiate
811+ id=default response=WWW-Authenticate: Basic realm="example.com"
812+ EOF
813+
814+ test_config_global credential.helper test-helper &&
815+ GIT_TRACE_CURL="$TRASH_DIRECTORY/trace-false" \
816+ git -c http.emptyAuth=false \
817+ ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
818+
819+ # With emptyAuth=false, Negotiate is stripped immediately and
820+ # credential_fill is called right away. Only one 401 response.
821+ grep "HTTP/[0-9.]* 401" "$TRASH_DIRECTORY/trace-false" >actual_401s &&
822+ test_line_count = 1 actual_401s
823+ '
824+
722825test_done
0 commit comments