3 test_description
='test http auth header and credential helper interop'
6 .
"$TEST_DIRECTORY"/lib-httpd.sh
9 if ! test_have_prereq CGIPASSAUTH
11 skip_all
="no CGIPassAuth support"
16 test_expect_success
'setup_credential_helper' '
17 mkdir "$TRASH_DIRECTORY/bin" &&
18 PATH=$PATH:"$TRASH_DIRECTORY/bin" &&
21 CREDENTIAL_HELPER="$TRASH_DIRECTORY/bin/git-credential-test-helper" &&
22 write_script "$CREDENTIAL_HELPER" <<-\EOF
24 teefile=$cmd-query.cred
25 catfile=$cmd-reply.cred
26 sed -n -e "/^$/q" -e "p" >>$teefile
27 if test "$cmd" = "get"
34 set_credential_reply
() {
35 cat >"$TRASH_DIRECTORY/$1-reply.cred"
38 expect_credential_query
() {
39 cat >"$TRASH_DIRECTORY/$1-expect.cred" &&
40 test_cmp
"$TRASH_DIRECTORY/$1-expect.cred" \
41 "$TRASH_DIRECTORY/$1-query.cred"
46 rm -f "$HTTPD_ROOT_PATH"/custom-auth.valid \
47 "$HTTPD_ROOT_PATH"/custom-auth.challenge
50 test_expect_success
'setup repository' '
52 git init --bare "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
53 git push --mirror "$HTTPD_DOCUMENT_ROOT_PATH/repo.git"
56 test_expect_success
'access using basic auth' '
57 test_when_finished "per_test_cleanup" &&
59 set_credential_reply get <<-EOF &&
61 password=secret-passwd
64 # Basic base64(alice:secret-passwd)
65 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
66 Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
69 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
70 WWW-Authenticate: Basic realm="example.com"
73 test_config_global credential.helper test-helper &&
74 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
76 expect_credential_query get <<-EOF &&
79 wwwauth[]=Basic realm="example.com"
82 expect_credential_query store <<-EOF
86 password=secret-passwd
90 test_expect_success
'access using basic auth invalid credentials' '
91 test_when_finished "per_test_cleanup" &&
93 set_credential_reply get <<-EOF &&
98 # Basic base64(alice:secret-passwd)
99 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
100 Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
103 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
104 WWW-Authenticate: Basic realm="example.com"
107 test_config_global credential.helper test-helper &&
108 test_must_fail git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
110 expect_credential_query get <<-EOF &&
113 wwwauth[]=Basic realm="example.com"
116 expect_credential_query erase <<-EOF
120 password=wrong-passwd
121 wwwauth[]=Basic realm="example.com"
125 test_expect_success
'access using basic auth with extra challenges' '
126 test_when_finished "per_test_cleanup" &&
128 set_credential_reply get <<-EOF &&
130 password=secret-passwd
133 # Basic base64(alice:secret-passwd)
134 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
135 Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
138 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
139 WWW-Authenticate: FooBar param1="value1" param2="value2"
140 WWW-Authenticate: Bearer authorize_uri="id.example.com" p=1 q=0
141 WWW-Authenticate: Basic realm="example.com"
144 test_config_global credential.helper test-helper &&
145 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
147 expect_credential_query get <<-EOF &&
150 wwwauth[]=FooBar param1="value1" param2="value2"
151 wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0
152 wwwauth[]=Basic realm="example.com"
155 expect_credential_query store <<-EOF
159 password=secret-passwd
163 test_expect_success
'access using basic auth mixed-case wwwauth header name' '
164 test_when_finished "per_test_cleanup" &&
166 set_credential_reply get <<-EOF &&
168 password=secret-passwd
171 # Basic base64(alice:secret-passwd)
172 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
173 Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
176 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
177 www-authenticate: foobar param1="value1" param2="value2"
178 WWW-AUTHENTICATE: BEARER authorize_uri="id.example.com" p=1 q=0
179 WwW-aUtHeNtIcAtE: baSiC realm="example.com"
182 test_config_global credential.helper test-helper &&
183 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
185 expect_credential_query get <<-EOF &&
188 wwwauth[]=foobar param1="value1" param2="value2"
189 wwwauth[]=BEARER authorize_uri="id.example.com" p=1 q=0
190 wwwauth[]=baSiC realm="example.com"
193 expect_credential_query store <<-EOF
197 password=secret-passwd
201 test_expect_success
'access using basic auth with wwwauth header continuations' '
202 test_when_finished "per_test_cleanup" &&
204 set_credential_reply get <<-EOF &&
206 password=secret-passwd
209 # Basic base64(alice:secret-passwd)
210 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
211 Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
214 # Note that leading and trailing whitespace is important to correctly
215 # simulate a continuation/folded header.
216 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
217 WWW-Authenticate: FooBar param1="value1"
219 WWW-Authenticate: Bearer authorize_uri="id.example.com"
222 WWW-Authenticate: Basic realm="example.com"
225 test_config_global credential.helper test-helper &&
226 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
228 expect_credential_query get <<-EOF &&
231 wwwauth[]=FooBar param1="value1" param2="value2"
232 wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0
233 wwwauth[]=Basic realm="example.com"
236 expect_credential_query store <<-EOF
240 password=secret-passwd
244 test_expect_success
'access using basic auth with wwwauth header empty continuations' '
245 test_when_finished "per_test_cleanup" &&
247 set_credential_reply get <<-EOF &&
249 password=secret-passwd
252 # Basic base64(alice:secret-passwd)
253 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
254 Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
257 CHALLENGE="$HTTPD_ROOT_PATH/custom-auth.challenge" &&
259 # Note that leading and trailing whitespace is important to correctly
260 # simulate a continuation/folded header.
261 printf "WWW-Authenticate: FooBar param1=\"value1\"\r\n" >"$CHALLENGE" &&
262 printf " \r\n" >>"$CHALLENGE" &&
263 printf " param2=\"value2\"\r\n" >>"$CHALLENGE" &&
264 printf "WWW-Authenticate: Bearer authorize_uri=\"id.example.com\"\r\n" >>"$CHALLENGE" &&
265 printf " p=1\r\n" >>"$CHALLENGE" &&
266 printf " \r\n" >>"$CHALLENGE" &&
267 printf " q=0\r\n" >>"$CHALLENGE" &&
268 printf "WWW-Authenticate: Basic realm=\"example.com\"\r\n" >>"$CHALLENGE" &&
270 test_config_global credential.helper test-helper &&
271 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
273 expect_credential_query get <<-EOF &&
276 wwwauth[]=FooBar param1="value1" param2="value2"
277 wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0
278 wwwauth[]=Basic realm="example.com"
281 expect_credential_query store <<-EOF
285 password=secret-passwd
289 test_expect_success
'access using basic auth with wwwauth header mixed line-endings' '
290 test_when_finished "per_test_cleanup" &&
292 set_credential_reply get <<-EOF &&
294 password=secret-passwd
297 # Basic base64(alice:secret-passwd)
298 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
299 Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
302 CHALLENGE="$HTTPD_ROOT_PATH/custom-auth.challenge" &&
304 # Note that leading and trailing whitespace is important to correctly
305 # simulate a continuation/folded header.
306 printf "WWW-Authenticate: FooBar param1=\"value1\"\r\n" >"$CHALLENGE" &&
307 printf " \r\n" >>"$CHALLENGE" &&
308 printf "\tparam2=\"value2\"\r\n" >>"$CHALLENGE" &&
309 printf "WWW-Authenticate: Basic realm=\"example.com\"" >>"$CHALLENGE" &&
311 test_config_global credential.helper test-helper &&
312 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
314 expect_credential_query get <<-EOF &&
317 wwwauth[]=FooBar param1="value1" param2="value2"
318 wwwauth[]=Basic realm="example.com"
321 expect_credential_query store <<-EOF
325 password=secret-passwd