Skip to content

Commit afbf5ca

Browse files
peffgitster
authored andcommitted
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>
1 parent d2446df commit afbf5ca

File tree

6 files changed

+26
-17
lines changed

6 files changed

+26
-17
lines changed

t/lib-httpd.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ prepare_httpd() {
102102
HTTPD_DEST=127.0.0.1:$LIB_HTTPD_PORT
103103
HTTPD_URL=$HTTPD_PROTO://$HTTPD_DEST
104104
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
106106

107107
if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
108108
then
@@ -190,7 +190,15 @@ setup_askpass_helper() {
190190
test_expect_success 'setup askpass helper' '
191191
write_script "$TRASH_DIRECTORY/askpass" <<-\EOF &&
192192
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"
194202
EOF
195203
GIT_ASKPASS="$TRASH_DIRECTORY/askpass" &&
196204
export GIT_ASKPASS &&
@@ -200,7 +208,8 @@ setup_askpass_helper() {
200208

201209
set_askpass() {
202210
>"$TRASH_DIRECTORY/askpass-query" &&
203-
echo "$*" >"$TRASH_DIRECTORY/askpass-response"
211+
echo "$1" >"$TRASH_DIRECTORY/askpass-user" &&
212+
echo "$2" >"$TRASH_DIRECTORY/askpass-pass"
204213
}
205214

206215
expect_askpass() {

t/lib-httpd/passwd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
user@host:nKpa8pZUHx/ic
1+
user@host:xb4E8pqD81KQs

t/t5540-http-push.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
154154

155155
test_expect_success 'push to password-protected repository (user in URL)' '
156156
test_commit pw-user &&
157-
set_askpass user@host &&
157+
set_askpass user@host pass@host &&
158158
git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
159159
git rev-parse --verify HEAD >expect &&
160160
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' '
168168

169169
test_expect_failure 'push to password-protected repository (no user in URL)' '
170170
test_commit pw-nouser &&
171-
set_askpass user@host &&
171+
set_askpass user@host pass@host &&
172172
git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
173173
expect_askpass both user@host
174174
git rev-parse --verify HEAD >expect &&

t/t5541-http-push.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ test_expect_success 'push over smart http with auth' '
274274
cd "$ROOT_PATH/test_repo_clone" &&
275275
echo push-auth-test >expect &&
276276
test_commit push-auth-test &&
277-
set_askpass user@host &&
277+
set_askpass user@host pass@host &&
278278
git push "$HTTPD_URL"/auth/smart/test_repo.git &&
279279
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
280280
log -1 --format=%s >actual &&
@@ -286,7 +286,7 @@ test_expect_success 'push to auth-only-for-push repo' '
286286
cd "$ROOT_PATH/test_repo_clone" &&
287287
echo push-half-auth >expect &&
288288
test_commit push-half-auth &&
289-
set_askpass user@host &&
289+
set_askpass user@host pass@host &&
290290
git push "$HTTPD_URL"/auth-push/smart/test_repo.git &&
291291
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
292292
log -1 --format=%s >actual &&
@@ -316,7 +316,7 @@ test_expect_success 'push into half-auth-complete requires password' '
316316
cd "$ROOT_PATH/half-auth-clone" &&
317317
echo two >expect &&
318318
test_commit two &&
319-
set_askpass user@host &&
319+
set_askpass user@host pass@host &&
320320
git push "$HTTPD_URL/half-auth-complete/smart/half-auth.git" &&
321321
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git" \
322322
log -1 --format=%s >actual &&

t/t5550-http-fetch.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ test_expect_success 'http auth can use user/pass in URL' '
6262
'
6363

6464
test_expect_success 'http auth can use just user in URL' '
65-
set_askpass user@host &&
65+
set_askpass wrong pass@host &&
6666
git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
6767
expect_askpass pass user@host
6868
'
6969

7070
test_expect_success 'http auth can request both user and pass' '
71-
set_askpass user@host &&
71+
set_askpass user@host pass@host &&
7272
git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
7373
expect_askpass both user@host
7474
'
@@ -77,7 +77,7 @@ test_expect_success 'http auth respects credential helper config' '
7777
test_config_global credential.helper "!f() {
7878
cat >/dev/null
7979
echo username=user@host
80-
echo password=user@host
80+
echo password=pass@host
8181
}; f" &&
8282
set_askpass wrong &&
8383
git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
@@ -86,14 +86,14 @@ test_expect_success 'http auth respects credential helper config' '
8686

8787
test_expect_success 'http auth can get username from config' '
8888
test_config_global "credential.$HTTPD_URL.username" user@host &&
89-
set_askpass user@host &&
89+
set_askpass wrong pass@host &&
9090
git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
9191
expect_askpass pass user@host
9292
'
9393

9494
test_expect_success 'configured username does not override URL' '
9595
test_config_global "credential.$HTTPD_URL.username" wrong &&
96-
set_askpass user@host &&
96+
set_askpass wrong pass@host &&
9797
git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
9898
expect_askpass pass user@host
9999
'

t/t5551-http-fetch.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ test_expect_success 'redirects re-root further requests' '
119119

120120
test_expect_success 'clone from password-protected repository' '
121121
echo two >expect &&
122-
set_askpass user@host &&
122+
set_askpass user@host pass@host &&
123123
git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
124124
expect_askpass both user@host &&
125125
git --git-dir=smart-auth log -1 --format=%s >actual &&
@@ -137,7 +137,7 @@ test_expect_success 'clone from auth-only-for-push repository' '
137137

138138
test_expect_success 'clone from auth-only-for-objects repository' '
139139
echo two >expect &&
140-
set_askpass user@host &&
140+
set_askpass user@host pass@host &&
141141
git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
142142
expect_askpass both user@host &&
143143
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' '
151151
'
152152

153153
test_expect_success 'redirects send auth to new location' '
154-
set_askpass user@host &&
154+
set_askpass user@host pass@host &&
155155
git -c credential.useHttpPath=true \
156156
clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
157157
expect_askpass both user@host auth/smart/repo.git

0 commit comments

Comments
 (0)