Skip to content

Commit b694f1e

Browse files
peffgitster
authored andcommitted
t5551: test http interaction with credential helpers
We test authentication with http, and we independently test that credential helpers work, but we don't have any tests that cover the two features working together. Let's add two: 1. Make sure that a successful request asks the helper to save the credential. This works as expected. 2. Make sure that a failed request asks the helper to forget the credential. This is marked as expect_failure, as it was recently regressed by 1b0d954 (remote-curl: fall back to basic auth if Negotiate fails, 2021-03-22). The symptom here is that the second request should prompt the user, but doesn't. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b0d954 commit b694f1e

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

t/t5551-http-fetch-smart.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,4 +517,45 @@ test_expect_success 'server-side error detected' '
517517
test_i18ngrep "server-side error" actual
518518
'
519519

520+
test_expect_success 'http auth remembers successful credentials' '
521+
rm -f .git-credentials &&
522+
test_config credential.helper store &&
523+
524+
# the first request prompts the user...
525+
set_askpass user@host pass@host &&
526+
git ls-remote "$HTTPD_URL/auth/smart/repo.git" >/dev/null &&
527+
expect_askpass both user@host &&
528+
529+
# ...and the second one uses the stored value rather than
530+
# prompting the user.
531+
set_askpass bogus-user bogus-pass &&
532+
git ls-remote "$HTTPD_URL/auth/smart/repo.git" >/dev/null &&
533+
expect_askpass none
534+
'
535+
536+
test_expect_failure 'http auth forgets bogus credentials' '
537+
# seed credential store with bogus values. In real life,
538+
# this would probably come from a password which worked
539+
# for a previous request.
540+
rm -f .git-credentials &&
541+
test_config credential.helper store &&
542+
{
543+
echo "url=$HTTPD_URL" &&
544+
echo "username=bogus" &&
545+
echo "password=bogus"
546+
} | git credential approve &&
547+
548+
# we expect this to use the bogus values and fail, never even
549+
# prompting the user...
550+
set_askpass user@host pass@host &&
551+
test_must_fail git ls-remote "$HTTPD_URL/auth/smart/repo.git" >/dev/null &&
552+
expect_askpass none &&
553+
554+
# ...but now we should have forgotten the bad value, causing
555+
# us to prompt the user again.
556+
set_askpass user@host pass@host &&
557+
git ls-remote "$HTTPD_URL/auth/smart/repo.git" >/dev/null &&
558+
expect_askpass both user@host
559+
'
560+
520561
test_done

0 commit comments

Comments
 (0)