mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
t5550: factor out http auth setup
The t5550 script sets up a nice askpass helper for simulating user input and checking what git prompted for. Let's make it available to other http scripts by migrating it to lib-httpd. We can use this immediately in t5540 to make our tests more robust (previously, we did not check at all that hitting the password-protected repo actually involved a password). Unfortunately, we end up failing the test because the current code erroneously prompts twice (once for git-remote-http, and then again when the former spawns git-http-push). More importantly, though, it will let us easily add smart-http authentication tests in t5541 and t5551; we currently do not test smart-http authentication at all. As part of making it generic, let's always look for and store auxiliary askpass files at the top-level trash directory; this makes it compatible with t5540, which runs some tests from sub-repositories. We can abstract away the ugliness with a short helper function. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
726800a8b3
commit
e837936c7c
|
@ -163,3 +163,42 @@ test_http_push_nonff() {
|
||||||
test_i18ngrep "Updates were rejected because" output
|
test_i18ngrep "Updates were rejected because" output
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setup_askpass_helper() {
|
||||||
|
test_expect_success 'setup askpass helper' '
|
||||||
|
write_script "$TRASH_DIRECTORY/askpass" <<-\EOF &&
|
||||||
|
echo >>"$TRASH_DIRECTORY/askpass-query" "askpass: $*" &&
|
||||||
|
cat "$TRASH_DIRECTORY/askpass-response"
|
||||||
|
EOF
|
||||||
|
GIT_ASKPASS="$TRASH_DIRECTORY/askpass" &&
|
||||||
|
export GIT_ASKPASS &&
|
||||||
|
export TRASH_DIRECTORY
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_askpass() {
|
||||||
|
>"$TRASH_DIRECTORY/askpass-query" &&
|
||||||
|
echo "$*" >"$TRASH_DIRECTORY/askpass-response"
|
||||||
|
}
|
||||||
|
|
||||||
|
expect_askpass() {
|
||||||
|
dest=$HTTPD_DEST
|
||||||
|
{
|
||||||
|
case "$1" in
|
||||||
|
none)
|
||||||
|
;;
|
||||||
|
pass)
|
||||||
|
echo "askpass: Password for 'http://$2@$dest': "
|
||||||
|
;;
|
||||||
|
both)
|
||||||
|
echo "askpass: Username for 'http://$dest': "
|
||||||
|
echo "askpass: Password for 'http://$2@$dest': "
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
false
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
} >"$TRASH_DIRECTORY/askpass-expect" &&
|
||||||
|
test_cmp "$TRASH_DIRECTORY/askpass-expect" \
|
||||||
|
"$TRASH_DIRECTORY/askpass-query"
|
||||||
|
}
|
||||||
|
|
|
@ -46,15 +46,7 @@ test_expect_success 'create password-protected repository' '
|
||||||
"$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git"
|
"$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git"
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'setup askpass helper' '
|
setup_askpass_helper
|
||||||
cat >askpass <<-\EOF &&
|
|
||||||
#!/bin/sh
|
|
||||||
echo user@host
|
|
||||||
EOF
|
|
||||||
chmod +x askpass &&
|
|
||||||
GIT_ASKPASS="$PWD/askpass" &&
|
|
||||||
export GIT_ASKPASS
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success 'clone remote repository' '
|
test_expect_success 'clone remote repository' '
|
||||||
cd "$ROOT_PATH" &&
|
cd "$ROOT_PATH" &&
|
||||||
|
@ -162,6 +154,7 @@ test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
|
||||||
|
|
||||||
test_expect_success 'push to password-protected repository (user in URL)' '
|
test_expect_success 'push to password-protected repository (user in URL)' '
|
||||||
test_commit pw-user &&
|
test_commit pw-user &&
|
||||||
|
set_askpass user@host &&
|
||||||
git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
|
git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
|
||||||
git rev-parse --verify HEAD >expect &&
|
git rev-parse --verify HEAD >expect &&
|
||||||
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
|
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
|
||||||
|
@ -169,9 +162,15 @@ test_expect_success 'push to password-protected repository (user in URL)' '
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_failure 'user was prompted only once for password' '
|
||||||
|
expect_askpass pass user@host
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_failure 'push to password-protected repository (no user in URL)' '
|
test_expect_failure 'push to password-protected repository (no user in URL)' '
|
||||||
test_commit pw-nouser &&
|
test_commit pw-nouser &&
|
||||||
|
set_askpass user@host &&
|
||||||
git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
|
git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
|
||||||
|
expect_askpass both user@host
|
||||||
git rev-parse --verify HEAD >expect &&
|
git rev-parse --verify HEAD >expect &&
|
||||||
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
|
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
|
||||||
rev-parse --verify HEAD >actual &&
|
rev-parse --verify HEAD >actual &&
|
||||||
|
|
|
@ -46,62 +46,28 @@ test_expect_success 'create password-protected repository' '
|
||||||
"$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
|
"$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'setup askpass helpers' '
|
setup_askpass_helper
|
||||||
cat >askpass <<-EOF &&
|
|
||||||
#!/bin/sh
|
|
||||||
echo >>"$PWD/askpass-query" "askpass: \$*" &&
|
|
||||||
cat "$PWD/askpass-response"
|
|
||||||
EOF
|
|
||||||
chmod +x askpass &&
|
|
||||||
GIT_ASKPASS="$PWD/askpass" &&
|
|
||||||
export GIT_ASKPASS
|
|
||||||
'
|
|
||||||
|
|
||||||
expect_askpass() {
|
|
||||||
dest=$HTTPD_DEST
|
|
||||||
{
|
|
||||||
case "$1" in
|
|
||||||
none)
|
|
||||||
;;
|
|
||||||
pass)
|
|
||||||
echo "askpass: Password for 'http://$2@$dest': "
|
|
||||||
;;
|
|
||||||
both)
|
|
||||||
echo "askpass: Username for 'http://$dest': "
|
|
||||||
echo "askpass: Password for 'http://$2@$dest': "
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
false
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
} >askpass-expect &&
|
|
||||||
test_cmp askpass-expect askpass-query
|
|
||||||
}
|
|
||||||
|
|
||||||
test_expect_success 'cloning password-protected repository can fail' '
|
test_expect_success 'cloning password-protected repository can fail' '
|
||||||
>askpass-query &&
|
set_askpass wrong &&
|
||||||
echo wrong >askpass-response &&
|
|
||||||
test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
|
test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
|
||||||
expect_askpass both wrong
|
expect_askpass both wrong
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'http auth can use user/pass in URL' '
|
test_expect_success 'http auth can use user/pass in URL' '
|
||||||
>askpass-query &&
|
set_askpass wrong &&
|
||||||
echo wrong >askpass-response &&
|
|
||||||
git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
|
git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
|
||||||
expect_askpass none
|
expect_askpass none
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'http auth can use just user in URL' '
|
test_expect_success 'http auth can use just user in URL' '
|
||||||
>askpass-query &&
|
set_askpass user@host &&
|
||||||
echo user@host >askpass-response &&
|
|
||||||
git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
|
git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
|
||||||
expect_askpass pass user@host
|
expect_askpass pass user@host
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'http auth can request both user and pass' '
|
test_expect_success 'http auth can request both user and pass' '
|
||||||
>askpass-query &&
|
set_askpass user@host &&
|
||||||
echo user@host >askpass-response &&
|
|
||||||
git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
|
git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
|
||||||
expect_askpass both user@host
|
expect_askpass both user@host
|
||||||
'
|
'
|
||||||
|
@ -112,24 +78,21 @@ test_expect_success 'http auth respects credential helper config' '
|
||||||
echo username=user@host
|
echo username=user@host
|
||||||
echo password=user@host
|
echo password=user@host
|
||||||
}; f" &&
|
}; f" &&
|
||||||
>askpass-query &&
|
set_askpass wrong &&
|
||||||
echo wrong >askpass-response &&
|
|
||||||
git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
|
git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
|
||||||
expect_askpass none
|
expect_askpass none
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'http auth can get username from config' '
|
test_expect_success 'http auth can get username from config' '
|
||||||
test_config_global "credential.$HTTPD_URL.username" user@host &&
|
test_config_global "credential.$HTTPD_URL.username" user@host &&
|
||||||
>askpass-query &&
|
set_askpass user@host &&
|
||||||
echo user@host >askpass-response &&
|
|
||||||
git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
|
git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
|
||||||
expect_askpass pass user@host
|
expect_askpass pass user@host
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'configured username does not override URL' '
|
test_expect_success 'configured username does not override URL' '
|
||||||
test_config_global "credential.$HTTPD_URL.username" wrong &&
|
test_config_global "credential.$HTTPD_URL.username" wrong &&
|
||||||
>askpass-query &&
|
set_askpass user@host &&
|
||||||
echo user@host >askpass-response &&
|
|
||||||
git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
|
git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
|
||||||
expect_askpass pass user@host
|
expect_askpass pass user@host
|
||||||
'
|
'
|
||||||
|
|
Loading…
Reference in a new issue