Skip to content

Commit 5232586

Browse files
peffgitster
authored andcommitted
improve httpd auth tests
These just checked that we could clone a repository when the username and password were given in the URL; we should also check that git will prompt when no or partial credentials are given. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66c8448 commit 5232586

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

t/lib-httpd.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ prepare_httpd() {
8181

8282
if test -n "$LIB_HTTPD_SSL"
8383
then
84-
HTTPD_URL=https://127.0.0.1:$LIB_HTTPD_PORT
85-
AUTH_HTTPD_URL=https://user%40host:user%[email protected]:$LIB_HTTPD_PORT
84+
HTTPD_PROTO=https
8685

8786
RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \
8887
-config "$TEST_PATH/ssl.cnf" \
@@ -93,9 +92,12 @@ prepare_httpd() {
9392
export GIT_SSL_NO_VERIFY
9493
HTTPD_PARA="$HTTPD_PARA -DSSL"
9594
else
96-
HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT
97-
AUTH_HTTPD_URL=http://user%40host:user%[email protected]:$LIB_HTTPD_PORT
95+
HTTPD_PROTO=http
9896
fi
97+
HTTPD_DEST=127.0.0.1:$LIB_HTTPD_PORT
98+
HTTPD_URL=$HTTPD_PROTO://$HTTPD_DEST
99+
HTTPD_URL_USER=$HTTPD_PROTO://user%40host@$HTTPD_DEST
100+
HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:user%40host@$HTTPD_DEST
99101

100102
if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
101103
then

t/t5550-http-fetch.sh

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,54 @@ test_expect_success 'clone http repository' '
3535
test_cmp file clone/file
3636
'
3737

38-
test_expect_success 'clone http repository with authentication' '
38+
test_expect_success 'create password-protected repository' '
3939
mkdir "$HTTPD_DOCUMENT_ROOT_PATH/auth/" &&
40-
cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" "$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git" &&
41-
git clone $AUTH_HTTPD_URL/auth/repo.git clone-auth &&
42-
test_cmp file clone-auth/file
40+
cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
41+
"$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git"
42+
'
43+
44+
test_expect_success 'setup askpass helpers' '
45+
cat >askpass <<-EOF &&
46+
#!/bin/sh
47+
echo >>"$PWD/askpass-query" "askpass: \$*" &&
48+
cat "$PWD/askpass-response"
49+
EOF
50+
chmod +x askpass &&
51+
GIT_ASKPASS="$PWD/askpass" &&
52+
export GIT_ASKPASS &&
53+
>askpass-expect-none &&
54+
echo "askpass: Password: " >askpass-expect-pass &&
55+
{ echo "askpass: Username: " &&
56+
cat askpass-expect-pass
57+
} >askpass-expect-both
58+
'
59+
60+
test_expect_success 'cloning password-protected repository can fail' '
61+
>askpass-query &&
62+
echo wrong >askpass-response &&
63+
test_must_fail git clone "$HTTPD_URL/auth/repo.git" clone-auth-fail &&
64+
test_cmp askpass-expect-both askpass-query
65+
'
66+
67+
test_expect_success 'http auth can use user/pass in URL' '
68+
>askpass-query &&
69+
echo wrong >askpass-reponse &&
70+
git clone "$HTTPD_URL_USER_PASS/auth/repo.git" clone-auth-none &&
71+
test_cmp askpass-expect-none askpass-query
72+
'
73+
74+
test_expect_success 'http auth can use just user in URL' '
75+
>askpass-query &&
76+
echo user@host >askpass-response &&
77+
git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-pass &&
78+
test_cmp askpass-expect-pass askpass-query
79+
'
80+
81+
test_expect_success 'http auth can request both user and pass' '
82+
>askpass-query &&
83+
echo user@host >askpass-response &&
84+
git clone "$HTTPD_URL/auth/repo.git" clone-auth-both &&
85+
test_cmp askpass-expect-both askpass-query
4386
'
4487

4588
test_expect_success 'fetch changes via http' '

0 commit comments

Comments
 (0)