Raw
1 #!/bin/sh
2
3 test_description='test http auth header and credential helper interop'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-httpd.sh
7
8 enable_cgipassauth
9 if ! test_have_prereq CGIPASSAUTH
10 then
11 skip_all="no CGIPassAuth support"
12 test_done
13 fi
14 start_httpd
15
16 test_expect_success 'setup_credential_helper' '
17 mkdir "$TRASH_DIRECTORY/bin" &&
18 PATH=$PATH:"$TRASH_DIRECTORY/bin" &&
19 export PATH &&
20
21 CREDENTIAL_HELPER="$TRASH_DIRECTORY/bin/git-credential-test-helper" &&
22 write_script "$CREDENTIAL_HELPER" <<-\EOF
23 cmd=$1
24 teefile=$cmd-query-temp.cred
25 catfile=$cmd-reply.cred
26 sed -n -e "/^$/q" -e "p" >>$teefile
27 state=$(sed -ne "s/^state\[\]=helper://p" "$teefile")
28 if test -z "$state"
29 then
30 mv "$teefile" "$cmd-query.cred"
31 else
32 mv "$teefile" "$cmd-query-$state.cred"
33 catfile="$cmd-reply-$state.cred"
34 fi
35 if test "$cmd" = "get"
36 then
37 cat $catfile
38 fi
39 EOF
40 '
41
42 set_credential_reply () {
43 local suffix="$(test -n "$2" && echo "-$2")"
44 cat >"$TRASH_DIRECTORY/$1-reply$suffix.cred"
45 }
46
47 expect_credential_query () {
48 local suffix="$(test -n "$2" && echo "-$2")"
49 cat >"$TRASH_DIRECTORY/$1-expect$suffix.cred" &&
50 test_cmp "$TRASH_DIRECTORY/$1-expect$suffix.cred" \
51 "$TRASH_DIRECTORY/$1-query$suffix.cred"
52 }
53
54 per_test_cleanup () {
55 rm -f *.cred &&
56 rm -f "$HTTPD_ROOT_PATH"/custom-auth.valid \
57 "$HTTPD_ROOT_PATH"/custom-auth.challenge
58 }
59
60 test_expect_success 'setup repository' '
61 test_commit foo &&
62 git init --bare "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
63 git push --mirror "$HTTPD_DOCUMENT_ROOT_PATH/repo.git"
64 '
65
66 test_expect_success 'access using basic auth' '
67 test_when_finished "per_test_cleanup" &&
68
69 set_credential_reply get <<-EOF &&
70 username=alice
71 password=secret-passwd
72 EOF
73
74 # Basic base64(alice:secret-passwd)
75 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
76 id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
77 EOF
78
79 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
80 id=1 status=200
81 id=default response=WWW-Authenticate: Basic realm="example.com"
82 EOF
83
84 test_config_global credential.helper test-helper &&
85 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
86
87 expect_credential_query get <<-EOF &&
88 capability[]=authtype
89 capability[]=state
90 protocol=http
91 host=$HTTPD_DEST
92 wwwauth[]=Basic realm="example.com"
93 EOF
94
95 expect_credential_query store <<-EOF
96 protocol=http
97 host=$HTTPD_DEST
98 username=alice
99 password=secret-passwd
100 EOF
101 '
102
103 test_expect_success 'access using basic auth via authtype' '
104 test_when_finished "per_test_cleanup" &&
105
106 set_credential_reply get <<-EOF &&
107 capability[]=authtype
108 authtype=Basic
109 credential=YWxpY2U6c2VjcmV0LXBhc3N3ZA==
110 EOF
111
112 # Basic base64(alice:secret-passwd)
113 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
114 id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
115 EOF
116
117 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
118 id=1 status=200
119 id=default response=WWW-Authenticate: Basic realm="example.com"
120 EOF
121
122 test_config_global credential.helper test-helper &&
123 GIT_CURL_VERBOSE=1 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
124
125 expect_credential_query get <<-EOF &&
126 capability[]=authtype
127 capability[]=state
128 protocol=http
129 host=$HTTPD_DEST
130 wwwauth[]=Basic realm="example.com"
131 EOF
132
133 expect_credential_query store <<-EOF
134 capability[]=authtype
135 authtype=Basic
136 credential=YWxpY2U6c2VjcmV0LXBhc3N3ZA==
137 protocol=http
138 host=$HTTPD_DEST
139 EOF
140 '
141
142 test_expect_success 'access using basic auth invalid credentials' '
143 test_when_finished "per_test_cleanup" &&
144
145 set_credential_reply get <<-EOF &&
146 username=baduser
147 password=wrong-passwd
148 EOF
149
150 # Basic base64(alice:secret-passwd)
151 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
152 id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
153 EOF
154
155 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
156 id=1 status=200
157 id=default response=WWW-Authenticate: Basic realm="example.com"
158 EOF
159
160 test_config_global credential.helper test-helper &&
161 test_must_fail git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
162
163 expect_credential_query get <<-EOF &&
164 capability[]=authtype
165 capability[]=state
166 protocol=http
167 host=$HTTPD_DEST
168 wwwauth[]=Basic realm="example.com"
169 EOF
170
171 expect_credential_query erase <<-EOF
172 protocol=http
173 host=$HTTPD_DEST
174 username=baduser
175 password=wrong-passwd
176 wwwauth[]=Basic realm="example.com"
177 EOF
178 '
179
180 test_expect_success 'access using basic proactive auth' '
181 test_when_finished "per_test_cleanup" &&
182
183 set_credential_reply get <<-EOF &&
184 username=alice
185 password=secret-passwd
186 EOF
187
188 # Basic base64(alice:secret-passwd)
189 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
190 id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
191 EOF
192
193 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
194 id=1 status=200
195 id=default status=403
196 EOF
197
198 test_config_global credential.helper test-helper &&
199 test_config_global http.proactiveAuth basic &&
200 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
201
202 expect_credential_query get <<-EOF &&
203 capability[]=authtype
204 capability[]=state
205 protocol=http
206 host=$HTTPD_DEST
207 wwwauth[]=Basic
208 EOF
209
210 expect_credential_query store <<-EOF
211 protocol=http
212 host=$HTTPD_DEST
213 username=alice
214 password=secret-passwd
215 EOF
216 '
217
218 test_expect_success 'access using auto proactive auth with basic default' '
219 test_when_finished "per_test_cleanup" &&
220
221 set_credential_reply get <<-EOF &&
222 username=alice
223 password=secret-passwd
224 EOF
225
226 # Basic base64(alice:secret-passwd)
227 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
228 id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
229 EOF
230
231 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
232 id=1 status=200
233 id=default status=403
234 EOF
235
236 test_config_global credential.helper test-helper &&
237 test_config_global http.proactiveAuth auto &&
238 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
239
240 expect_credential_query get <<-EOF &&
241 capability[]=authtype
242 capability[]=state
243 protocol=http
244 host=$HTTPD_DEST
245 EOF
246
247 expect_credential_query store <<-EOF
248 protocol=http
249 host=$HTTPD_DEST
250 username=alice
251 password=secret-passwd
252 EOF
253 '
254
255 test_expect_success 'access using auto proactive auth with authtype from credential helper' '
256 test_when_finished "per_test_cleanup" &&
257
258 set_credential_reply get <<-EOF &&
259 capability[]=authtype
260 authtype=Bearer
261 credential=YS1naXQtdG9rZW4=
262 EOF
263
264 # Basic base64(a-git-token)
265 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
266 id=1 creds=Bearer YS1naXQtdG9rZW4=
267 EOF
268
269 CHALLENGE="$HTTPD_ROOT_PATH/custom-auth.challenge" &&
270
271 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
272 id=1 status=200
273 id=default status=403
274 EOF
275
276 test_config_global credential.helper test-helper &&
277 test_config_global http.proactiveAuth auto &&
278 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
279
280 expect_credential_query get <<-EOF &&
281 capability[]=authtype
282 capability[]=state
283 protocol=http
284 host=$HTTPD_DEST
285 EOF
286
287 expect_credential_query store <<-EOF
288 capability[]=authtype
289 authtype=Bearer
290 credential=YS1naXQtdG9rZW4=
291 protocol=http
292 host=$HTTPD_DEST
293 EOF
294 '
295
296 test_expect_success 'access using basic auth with extra challenges' '
297 test_when_finished "per_test_cleanup" &&
298
299 set_credential_reply get <<-EOF &&
300 username=alice
301 password=secret-passwd
302 EOF
303
304 # Basic base64(alice:secret-passwd)
305 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
306 id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
307 EOF
308
309 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
310 id=1 status=200
311 id=default response=WWW-Authenticate: FooBar param1="value1" param2="value2"
312 id=default response=WWW-Authenticate: Bearer authorize_uri="id.example.com" p=1 q=0
313 id=default response=WWW-Authenticate: Basic realm="example.com"
314 EOF
315
316 test_config_global credential.helper test-helper &&
317 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
318
319 expect_credential_query get <<-EOF &&
320 capability[]=authtype
321 capability[]=state
322 protocol=http
323 host=$HTTPD_DEST
324 wwwauth[]=FooBar param1="value1" param2="value2"
325 wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0
326 wwwauth[]=Basic realm="example.com"
327 EOF
328
329 expect_credential_query store <<-EOF
330 protocol=http
331 host=$HTTPD_DEST
332 username=alice
333 password=secret-passwd
334 EOF
335 '
336
337 test_expect_success 'access using basic auth mixed-case wwwauth header name' '
338 test_when_finished "per_test_cleanup" &&
339
340 set_credential_reply get <<-EOF &&
341 username=alice
342 password=secret-passwd
343 EOF
344
345 # Basic base64(alice:secret-passwd)
346 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
347 id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
348 EOF
349
350 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
351 id=1 status=200
352 id=default response=www-authenticate: foobar param1="value1" param2="value2"
353 id=default response=WWW-AUTHENTICATE: BEARER authorize_uri="id.example.com" p=1 q=0
354 id=default response=WwW-aUtHeNtIcAtE: baSiC realm="example.com"
355 EOF
356
357 test_config_global credential.helper test-helper &&
358 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
359
360 expect_credential_query get <<-EOF &&
361 capability[]=authtype
362 capability[]=state
363 protocol=http
364 host=$HTTPD_DEST
365 wwwauth[]=foobar param1="value1" param2="value2"
366 wwwauth[]=BEARER authorize_uri="id.example.com" p=1 q=0
367 wwwauth[]=baSiC realm="example.com"
368 EOF
369
370 expect_credential_query store <<-EOF
371 protocol=http
372 host=$HTTPD_DEST
373 username=alice
374 password=secret-passwd
375 EOF
376 '
377
378 test_expect_success 'access using basic auth with wwwauth header continuations' '
379 test_when_finished "per_test_cleanup" &&
380
381 set_credential_reply get <<-EOF &&
382 username=alice
383 password=secret-passwd
384 EOF
385
386 # Basic base64(alice:secret-passwd)
387 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
388 id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
389 EOF
390
391 # Note that leading and trailing whitespace is important to correctly
392 # simulate a continuation/folded header.
393 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
394 id=1 status=200
395 id=default response=WWW-Authenticate: FooBar param1="value1"
396 id=default response= param2="value2"
397 id=default response=WWW-Authenticate: Bearer authorize_uri="id.example.com"
398 id=default response= p=1
399 id=default response= q=0
400 id=default response=WWW-Authenticate: Basic realm="example.com"
401 EOF
402
403 test_config_global credential.helper test-helper &&
404 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
405
406 expect_credential_query get <<-EOF &&
407 capability[]=authtype
408 capability[]=state
409 protocol=http
410 host=$HTTPD_DEST
411 wwwauth[]=FooBar param1="value1" param2="value2"
412 wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0
413 wwwauth[]=Basic realm="example.com"
414 EOF
415
416 expect_credential_query store <<-EOF
417 protocol=http
418 host=$HTTPD_DEST
419 username=alice
420 password=secret-passwd
421 EOF
422 '
423
424 test_expect_success 'access using basic auth with wwwauth header empty continuations' '
425 test_when_finished "per_test_cleanup" &&
426
427 set_credential_reply get <<-EOF &&
428 username=alice
429 password=secret-passwd
430 EOF
431
432 # Basic base64(alice:secret-passwd)
433 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
434 id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
435 EOF
436
437 CHALLENGE="$HTTPD_ROOT_PATH/custom-auth.challenge" &&
438
439 # Note that leading and trailing whitespace is important to correctly
440 # simulate a continuation/folded header.
441 printf "id=1 status=200\n" >"$CHALLENGE" &&
442 printf "id=default response=WWW-Authenticate: FooBar param1=\"value1\"\r\n" >>"$CHALLENGE" &&
443 printf "id=default response= \r\n" >>"$CHALLENGE" &&
444 printf "id=default response= param2=\"value2\"\r\n" >>"$CHALLENGE" &&
445 printf "id=default response=WWW-Authenticate: Bearer authorize_uri=\"id.example.com\"\r\n" >>"$CHALLENGE" &&
446 printf "id=default response= p=1\r\n" >>"$CHALLENGE" &&
447 printf "id=default response= \r\n" >>"$CHALLENGE" &&
448 printf "id=default response= q=0\r\n" >>"$CHALLENGE" &&
449 printf "id=default response=WWW-Authenticate: Basic realm=\"example.com\"\r\n" >>"$CHALLENGE" &&
450
451 test_config_global credential.helper test-helper &&
452 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
453
454 expect_credential_query get <<-EOF &&
455 capability[]=authtype
456 capability[]=state
457 protocol=http
458 host=$HTTPD_DEST
459 wwwauth[]=FooBar param1="value1" param2="value2"
460 wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0
461 wwwauth[]=Basic realm="example.com"
462 EOF
463
464 expect_credential_query store <<-EOF
465 protocol=http
466 host=$HTTPD_DEST
467 username=alice
468 password=secret-passwd
469 EOF
470 '
471
472 test_expect_success 'access using basic auth with wwwauth header mixed continuations' '
473 test_when_finished "per_test_cleanup" &&
474
475 set_credential_reply get <<-EOF &&
476 username=alice
477 password=secret-passwd
478 EOF
479
480 # Basic base64(alice:secret-passwd)
481 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
482 id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
483 EOF
484
485 CHALLENGE="$HTTPD_ROOT_PATH/custom-auth.challenge" &&
486
487 # Note that leading and trailing whitespace is important to correctly
488 # simulate a continuation/folded header.
489 printf "id=1 status=200\n" >"$CHALLENGE" &&
490 printf "id=default response=WWW-Authenticate: FooBar param1=\"value1\"\r\n" >>"$CHALLENGE" &&
491 printf "id=default response= \r\n" >>"$CHALLENGE" &&
492 printf "id=default response=\tparam2=\"value2\"\r\n" >>"$CHALLENGE" &&
493 printf "id=default response=WWW-Authenticate: Basic realm=\"example.com\"\r\n" >>"$CHALLENGE" &&
494
495 test_config_global credential.helper test-helper &&
496 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
497
498 expect_credential_query get <<-EOF &&
499 capability[]=authtype
500 capability[]=state
501 protocol=http
502 host=$HTTPD_DEST
503 wwwauth[]=FooBar param1="value1" param2="value2"
504 wwwauth[]=Basic realm="example.com"
505 EOF
506
507 expect_credential_query store <<-EOF
508 protocol=http
509 host=$HTTPD_DEST
510 username=alice
511 password=secret-passwd
512 EOF
513 '
514
515 test_expect_success 'access using bearer auth' '
516 test_when_finished "per_test_cleanup" &&
517
518 set_credential_reply get <<-EOF &&
519 capability[]=authtype
520 authtype=Bearer
521 credential=YS1naXQtdG9rZW4=
522 EOF
523
524 # Basic base64(a-git-token)
525 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
526 id=1 creds=Bearer YS1naXQtdG9rZW4=
527 EOF
528
529 CHALLENGE="$HTTPD_ROOT_PATH/custom-auth.challenge" &&
530
531 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
532 id=1 status=200
533 id=default response=WWW-Authenticate: FooBar param1="value1" param2="value2"
534 id=default response=WWW-Authenticate: Bearer authorize_uri="id.example.com" p=1 q=0
535 id=default response=WWW-Authenticate: Basic realm="example.com"
536 EOF
537
538 test_config_global credential.helper test-helper &&
539 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
540
541 expect_credential_query get <<-EOF &&
542 capability[]=authtype
543 capability[]=state
544 protocol=http
545 host=$HTTPD_DEST
546 wwwauth[]=FooBar param1="value1" param2="value2"
547 wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0
548 wwwauth[]=Basic realm="example.com"
549 EOF
550
551 expect_credential_query store <<-EOF
552 capability[]=authtype
553 authtype=Bearer
554 credential=YS1naXQtdG9rZW4=
555 protocol=http
556 host=$HTTPD_DEST
557 EOF
558 '
559
560 test_expect_success 'access using bearer auth with invalid credentials' '
561 test_when_finished "per_test_cleanup" &&
562
563 set_credential_reply get <<-EOF &&
564 capability[]=authtype
565 authtype=Bearer
566 credential=incorrect-token
567 EOF
568
569 # Basic base64(a-git-token)
570 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
571 id=1 creds=Bearer YS1naXQtdG9rZW4=
572 EOF
573
574 CHALLENGE="$HTTPD_ROOT_PATH/custom-auth.challenge" &&
575
576 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
577 id=1 status=200
578 id=default response=WWW-Authenticate: FooBar param1="value1" param2="value2"
579 id=default response=WWW-Authenticate: Bearer authorize_uri="id.example.com" p=1 q=0
580 id=default response=WWW-Authenticate: Basic realm="example.com"
581 EOF
582
583 test_config_global credential.helper test-helper &&
584 test_must_fail git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
585
586 expect_credential_query get <<-EOF &&
587 capability[]=authtype
588 capability[]=state
589 protocol=http
590 host=$HTTPD_DEST
591 wwwauth[]=FooBar param1="value1" param2="value2"
592 wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0
593 wwwauth[]=Basic realm="example.com"
594 EOF
595
596 expect_credential_query erase <<-EOF
597 capability[]=authtype
598 authtype=Bearer
599 credential=incorrect-token
600 protocol=http
601 host=$HTTPD_DEST
602 wwwauth[]=FooBar param1="value1" param2="value2"
603 wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0
604 wwwauth[]=Basic realm="example.com"
605 EOF
606 '
607
608 test_expect_success 'clone with bearer auth and probe_rpc' '
609 test_when_finished "per_test_cleanup" &&
610 test_when_finished "rm -rf large.git" &&
611
612 # Set up a repository large enough to trigger probe_rpc
613 git init large.git &&
614 (
615 cd large.git &&
616 git config set maintenance.auto false &&
617 git commit --allow-empty --message "initial" &&
618 # Create many refs to trigger probe_rpc, which is called when
619 # the request body is larger than http.postBuffer.
620 #
621 # In the test later, http.postBuffer is set to 70000. Each
622 # "want" line is ~45 bytes, so we need at least 70000/45 = ~1600
623 # refs
624 test_seq -f "create refs/heads/branch-%d @" 2000 |
625 git update-ref --stdin
626 ) &&
627 git clone --bare large.git "$HTTPD_DOCUMENT_ROOT_PATH/large.git" &&
628
629 # Clone it through HTTP with a Bearer token
630 set_credential_reply get <<-EOF &&
631 capability[]=authtype
632 authtype=Bearer
633 credential=YS1naXQtdG9rZW4=
634 EOF
635
636 # Bearer token
637 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
638 id=1 creds=Bearer YS1naXQtdG9rZW4=
639 EOF
640
641 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
642 id=1 status=200
643 id=default response=WWW-Authenticate: Bearer authorize_uri="id.example.com"
644 EOF
645
646 # Set a small buffer to force probe_rpc to be called
647 # Must be > LARGE_PACKET_MAX (65520)
648 test_config_global http.postBuffer 70000 &&
649 test_config_global credential.helper test-helper &&
650 git clone "$HTTPD_URL/custom_auth/large.git" partial-auth-clone 2>clone-error
651 '
652
653 test_expect_success 'access using three-legged auth' '
654 test_when_finished "per_test_cleanup" &&
655
656 set_credential_reply get <<-EOF &&
657 capability[]=authtype
658 capability[]=state
659 authtype=Multistage
660 credential=YS1naXQtdG9rZW4=
661 state[]=helper:foobar
662 continue=1
663 EOF
664
665 set_credential_reply get foobar <<-EOF &&
666 capability[]=authtype
667 capability[]=state
668 authtype=Multistage
669 credential=YW5vdGhlci10b2tlbg==
670 state[]=helper:bazquux
671 EOF
672
673 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
674 id=1 creds=Multistage YS1naXQtdG9rZW4=
675 id=2 creds=Multistage YW5vdGhlci10b2tlbg==
676 EOF
677
678 CHALLENGE="$HTTPD_ROOT_PATH/custom-auth.challenge" &&
679
680 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
681 id=1 status=401 response=WWW-Authenticate: Multistage challenge="456"
682 id=1 status=401 response=WWW-Authenticate: Bearer authorize_uri="id.example.com" p=1 q=0
683 id=2 status=200
684 id=default response=WWW-Authenticate: Multistage challenge="123"
685 id=default response=WWW-Authenticate: Bearer authorize_uri="id.example.com" p=1 q=0
686 EOF
687
688 test_config_global credential.helper test-helper &&
689 git ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
690
691 expect_credential_query get <<-EOF &&
692 capability[]=authtype
693 capability[]=state
694 protocol=http
695 host=$HTTPD_DEST
696 wwwauth[]=Multistage challenge="123"
697 wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0
698 EOF
699
700 expect_credential_query get foobar <<-EOF &&
701 capability[]=authtype
702 capability[]=state
703 authtype=Multistage
704 protocol=http
705 host=$HTTPD_DEST
706 wwwauth[]=Multistage challenge="456"
707 wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0
708 state[]=helper:foobar
709 EOF
710
711 expect_credential_query store bazquux <<-EOF
712 capability[]=authtype
713 capability[]=state
714 authtype=Multistage
715 credential=YW5vdGhlci10b2tlbg==
716 protocol=http
717 host=$HTTPD_DEST
718 state[]=helper:bazquux
719 EOF
720 '
721
722 test_lazy_prereq SPNEGO 'curl --version | grep -qi "SPNEGO\|GSS-API\|Kerberos\|negotiate"'
723
724 test_expect_success SPNEGO 'http.emptyAuth=auto attempts Negotiate before credential_fill' '
725 test_when_finished "per_test_cleanup" &&
726
727 set_credential_reply get <<-EOF &&
728 username=alice
729 password=secret-passwd
730 EOF
731
732 # Basic base64(alice:secret-passwd)
733 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
734 id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
735 EOF
736
737 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
738 id=1 status=200
739 id=default response=WWW-Authenticate: Negotiate
740 id=default response=WWW-Authenticate: Basic realm="example.com"
741 EOF
742
743 test_config_global credential.helper test-helper &&
744 GIT_TRACE_CURL="$TRASH_DIRECTORY/trace-auto" \
745 git -c http.emptyAuth=auto \
746 ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
747
748 # In auto mode with a Negotiate+Basic server, there should be
749 # three 401 responses: (1) initial no-auth request, (2) empty-auth
750 # retry where Negotiate fails (no Kerberos ticket), (3) libcurl
751 # internal Negotiate retry. The fourth attempt uses Basic
752 # credentials from credential_fill and succeeds.
753 grep "HTTP/[0-9.]* 401" "$TRASH_DIRECTORY/trace-auto" >actual_401s &&
754 test_line_count = 3 actual_401s &&
755
756 expect_credential_query get <<-EOF
757 capability[]=authtype
758 capability[]=state
759 protocol=http
760 host=$HTTPD_DEST
761 wwwauth[]=Negotiate
762 wwwauth[]=Basic realm="example.com"
763 EOF
764 '
765
766 test_expect_success SPNEGO 'http.emptyAuth=false skips Negotiate' '
767 test_when_finished "per_test_cleanup" &&
768
769 set_credential_reply get <<-EOF &&
770 username=alice
771 password=secret-passwd
772 EOF
773
774 # Basic base64(alice:secret-passwd)
775 cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF &&
776 id=1 creds=Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA==
777 EOF
778
779 cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF &&
780 id=1 status=200
781 id=default response=WWW-Authenticate: Negotiate
782 id=default response=WWW-Authenticate: Basic realm="example.com"
783 EOF
784
785 test_config_global credential.helper test-helper &&
786 GIT_TRACE_CURL="$TRASH_DIRECTORY/trace-false" \
787 git -c http.emptyAuth=false \
788 ls-remote "$HTTPD_URL/custom_auth/repo.git" &&
789
790 # With emptyAuth=false, Negotiate is stripped immediately and
791 # credential_fill is called right away. Only one 401 response.
792 grep "HTTP/[0-9.]* 401" "$TRASH_DIRECTORY/trace-false" >actual_401s &&
793 test_line_count = 1 actual_401s
794 '
795
796 test_done