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 1b0d9545bb (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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 18, 2021 at 02:27 UTC b694f1e49ec39f45f61ca3b6d9df5945cbf43b71
1 file changed +41
t/t5551-http-fetch-smart.sh
+41
@@ -517,4 +517,45 @@ test_expect_success 'server-side error detected' '
517 test_i18ngrep "server-side error" actual
518 '
519
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 +
561 test_done