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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 18, 2011 at 03:49 UTC 5232586c7985e6a420ee741e19e7fd6d040d43f6
2 files changed +53 -8
t/lib-httpd.sh
+6 -4
@@ -81,8 +81,7 @@ prepare_httpd() {
81
82 if test -n "$LIB_HTTPD_SSL"
83 then
84 - HTTPD_URL=https://127.0.0.1:$LIB_HTTPD_PORT
85 - AUTH_HTTPD_URL=https://user%40host:user%40host@127.0.0.1:$LIB_HTTPD_PORT
84 + HTTPD_PROTO=https
85
86 RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \
87 -config "$TEST_PATH/ssl.cnf" \
@@ -93,9 +92,12 @@ prepare_httpd() {
92 export GIT_SSL_NO_VERIFY
93 HTTPD_PARA="$HTTPD_PARA -DSSL"
94 else
96 - HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT
97 - AUTH_HTTPD_URL=http://user%40host:user%40host@127.0.0.1:$LIB_HTTPD_PORT
95 + HTTPD_PROTO=http
96 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
101
102 if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
103 then
t/t5550-http-fetch.sh
+47 -4
@@ -35,11 +35,54 @@ test_expect_success 'clone http repository' '
35 test_cmp file clone/file
36 '
37
38 -test_expect_success 'clone http repository with authentication' '
38 +test_expect_success 'create password-protected repository' '
39 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
86 '
87
88 test_expect_success 'fetch changes via http' '