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:

committed by
Junio C Hamano

parent
726800a8b3
commit
e837936c7c
@ -163,3 +163,42 @@ test_http_push_nonff() {
|
||||
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"
|
||||
}
|
||||
|
Reference in New Issue
Block a user