use distinct username/password for http auth tests

The httpd server we set up to test git's http client code knows about a single account, in which both the username and password are "user@host" (the unusual use of the "@" here is to verify that we handle the character correctly when URL escaped). This means that we may miss a certain class of errors in which the username and password are mixed up internally by git. We can make our tests more robust by having distinct values for the username and password. In addition to tweaking the server passwd file and the client URL, we must teach the "askpass" harness to accept multiple values. As a bonus, this makes the setup of some tests more obvious; when we are expecting git to ask only about the password, we can seed the username askpass response with a bogus value. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 2, 2014 at 02:38 UTC afbf5ca507470aab6716671f2ad207c74cd585fb
6 files changed +26 -17
t/lib-httpd.sh
+12 -3
@@ -102,7 +102,7 @@ prepare_httpd() {
102 HTTPD_DEST=127.0.0.1:$LIB_HTTPD_PORT
103 HTTPD_URL=$HTTPD_PROTO://$HTTPD_DEST
104 HTTPD_URL_USER=$HTTPD_PROTO://user%40host@$HTTPD_DEST
105 - HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:user%40host@$HTTPD_DEST
105 + HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:pass%40host@$HTTPD_DEST
106
107 if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
108 then
@@ -190,7 +190,15 @@ setup_askpass_helper() {
190 test_expect_success 'setup askpass helper' '
191 write_script "$TRASH_DIRECTORY/askpass" <<-\EOF &&
192 echo >>"$TRASH_DIRECTORY/askpass-query" "askpass: $*" &&
193 - cat "$TRASH_DIRECTORY/askpass-response"
193 + case "$*" in
194 + *Username*)
195 + what=user
196 + ;;
197 + *Password*)
198 + what=pass
199 + ;;
200 + esac &&
201 + cat "$TRASH_DIRECTORY/askpass-$what"
202 EOF
203 GIT_ASKPASS="$TRASH_DIRECTORY/askpass" &&
204 export GIT_ASKPASS &&
@@ -200,7 +208,8 @@ setup_askpass_helper() {
208
209 set_askpass() {
210 >"$TRASH_DIRECTORY/askpass-query" &&
203 - echo "$*" >"$TRASH_DIRECTORY/askpass-response"
211 + echo "$1" >"$TRASH_DIRECTORY/askpass-user" &&
212 + echo "$2" >"$TRASH_DIRECTORY/askpass-pass"
213 }
214
215 expect_askpass() {
t/lib-httpd/passwd
+1 -1
@@ -1 +1 @@
1 -user@host:nKpa8pZUHx/ic
1 +user@host:xb4E8pqD81KQs
t/t5540-http-push.sh
+2 -2
@@ -154,7 +154,7 @@ test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
154
155 test_expect_success 'push to password-protected repository (user in URL)' '
156 test_commit pw-user &&
157 - set_askpass user@host &&
157 + set_askpass user@host pass@host &&
158 git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
159 git rev-parse --verify HEAD >expect &&
160 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
@@ -168,7 +168,7 @@ test_expect_failure 'user was prompted only once for password' '
168
169 test_expect_failure 'push to password-protected repository (no user in URL)' '
170 test_commit pw-nouser &&
171 - set_askpass user@host &&
171 + set_askpass user@host pass@host &&
172 git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
173 expect_askpass both user@host
174 git rev-parse --verify HEAD >expect &&
t/t5541-http-push.sh
+3 -3
@@ -274,7 +274,7 @@ test_expect_success 'push over smart http with auth' '
274 cd "$ROOT_PATH/test_repo_clone" &&
275 echo push-auth-test >expect &&
276 test_commit push-auth-test &&
277 - set_askpass user@host &&
277 + set_askpass user@host pass@host &&
278 git push "$HTTPD_URL"/auth/smart/test_repo.git &&
279 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
280 log -1 --format=%s >actual &&
@@ -286,7 +286,7 @@ test_expect_success 'push to auth-only-for-push repo' '
286 cd "$ROOT_PATH/test_repo_clone" &&
287 echo push-half-auth >expect &&
288 test_commit push-half-auth &&
289 - set_askpass user@host &&
289 + set_askpass user@host pass@host &&
290 git push "$HTTPD_URL"/auth-push/smart/test_repo.git &&
291 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
292 log -1 --format=%s >actual &&
@@ -316,7 +316,7 @@ test_expect_success 'push into half-auth-complete requires password' '
316 cd "$ROOT_PATH/half-auth-clone" &&
317 echo two >expect &&
318 test_commit two &&
319 - set_askpass user@host &&
319 + set_askpass user@host pass@host &&
320 git push "$HTTPD_URL/half-auth-complete/smart/half-auth.git" &&
321 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git" \
322 log -1 --format=%s >actual &&
t/t5550-http-fetch.sh
+5 -5
@@ -62,13 +62,13 @@ test_expect_success 'http auth can use user/pass in URL' '
62 '
63
64 test_expect_success 'http auth can use just user in URL' '
65 - set_askpass user@host &&
65 + set_askpass wrong pass@host &&
66 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
67 expect_askpass pass user@host
68 '
69
70 test_expect_success 'http auth can request both user and pass' '
71 - set_askpass user@host &&
71 + set_askpass user@host pass@host &&
72 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
73 expect_askpass both user@host
74 '
@@ -77,7 +77,7 @@ test_expect_success 'http auth respects credential helper config' '
77 test_config_global credential.helper "!f() {
78 cat >/dev/null
79 echo username=user@host
80 - echo password=user@host
80 + echo password=pass@host
81 }; f" &&
82 set_askpass wrong &&
83 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
@@ -86,14 +86,14 @@ test_expect_success 'http auth respects credential helper config' '
86
87 test_expect_success 'http auth can get username from config' '
88 test_config_global "credential.$HTTPD_URL.username" user@host &&
89 - set_askpass user@host &&
89 + set_askpass wrong pass@host &&
90 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
91 expect_askpass pass user@host
92 '
93
94 test_expect_success 'configured username does not override URL' '
95 test_config_global "credential.$HTTPD_URL.username" wrong &&
96 - set_askpass user@host &&
96 + set_askpass wrong pass@host &&
97 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
98 expect_askpass pass user@host
99 '
t/t5551-http-fetch.sh
+3 -3
@@ -119,7 +119,7 @@ test_expect_success 'redirects re-root further requests' '
119
120 test_expect_success 'clone from password-protected repository' '
121 echo two >expect &&
122 - set_askpass user@host &&
122 + set_askpass user@host pass@host &&
123 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
124 expect_askpass both user@host &&
125 git --git-dir=smart-auth log -1 --format=%s >actual &&
@@ -137,7 +137,7 @@ test_expect_success 'clone from auth-only-for-push repository' '
137
138 test_expect_success 'clone from auth-only-for-objects repository' '
139 echo two >expect &&
140 - set_askpass user@host &&
140 + set_askpass user@host pass@host &&
141 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
142 expect_askpass both user@host &&
143 git --git-dir=half-auth log -1 --format=%s >actual &&
@@ -151,7 +151,7 @@ test_expect_success 'no-op half-auth fetch does not require a password' '
151 '
152
153 test_expect_success 'redirects send auth to new location' '
154 - set_askpass user@host &&
154 + set_askpass user@host pass@host &&
155 git -c credential.useHttpPath=true \
156 clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
157 expect_askpass both user@host auth/smart/repo.git