@@ -580,4 +580,81 @@ test_expect_success 'passing hostname resolution information works' '
580580 git -c "http.curloptResolve=$BOGUS_HOST:$LIB_HTTPD_PORT:127.0.0.1" ls-remote "$BOGUS_HTTPD_URL/smart/repo.git" >/dev/null
581581'
582582
583+ # here user%40host is the URL-encoded version of user@host,
584+ # which is our intentionally-odd username to catch parsing errors
585+ url_user=$HTTPD_URL_USER /auth/smart/repo.git
586+ url_userpass=$HTTPD_URL_USER_PASS /auth/smart/repo.git
587+ url_userblank=$HTTPD_PROTO ://user%40host:@$HTTPD_DEST /auth/smart/repo.git
588+ message=" URL .*:<redacted>@.* uses plaintext credentials"
589+
590+ test_expect_success ' clone warns or fails when using username:password' '
591+ test_when_finished "rm -rf attempt*" &&
592+
593+ git -c transfer.credentialsInUrl=allow \
594+ clone $url_userpass attempt1 2>err &&
595+ ! grep "$message" err &&
596+
597+ git -c transfer.credentialsInUrl=warn \
598+ clone $url_userpass attempt2 2>err &&
599+ grep "warning: $message" err >warnings &&
600+ test_line_count -ge 1 warnings &&
601+
602+ test_must_fail git -c transfer.credentialsInUrl=die \
603+ clone $url_userpass attempt3 2>err &&
604+ grep "fatal: $message" err >warnings &&
605+ test_line_count -ge 1 warnings &&
606+
607+ test_must_fail git -c transfer.credentialsInUrl=die \
608+ clone $url_userblank attempt4 2>err &&
609+ grep "fatal: $message" err >warnings &&
610+ test_line_count -ge 1 warnings
611+ '
612+
613+ test_expect_success ' clone does not detect username:password when it is https://username@domain:port/' '
614+ test_when_finished "rm -rf attempt1" &&
615+
616+ # we are relying on lib-httpd for url construction, so document our
617+ # assumptions
618+ case "$HTTPD_URL_USER" in
619+ *:[0-9]*) : ok ;;
620+ *) BUG "httpd url does not have port: $HTTPD_URL_USER"
621+ esac &&
622+
623+ git -c transfer.credentialsInUrl=warn clone $url_user attempt1 2>err &&
624+ ! grep "uses plaintext credentials" err
625+ '
626+
627+ test_expect_success ' fetch warns or fails when using username:password' '
628+ git -c transfer.credentialsInUrl=allow fetch $url_userpass 2>err &&
629+ ! grep "$message" err &&
630+
631+ git -c transfer.credentialsInUrl=warn fetch $url_userpass 2>err &&
632+ grep "warning: $message" err >warnings &&
633+ test_line_count -ge 1 warnings &&
634+
635+ test_must_fail git -c transfer.credentialsInUrl=die \
636+ fetch $url_userpass 2>err &&
637+ grep "fatal: $message" err >warnings &&
638+ test_line_count -ge 1 warnings &&
639+
640+ test_must_fail git -c transfer.credentialsInUrl=die \
641+ fetch $url_userblank 2>err &&
642+ grep "fatal: $message" err >warnings &&
643+ test_line_count -ge 1 warnings
644+ '
645+
646+
647+ test_expect_success ' push warns or fails when using username:password' '
648+ git -c transfer.credentialsInUrl=allow push $url_userpass 2>err &&
649+ ! grep "$message" err &&
650+
651+ git -c transfer.credentialsInUrl=warn push $url_userpass 2>err &&
652+ grep "warning: $message" err >warnings &&
653+
654+ test_must_fail git -c transfer.credentialsInUrl=die \
655+ push $url_userpass 2>err &&
656+ grep "fatal: $message" err >warnings &&
657+ test_line_count -ge 1 warnings
658+ '
659+
583660test_done
0 commit comments