Git 2.45
[git/gitster.git] / t / t5563-simple-http-auth.sh
blobab8a721ccc7db4611fd2f44ae60d9506ea011a01
1 #!/bin/sh
3 test_description='test http auth header and credential helper interop'
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-httpd.sh
8 enable_cgipassauth
9 if ! test_have_prereq CGIPASSAUTH
10 then
11 skip_all="no CGIPassAuth support"
12 test_done
14 start_httpd
16 test_expect_success 'setup_credential_helper' '
17 mkdir "$TRASH_DIRECTORY/bin" &&
18 PATH=$PATH:"$TRASH_DIRECTORY/bin" &&
19 export PATH &&
21 CREDENTIAL_HELPER="$TRASH_DIRECTORY/bin/git-credential-test-helper" &&
22 write_script "$CREDENTIAL_HELPER" <<-\EOF
23 cmd=$1
24 teefile=$cmd-query.cred
25 catfile=$cmd-reply.cred
26 sed -n -e "/^$/q" -e "p" >>$teefile
27 if test "$cmd" = "get"
28 then
29 cat $catfile
31 EOF
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"
44 per_test_cleanup () {
45 rm -f *.cred &&
46 rm -f "$HTTPD_ROOT_PATH"/custom-auth.valid \
47 "$HTTPD_ROOT_PATH"/custom-auth.challenge
50 test_expect_success 'setup repository' '
51 test_commit foo &&
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 &&
60 username=alice
61 password=secret-passwd
62 EOF
64 # Basic base64(alice:secret-passwd)
65 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
66 Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
67 EOF
69 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
70 WWW-Authenticate: Basic realm="example.com"
71 EOF
73 test_config_global credential.helper test-helper &&
74 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
76 expect_credential_query get <<-EOF &&
77 protocol=http
78 host=$HTTPD_DEST
79 wwwauth[]=Basic realm="example.com"
80 EOF
82 expect_credential_query store <<-EOF
83 protocol=http
84 host=$HTTPD_DEST
85 username=alice
86 password=secret-passwd
87 EOF
90 test_expect_success 'access using basic auth invalid credentials' '
91 test_when_finished "per_test_cleanup" &&
93 set_credential_reply get <<-EOF &&
94 username=baduser
95 password=wrong-passwd
96 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 &&
111 protocol=http
112 host=$HTTPD_DEST
113 wwwauth[]=Basic realm="example.com"
116 expect_credential_query erase <<-EOF
117 protocol=http
118 host=$HTTPD_DEST
119 username=baduser
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 &&
129 username=alice
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 &&
148 protocol=http
149 host=$HTTPD_DEST
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
156 protocol=http
157 host=$HTTPD_DEST
158 username=alice
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 &&
167 username=alice
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 &&
186 protocol=http
187 host=$HTTPD_DEST
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
194 protocol=http
195 host=$HTTPD_DEST
196 username=alice
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 &&
205 username=alice
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"
218 param2="value2"
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 &&
229 protocol=http
230 host=$HTTPD_DEST
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
237 protocol=http
238 host=$HTTPD_DEST
239 username=alice
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 &&
248 username=alice
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 &&
274 protocol=http
275 host=$HTTPD_DEST
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
282 protocol=http
283 host=$HTTPD_DEST
284 username=alice
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 &&
293 username=alice
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 &&
315 protocol=http
316 host=$HTTPD_DEST
317 wwwauth[]=FooBar param1="value1" param2="value2"
318 wwwauth[]=Basic realm="example.com"
321 expect_credential_query store <<-EOF
322 protocol=http
323 host=$HTTPD_DEST
324 username=alice
325 password=secret-passwd
329 test_done