t5551: handle HTTP/2 when checking curl trace
[git.git] / t / t5551-http-fetch-smart.sh
blob716c9dbb6925942ee70f6d64e0adbfd48ef000a4
1 #!/bin/sh
3 : ${HTTP_PROTO:=HTTP/1.1}
4 test_description="test smart fetching over http via http-backend ($HTTP_PROTO)"
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-httpd.sh
10 test "$HTTP_PROTO" = "HTTP/2" && enable_http2
11 start_httpd
13 test_expect_success HTTP2 'enable client-side http/2' '
14 git config --global http.version HTTP/2
17 test_expect_success 'setup repository' '
18 git config push.default matching &&
19 echo content >file &&
20 git add file &&
21 git commit -m one
24 test_expect_success 'create http-accessible bare repository' '
25 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
26 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
27 git --bare init
28 ) &&
29 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
30 git push public main:main
33 setup_askpass_helper
35 test_expect_success 'clone http repository' '
36 cat >exp <<-EOF &&
37 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
38 > accept: */*
39 > accept-encoding: ENCODINGS
40 > accept-language: ko-KR, *;q=0.9
41 > pragma: no-cache
42 < $HTTP_PROTO 200 OK
43 < pragma: no-cache
44 < cache-control: no-cache, max-age=0, must-revalidate
45 < content-type: application/x-git-upload-pack-advertisement
46 > POST /smart/repo.git/git-upload-pack HTTP/1.1
47 > accept-encoding: ENCODINGS
48 > content-type: application/x-git-upload-pack-request
49 > accept: application/x-git-upload-pack-result
50 > accept-language: ko-KR, *;q=0.9
51 > content-length: xxx
52 < HTTP/1.1 200 OK
53 < pragma: no-cache
54 < cache-control: no-cache, max-age=0, must-revalidate
55 < content-type: application/x-git-upload-pack-result
56 EOF
58 GIT_TRACE_CURL=true GIT_TEST_PROTOCOL_VERSION=0 LANGUAGE="ko_KR.UTF-8" \
59 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
60 test_cmp file clone/file &&
61 tr '\''\015'\'' Q <err |
62 perl -pe '\''
63 s/(Send|Recv) header: ([A-Za-z0-9-]+):/
64 "$1 header: " . lc($2) . ":"
65 /e;
66 '\'' |
67 sed -e "
68 s/Q\$//
69 /^[*] /d
70 /^== Info:/d
71 /^=> Send header, /d
72 /^=> Send header:$/d
73 /^<= Recv header, /d
74 /^<= Recv header:$/d
75 s/=> Send header: //
76 s/= Recv header://
77 /^<= Recv data/d
78 /^=> Send data/d
79 /^$/d
80 /^< $/d
82 /^[^><]/{
83 s/^/> /
86 /^< HTTP/ {
87 s/200$/200 OK/
89 /^< HTTP\\/1.1 101/d
90 /^[><] connection: /d
91 /^[><] upgrade: /d
92 /^> http2-settings: /d
94 /^> user-agent: /d
95 /^> host: /d
96 /^> POST /,$ {
97 /^> Accept: [*]\\/[*]/d
99 s/^> content-length: .*/> content-length: xxx/
100 /^> 00..want /d
101 /^> 00.*done/d
103 /^< server: /d
104 /^< expires: /d
105 /^< date: /d
106 /^< content-length: /d
107 /^< transfer-encoding: /d
108 " >actual &&
110 # NEEDSWORK: If the overspecification of the expected result is reduced, we
111 # might be able to run this test in all protocol versions.
112 if test "$GIT_TEST_PROTOCOL_VERSION" = 0
113 then
114 sed -e "s/^> accept-encoding: .*/> accept-encoding: ENCODINGS/" \
115 actual >actual.smudged &&
116 test_cmp exp actual.smudged &&
118 grep "accept-encoding:.*gzip" actual >actual.gzip &&
119 test_line_count = 2 actual.gzip
123 test_expect_success 'fetch changes via http' '
124 echo content >>file &&
125 git commit -a -m two &&
126 git push public &&
127 (cd clone && git pull) &&
128 test_cmp file clone/file
131 test_expect_success 'used upload-pack service' '
132 cat >exp <<-\EOF &&
133 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
134 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
135 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
136 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
139 # NEEDSWORK: If the overspecification of the expected result is reduced, we
140 # might be able to run this test in all protocol versions.
141 if test "$GIT_TEST_PROTOCOL_VERSION" = 0
142 then
143 check_access_log exp
147 test_expect_success 'follow redirects (301)' '
148 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
151 test_expect_success 'follow redirects (302)' '
152 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
155 test_expect_success 'redirects re-root further requests' '
156 git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
159 test_expect_success 're-rooting dies on insane schemes' '
160 test_must_fail git clone $HTTPD_URL/insane-redir/repo.git insane
163 test_expect_success 'clone from password-protected repository' '
164 echo two >expect &&
165 set_askpass user@host pass@host &&
166 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
167 expect_askpass both user@host &&
168 git --git-dir=smart-auth log -1 --format=%s >actual &&
169 test_cmp expect actual
172 test_expect_success 'clone from auth-only-for-push repository' '
173 echo two >expect &&
174 set_askpass wrong &&
175 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
176 expect_askpass none &&
177 git --git-dir=smart-noauth log -1 --format=%s >actual &&
178 test_cmp expect actual
181 test_expect_success 'clone from auth-only-for-objects repository' '
182 echo two >expect &&
183 set_askpass user@host pass@host &&
184 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
185 expect_askpass both user@host &&
186 git --git-dir=half-auth log -1 --format=%s >actual &&
187 test_cmp expect actual
190 test_expect_success 'no-op half-auth fetch does not require a password' '
191 set_askpass wrong &&
193 # NEEDSWORK: When using HTTP(S), protocol v0 supports a "half-auth"
194 # configuration with authentication required only when downloading
195 # objects and not refs, by having the HTTP server only require
196 # authentication for the "git-upload-pack" path and not "info/refs".
197 # This is not possible with protocol v2, since both objects and refs
198 # are obtained from the "git-upload-pack" path. A solution to this is
199 # to teach the server and client to be able to inline ls-refs requests
200 # as an Extra Parameter (see "git help gitformat-pack-protocol"), so that
201 # "info/refs" can serve refs, just like it does in protocol v0.
202 GIT_TEST_PROTOCOL_VERSION=0 git --git-dir=half-auth fetch &&
203 expect_askpass none
206 test_expect_success 'redirects send auth to new location' '
207 set_askpass user@host pass@host &&
208 git -c credential.useHttpPath=true \
209 clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
210 expect_askpass both user@host auth/smart/repo.git
213 test_expect_success 'GIT_TRACE_CURL redacts auth details' '
214 rm -rf redact-auth trace &&
215 set_askpass user@host pass@host &&
216 GIT_TRACE_CURL="$(pwd)/trace" git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth &&
217 expect_askpass both user@host &&
219 # Ensure that there is no "Basic" followed by a base64 string, but that
220 # the auth details are redacted
221 ! grep -i "Authorization: Basic [0-9a-zA-Z+/]" trace &&
222 grep -i "Authorization: Basic <redacted>" trace
225 test_expect_success 'GIT_CURL_VERBOSE redacts auth details' '
226 rm -rf redact-auth trace &&
227 set_askpass user@host pass@host &&
228 GIT_CURL_VERBOSE=1 git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth 2>trace &&
229 expect_askpass both user@host &&
231 # Ensure that there is no "Basic" followed by a base64 string, but that
232 # the auth details are redacted
233 ! grep -i "Authorization: Basic [0-9a-zA-Z+/]" trace &&
234 grep -i "Authorization: Basic <redacted>" trace
237 test_expect_success 'GIT_TRACE_CURL does not redact auth details if GIT_TRACE_REDACT=0' '
238 rm -rf redact-auth trace &&
239 set_askpass user@host pass@host &&
240 GIT_TRACE_REDACT=0 GIT_TRACE_CURL="$(pwd)/trace" \
241 git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth &&
242 expect_askpass both user@host &&
244 grep -i "Authorization: Basic [0-9a-zA-Z+/]" trace
247 test_expect_success 'disable dumb http on server' '
248 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
249 config http.getanyfile false
252 test_expect_success 'GIT_SMART_HTTP can disable smart http' '
253 (GIT_SMART_HTTP=0 &&
254 export GIT_SMART_HTTP &&
255 cd clone &&
256 test_must_fail git fetch)
259 test_expect_success 'invalid Content-Type rejected' '
260 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
261 test_i18ngrep "not valid:" actual
264 test_expect_success 'create namespaced refs' '
265 test_commit namespaced &&
266 git push public HEAD:refs/namespaces/ns/refs/heads/main &&
267 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
268 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/main
271 test_expect_success 'smart clone respects namespace' '
272 git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
273 echo namespaced >expect &&
274 git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
275 test_cmp expect actual
278 test_expect_success 'dumb clone via http-backend respects namespace' '
279 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
280 config http.getanyfile true &&
281 GIT_SMART_HTTP=0 git clone \
282 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
283 echo namespaced >expect &&
284 git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
285 test_cmp expect actual
288 test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
289 cat >cookies.txt <<-\EOF &&
290 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
292 sort >expect_cookies.txt <<-\EOF &&
294 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
295 127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
297 git config http.cookiefile cookies.txt &&
298 git config http.savecookies true &&
299 git ls-remote $HTTPD_URL/smart_cookies/repo.git main &&
301 # NEEDSWORK: If the overspecification of the expected result is reduced, we
302 # might be able to run this test in all protocol versions.
303 if test "$GIT_TEST_PROTOCOL_VERSION" = 0
304 then
305 tail -3 cookies.txt | sort >cookies_tail.txt &&
306 test_cmp expect_cookies.txt cookies_tail.txt
310 test_expect_success 'transfer.hiderefs works over smart-http' '
311 test_commit hidden &&
312 test_commit visible &&
313 git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
314 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
315 config transfer.hiderefs refs/heads/a &&
316 git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
317 test_must_fail git -C hidden.git rev-parse --verify a &&
318 git -C hidden.git rev-parse --verify b
321 # create an arbitrary number of tags, numbered from tag-$1 to tag-$2
322 create_tags () {
323 rm -f marks &&
324 for i in $(test_seq "$1" "$2")
326 # don't use here-doc, because it requires a process
327 # per loop iteration
328 echo "commit refs/heads/too-many-refs-$1" &&
329 echo "mark :$i" &&
330 echo "committer git <git@example.com> $i +0000" &&
331 echo "data 0" &&
332 echo "M 644 inline bla.txt" &&
333 echo "data 4" &&
334 echo "bla" &&
335 # make every commit dangling by always
336 # rewinding the branch after each commit
337 echo "reset refs/heads/too-many-refs-$1" &&
338 echo "from :$1"
339 done | git fast-import --export-marks=marks &&
341 # now assign tags to all the dangling commits we created above
342 tag=$(perl -e "print \"bla\" x 30") &&
343 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
346 test_expect_success 'create 2,000 tags in the repo' '
348 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
349 create_tags 1 2000
353 test_expect_success CMDLINE_LIMIT \
354 'clone the 2,000 tag repo to check OS command line overflow' '
355 run_with_limited_cmdline git clone $HTTPD_URL/smart/repo.git too-many-refs &&
357 cd too-many-refs &&
358 git for-each-ref refs/tags >actual &&
359 test_line_count = 2000 actual
363 test_expect_success 'large fetch-pack requests can be sent using chunked encoding' '
364 GIT_TRACE_CURL=true git -c http.postbuffer=65536 \
365 clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
367 test_have_prereq HTTP2 ||
368 grep "^=> Send header: Transfer-Encoding: chunked" err
372 test_expect_success 'test allowreachablesha1inwant' '
373 test_when_finished "rm -rf test_reachable.git" &&
374 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
375 main_sha=$(git -C "$server" rev-parse refs/heads/main) &&
376 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
378 git init --bare test_reachable.git &&
379 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
380 git -C test_reachable.git fetch origin "$main_sha"
383 test_expect_success 'test allowreachablesha1inwant with unreachable' '
384 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
386 #create unreachable sha
387 echo content >file2 &&
388 git add file2 &&
389 git commit -m two &&
390 git push public HEAD:refs/heads/doomed &&
391 git push public :refs/heads/doomed &&
393 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
394 main_sha=$(git -C "$server" rev-parse refs/heads/main) &&
395 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
397 git init --bare test_reachable.git &&
398 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
399 # Some protocol versions (e.g. 2) support fetching
400 # unadvertised objects, so restrict this test to v0.
401 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
402 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
405 test_expect_success 'test allowanysha1inwant with unreachable' '
406 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
408 #create unreachable sha
409 echo content >file2 &&
410 git add file2 &&
411 git commit -m two &&
412 git push public HEAD:refs/heads/doomed &&
413 git push public :refs/heads/doomed &&
415 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
416 main_sha=$(git -C "$server" rev-parse refs/heads/main) &&
417 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
419 git init --bare test_reachable.git &&
420 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
421 # Some protocol versions (e.g. 2) support fetching
422 # unadvertised objects, so restrict this test to v0.
423 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
424 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)" &&
426 git -C "$server" config uploadpack.allowanysha1inwant 1 &&
427 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
430 test_expect_success EXPENSIVE 'http can handle enormous ref negotiation' '
432 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
433 create_tags 2001 50000
434 ) &&
435 git -C too-many-refs fetch -q --tags &&
437 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
438 create_tags 50001 100000
439 ) &&
440 git -C too-many-refs fetch -q --tags &&
441 git -C too-many-refs for-each-ref refs/tags >tags &&
442 test_line_count = 100000 tags
445 test_expect_success 'custom http headers' '
446 test_must_fail git -c http.extraheader="x-magic-two: cadabra" \
447 fetch "$HTTPD_URL/smart_headers/repo.git" &&
448 git -c http.extraheader="x-magic-one: abra" \
449 -c http.extraheader="x-magic-two: cadabra" \
450 fetch "$HTTPD_URL/smart_headers/repo.git" &&
451 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
452 git config -f .gitmodules submodule.sub.path sub &&
453 git config -f .gitmodules submodule.sub.url \
454 "$HTTPD_URL/smart_headers/repo.git" &&
455 git submodule init sub &&
456 test_must_fail git submodule update sub &&
457 git -c http.extraheader="x-magic-one: abra" \
458 -c http.extraheader="x-magic-two: cadabra" \
459 submodule update sub
462 test_expect_success 'using fetch command in remote-curl updates refs' '
463 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/twobranch" &&
464 rm -rf "$SERVER" client &&
466 git init "$SERVER" &&
467 test_commit -C "$SERVER" foo &&
468 git -C "$SERVER" update-ref refs/heads/anotherbranch foo &&
470 git clone $HTTPD_URL/smart/twobranch client &&
472 test_commit -C "$SERVER" bar &&
473 git -C client -c protocol.version=0 fetch &&
475 git -C "$SERVER" rev-parse main >expect &&
476 git -C client rev-parse origin/main >actual &&
477 test_cmp expect actual
480 test_expect_success 'fetch by SHA-1 without tag following' '
481 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
482 rm -rf "$SERVER" client &&
484 git init "$SERVER" &&
485 test_commit -C "$SERVER" foo &&
487 git clone $HTTPD_URL/smart/server client &&
489 test_commit -C "$SERVER" bar &&
490 git -C "$SERVER" rev-parse bar >bar_hash &&
491 git -C client -c protocol.version=0 fetch \
492 --no-tags origin $(cat bar_hash)
495 test_expect_success 'cookies are redacted by default' '
496 rm -rf clone &&
497 echo "Set-Cookie: Foo=1" >cookies &&
498 echo "Set-Cookie: Bar=2" >>cookies &&
499 GIT_TRACE_CURL=true \
500 git -c "http.cookieFile=$(pwd)/cookies" clone \
501 $HTTPD_URL/smart/repo.git clone 2>err &&
502 grep -i "Cookie:.*Foo=<redacted>" err &&
503 grep -i "Cookie:.*Bar=<redacted>" err &&
504 ! grep -i "Cookie:.*Foo=1" err &&
505 ! grep -i "Cookie:.*Bar=2" err
508 test_expect_success 'empty values of cookies are also redacted' '
509 rm -rf clone &&
510 echo "Set-Cookie: Foo=" >cookies &&
511 GIT_TRACE_CURL=true \
512 git -c "http.cookieFile=$(pwd)/cookies" clone \
513 $HTTPD_URL/smart/repo.git clone 2>err &&
514 grep -i "Cookie:.*Foo=<redacted>" err
517 test_expect_success 'GIT_TRACE_REDACT=0 disables cookie redaction' '
518 rm -rf clone &&
519 echo "Set-Cookie: Foo=1" >cookies &&
520 echo "Set-Cookie: Bar=2" >>cookies &&
521 GIT_TRACE_REDACT=0 GIT_TRACE_CURL=true \
522 git -c "http.cookieFile=$(pwd)/cookies" clone \
523 $HTTPD_URL/smart/repo.git clone 2>err &&
524 grep -i "Cookie:.*Foo=1" err &&
525 grep -i "Cookie:.*Bar=2" err
528 test_expect_success 'GIT_TRACE_CURL_NO_DATA prevents data from being traced' '
529 rm -rf clone &&
530 GIT_TRACE_CURL=true \
531 git clone $HTTPD_URL/smart/repo.git clone 2>err &&
532 grep "=> Send data" err &&
534 rm -rf clone &&
535 GIT_TRACE_CURL=true GIT_TRACE_CURL_NO_DATA=1 \
536 git clone $HTTPD_URL/smart/repo.git clone 2>err &&
537 ! grep "=> Send data" err
540 test_expect_success 'server-side error detected' '
541 test_must_fail git clone $HTTPD_URL/error_smart/repo.git 2>actual &&
542 test_i18ngrep "server-side error" actual
545 test_expect_success 'http auth remembers successful credentials' '
546 rm -f .git-credentials &&
547 test_config credential.helper store &&
549 # the first request prompts the user...
550 set_askpass user@host pass@host &&
551 git ls-remote "$HTTPD_URL/auth/smart/repo.git" >/dev/null &&
552 expect_askpass both user@host &&
554 # ...and the second one uses the stored value rather than
555 # prompting the user.
556 set_askpass bogus-user bogus-pass &&
557 git ls-remote "$HTTPD_URL/auth/smart/repo.git" >/dev/null &&
558 expect_askpass none
561 test_expect_success 'http auth forgets bogus credentials' '
562 # seed credential store with bogus values. In real life,
563 # this would probably come from a password which worked
564 # for a previous request.
565 rm -f .git-credentials &&
566 test_config credential.helper store &&
568 echo "url=$HTTPD_URL" &&
569 echo "username=bogus" &&
570 echo "password=bogus"
571 } | git credential approve &&
573 # we expect this to use the bogus values and fail, never even
574 # prompting the user...
575 set_askpass user@host pass@host &&
576 test_must_fail git ls-remote "$HTTPD_URL/auth/smart/repo.git" >/dev/null &&
577 expect_askpass none &&
579 # ...but now we should have forgotten the bad value, causing
580 # us to prompt the user again.
581 set_askpass user@host pass@host &&
582 git ls-remote "$HTTPD_URL/auth/smart/repo.git" >/dev/null &&
583 expect_askpass both user@host
586 test_expect_success 'client falls back from v2 to v0 to match server' '
587 GIT_TRACE_PACKET=$PWD/trace \
588 GIT_TEST_PROTOCOL_VERSION=2 \
589 git clone $HTTPD_URL/smart_v0/repo.git repo-v0 &&
590 # check for v0; there the HEAD symref is communicated in the capability
591 # line; v2 uses a different syntax on each ref advertisement line
592 grep symref=HEAD:refs/heads/ trace
595 test_expect_success 'passing hostname resolution information works' '
596 BOGUS_HOST=gitbogusexamplehost.invalid &&
597 BOGUS_HTTPD_URL=$HTTPD_PROTO://$BOGUS_HOST:$LIB_HTTPD_PORT &&
598 test_must_fail git ls-remote "$BOGUS_HTTPD_URL/smart/repo.git" >/dev/null &&
599 git -c "http.curloptResolve=$BOGUS_HOST:$LIB_HTTPD_PORT:127.0.0.1" ls-remote "$BOGUS_HTTPD_URL/smart/repo.git" >/dev/null
602 # here user%40host is the URL-encoded version of user@host,
603 # which is our intentionally-odd username to catch parsing errors
604 url_user=$HTTPD_URL_USER/auth/smart/repo.git
605 url_userpass=$HTTPD_URL_USER_PASS/auth/smart/repo.git
606 url_userblank=$HTTPD_PROTO://user%40host:@$HTTPD_DEST/auth/smart/repo.git
607 message="URL .*:<redacted>@.* uses plaintext credentials"
609 test_expect_success 'clone warns or fails when using username:password' '
610 test_when_finished "rm -rf attempt*" &&
612 git -c transfer.credentialsInUrl=allow \
613 clone $url_userpass attempt1 2>err &&
614 ! grep "$message" err &&
616 git -c transfer.credentialsInUrl=warn \
617 clone $url_userpass attempt2 2>err &&
618 grep "warning: $message" err >warnings &&
619 test_line_count -ge 1 warnings &&
621 test_must_fail git -c transfer.credentialsInUrl=die \
622 clone $url_userpass attempt3 2>err &&
623 grep "fatal: $message" err >warnings &&
624 test_line_count -ge 1 warnings &&
626 test_must_fail git -c transfer.credentialsInUrl=die \
627 clone $url_userblank attempt4 2>err &&
628 grep "fatal: $message" err >warnings &&
629 test_line_count -ge 1 warnings
632 test_expect_success 'clone does not detect username:password when it is https://username@domain:port/' '
633 test_when_finished "rm -rf attempt1" &&
635 # we are relying on lib-httpd for url construction, so document our
636 # assumptions
637 case "$HTTPD_URL_USER" in
638 *:[0-9]*) : ok ;;
639 *) BUG "httpd url does not have port: $HTTPD_URL_USER"
640 esac &&
642 git -c transfer.credentialsInUrl=warn clone $url_user attempt1 2>err &&
643 ! grep "uses plaintext credentials" err
646 test_expect_success 'fetch warns or fails when using username:password' '
647 git -c transfer.credentialsInUrl=allow fetch $url_userpass 2>err &&
648 ! grep "$message" err &&
650 git -c transfer.credentialsInUrl=warn fetch $url_userpass 2>err &&
651 grep "warning: $message" err >warnings &&
652 test_line_count -ge 1 warnings &&
654 test_must_fail git -c transfer.credentialsInUrl=die \
655 fetch $url_userpass 2>err &&
656 grep "fatal: $message" err >warnings &&
657 test_line_count -ge 1 warnings &&
659 test_must_fail git -c transfer.credentialsInUrl=die \
660 fetch $url_userblank 2>err &&
661 grep "fatal: $message" err >warnings &&
662 test_line_count -ge 1 warnings
666 test_expect_success 'push warns or fails when using username:password' '
667 git -c transfer.credentialsInUrl=allow push $url_userpass 2>err &&
668 ! grep "$message" err &&
670 git -c transfer.credentialsInUrl=warn push $url_userpass 2>err &&
671 grep "warning: $message" err >warnings &&
673 test_must_fail git -c transfer.credentialsInUrl=die \
674 push $url_userpass 2>err &&
675 grep "fatal: $message" err >warnings &&
676 test_line_count -ge 1 warnings
679 test_expect_success 'no empty path components' '
680 # In the URL, add a trailing slash, and see if git appends yet another
681 # slash.
682 git clone $HTTPD_URL/smart/repo.git/ clone-with-slash &&
684 strip_access_log >log &&
685 ! grep "//" log
688 test_done