Merge branch 'fixes/2.45.1/2.41' into fixes/2.45.1/2.42
[alt-git.git] / t / t5551-http-fetch-smart.sh
blob21b7767cbd313b48a13888c28f5e757e59b394db
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 if test_have_prereq HTTP2 && test "$HTTPD_PROTO" = "https"
37 then
38 # ALPN lets us immediately use HTTP/2; likewise, POSTs with
39 # bodies can use it because they do not need to upgrade
40 INITIAL_PROTO=HTTP/2
41 else
42 # either we are not using HTTP/2, or the initial
43 # request is sent via HTTP/1.1 and asks for upgrade
44 INITIAL_PROTO=HTTP/1.1
45 fi &&
47 cat >exp.raw <<-EOF &&
48 > GET /smart/repo.git/info/refs?service=git-upload-pack $INITIAL_PROTO
49 > accept: */*
50 > accept-encoding: ENCODINGS
51 > accept-language: ko-KR, *;q=0.9
52 > pragma: no-cache
53 {V2} > git-protocol: version=2
54 < $HTTP_PROTO 200 OK
55 < pragma: no-cache
56 < cache-control: no-cache, max-age=0, must-revalidate
57 < content-type: application/x-git-upload-pack-advertisement
58 > POST /smart/repo.git/git-upload-pack $INITIAL_PROTO
59 > accept-encoding: ENCODINGS
60 > content-type: application/x-git-upload-pack-request
61 > accept: application/x-git-upload-pack-result
62 > accept-language: ko-KR, *;q=0.9
63 {V2} > git-protocol: version=2
64 > content-length: xxx
65 < $INITIAL_PROTO 200 OK
66 < pragma: no-cache
67 < cache-control: no-cache, max-age=0, must-revalidate
68 < content-type: application/x-git-upload-pack-result
69 {V2} > POST /smart/repo.git/git-upload-pack $INITIAL_PROTO
70 {V2} > accept-encoding: ENCODINGS
71 {V2} > content-type: application/x-git-upload-pack-request
72 {V2} > accept: application/x-git-upload-pack-result
73 {V2} > accept-language: ko-KR, *;q=0.9
74 {V2} > git-protocol: version=2
75 {V2} > content-length: xxx
76 {V2} < $INITIAL_PROTO 200 OK
77 {V2} < pragma: no-cache
78 {V2} < cache-control: no-cache, max-age=0, must-revalidate
79 {V2} < content-type: application/x-git-upload-pack-result
80 EOF
82 if test "$GIT_TEST_PROTOCOL_VERSION" = 0
83 then
84 sed "/^{V2}/d" <exp.raw >exp
85 else
86 sed "s/^{V2} //" <exp.raw >exp
87 fi &&
89 GIT_TRACE_CURL=true LANGUAGE="ko_KR.UTF-8" \
90 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
91 test_cmp file clone/file &&
92 tr '\''\015'\'' Q <err |
93 perl -pe '\''
94 s/(Send|Recv) header: ([A-Za-z0-9-]+):/
95 "$1 header: " . lc($2) . ":"
96 /e;
97 '\'' |
98 sed -e "
99 s/Q\$//
100 /^[^<=]/d
101 /^== Info:/d
102 /^=> Send header, /d
103 /^=> Send header:$/d
104 /^<= Recv header, /d
105 /^<= Recv header:$/d
106 s/=> Send header: //
107 s/= Recv header://
108 /^<= Recv data/d
109 /^=> Send data/d
110 /^<= Recv SSL data/d
111 /^=> Send SSL data/d
112 /^$/d
113 /^< $/d
115 /^[^><]/{
116 s/^/> /
119 /^< HTTP/ {
120 s/200$/200 OK/
122 /^< HTTP\\/1.1 101/d
123 /^[><] connection: /d
124 /^[><] upgrade: /d
125 /^> http2-settings: /d
127 /^> user-agent: /d
128 /^> host: /d
129 /^> POST /,$ {
130 /^> Accept: [*]\\/[*]/d
132 s/^> content-length: .*/> content-length: xxx/
133 /^> 00..want /d
134 /^> 00.*done/d
136 /^< server: /d
137 /^< expires: /d
138 /^< date: /d
139 /^< content-length: /d
140 /^< transfer-encoding: /d
141 " >actual &&
143 sed -e "s/^> accept-encoding: .*/> accept-encoding: ENCODINGS/" \
144 actual >actual.smudged &&
145 test_cmp exp actual.smudged &&
147 grep "accept-encoding:.*gzip" actual >actual.gzip
150 test_expect_success 'fetch changes via http' '
151 echo content >>file &&
152 git commit -a -m two &&
153 git push public &&
154 (cd clone && git pull) &&
155 test_cmp file clone/file
158 test_expect_success 'used upload-pack service' '
159 strip_access_log >log &&
160 grep "GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/[0-9.]* 200" log &&
161 grep "POST /smart/repo.git/git-upload-pack HTTP/[0-9.]* 200" log
164 test_expect_success 'follow redirects (301)' '
165 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
168 test_expect_success 'follow redirects (302)' '
169 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
172 test_expect_success 'redirects re-root further requests' '
173 git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
176 test_expect_success 're-rooting dies on insane schemes' '
177 test_must_fail git clone $HTTPD_URL/insane-redir/repo.git insane
180 test_expect_success 'clone from password-protected repository' '
181 echo two >expect &&
182 set_askpass user@host pass@host &&
183 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
184 expect_askpass both user@host &&
185 git --git-dir=smart-auth log -1 --format=%s >actual &&
186 test_cmp expect actual
189 test_expect_success 'clone from auth-only-for-push repository' '
190 echo two >expect &&
191 set_askpass wrong &&
192 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
193 expect_askpass none &&
194 git --git-dir=smart-noauth log -1 --format=%s >actual &&
195 test_cmp expect actual
198 test_expect_success 'clone from auth-only-for-objects repository' '
199 echo two >expect &&
200 set_askpass user@host pass@host &&
201 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
202 expect_askpass both user@host &&
203 git --git-dir=half-auth log -1 --format=%s >actual &&
204 test_cmp expect actual
207 test_expect_success 'no-op half-auth fetch does not require a password' '
208 set_askpass wrong &&
210 # NEEDSWORK: When using HTTP(S), protocol v0 supports a "half-auth"
211 # configuration with authentication required only when downloading
212 # objects and not refs, by having the HTTP server only require
213 # authentication for the "git-upload-pack" path and not "info/refs".
214 # This is not possible with protocol v2, since both objects and refs
215 # are obtained from the "git-upload-pack" path. A solution to this is
216 # to teach the server and client to be able to inline ls-refs requests
217 # as an Extra Parameter (see "git help gitformat-pack-protocol"), so that
218 # "info/refs" can serve refs, just like it does in protocol v0.
219 GIT_TEST_PROTOCOL_VERSION=0 git --git-dir=half-auth fetch &&
220 expect_askpass none
223 test_expect_success 'redirects send auth to new location' '
224 set_askpass user@host pass@host &&
225 git -c credential.useHttpPath=true \
226 clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
227 expect_askpass both user@host auth/smart/repo.git
230 test_expect_success 'GIT_TRACE_CURL redacts auth details' '
231 rm -rf redact-auth trace &&
232 set_askpass user@host pass@host &&
233 GIT_TRACE_CURL="$(pwd)/trace" git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth &&
234 expect_askpass both user@host &&
236 # Ensure that there is no "Basic" followed by a base64 string, but that
237 # the auth details are redacted
238 ! grep -i "Authorization: Basic [0-9a-zA-Z+/]" trace &&
239 grep -i "Authorization: Basic <redacted>" trace
242 test_expect_success 'GIT_CURL_VERBOSE redacts auth details' '
243 rm -rf redact-auth trace &&
244 set_askpass user@host pass@host &&
245 GIT_CURL_VERBOSE=1 git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth 2>trace &&
246 expect_askpass both user@host &&
248 # Ensure that there is no "Basic" followed by a base64 string, but that
249 # the auth details are redacted
250 ! grep -i "Authorization: Basic [0-9a-zA-Z+/]" trace &&
251 grep -i "Authorization: Basic <redacted>" trace
254 test_expect_success 'GIT_TRACE_CURL does not redact auth details if GIT_TRACE_REDACT=0' '
255 rm -rf redact-auth trace &&
256 set_askpass user@host pass@host &&
257 GIT_TRACE_REDACT=0 GIT_TRACE_CURL="$(pwd)/trace" \
258 git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth &&
259 expect_askpass both user@host &&
261 grep -i "Authorization: Basic [0-9a-zA-Z+/]" trace
264 test_expect_success 'disable dumb http on server' '
265 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
266 config http.getanyfile false
269 test_expect_success 'GIT_SMART_HTTP can disable smart http' '
270 (GIT_SMART_HTTP=0 &&
271 export GIT_SMART_HTTP &&
272 cd clone &&
273 test_must_fail git fetch)
276 test_expect_success 'invalid Content-Type rejected' '
277 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
278 test_i18ngrep "not valid:" actual
281 test_expect_success 'create namespaced refs' '
282 test_commit namespaced &&
283 git push public HEAD:refs/namespaces/ns/refs/heads/main &&
284 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
285 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/main
288 test_expect_success 'smart clone respects namespace' '
289 git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
290 echo namespaced >expect &&
291 git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
292 test_cmp expect actual
295 test_expect_success 'dumb clone via http-backend respects namespace' '
296 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
297 config http.getanyfile true &&
298 GIT_SMART_HTTP=0 git clone \
299 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
300 echo namespaced >expect &&
301 git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
302 test_cmp expect actual
305 test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
306 cat >cookies.txt <<-\EOF &&
307 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
309 sort >expect_cookies.txt <<-\EOF &&
310 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
311 127.0.0.1 FALSE /smart_cookies/repo.git/ FALSE 0 name value
312 127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
314 git config http.cookiefile cookies.txt &&
315 git config http.savecookies true &&
317 test_when_finished "
318 git --git-dir=\"\$HTTPD_DOCUMENT_ROOT_PATH/repo.git\" \
319 tag -d cookie-tag
320 " &&
321 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
322 tag -m "foo" cookie-tag &&
323 git fetch $HTTPD_URL/smart_cookies/repo.git cookie-tag &&
325 grep "^[^#]" cookies.txt | sort >cookies_stripped.txt &&
326 test_cmp expect_cookies.txt cookies_stripped.txt
329 test_expect_success 'transfer.hiderefs works over smart-http' '
330 test_commit hidden &&
331 test_commit visible &&
332 git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
333 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
334 config transfer.hiderefs refs/heads/a &&
335 git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
336 test_must_fail git -C hidden.git rev-parse --verify a &&
337 git -C hidden.git rev-parse --verify b
340 # create an arbitrary number of tags, numbered from tag-$1 to tag-$2
341 create_tags () {
342 rm -f marks &&
343 for i in $(test_seq "$1" "$2")
345 # don't use here-doc, because it requires a process
346 # per loop iteration
347 echo "commit refs/heads/too-many-refs-$1" &&
348 echo "mark :$i" &&
349 echo "committer git <git@example.com> $i +0000" &&
350 echo "data 0" &&
351 echo "M 644 inline bla.txt" &&
352 echo "data 4" &&
353 echo "bla" &&
354 # make every commit dangling by always
355 # rewinding the branch after each commit
356 echo "reset refs/heads/too-many-refs-$1" &&
357 echo "from :$1"
358 done | git fast-import --export-marks=marks &&
360 # now assign tags to all the dangling commits we created above
361 tag=$(perl -e "print \"bla\" x 30") &&
362 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
365 test_expect_success 'create 2,000 tags in the repo' '
367 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
368 create_tags 1 2000
372 test_expect_success CMDLINE_LIMIT \
373 'clone the 2,000 tag repo to check OS command line overflow' '
374 run_with_limited_cmdline git clone $HTTPD_URL/smart/repo.git too-many-refs &&
376 cd too-many-refs &&
377 git for-each-ref refs/tags >actual &&
378 test_line_count = 2000 actual
382 test_expect_success 'large fetch-pack requests can be sent using chunked encoding' '
383 GIT_TRACE_CURL=true git -c http.postbuffer=65536 \
384 clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
386 test_have_prereq HTTP2 ||
387 grep "^=> Send header: Transfer-Encoding: chunked" err
391 test_expect_success 'test allowreachablesha1inwant' '
392 test_when_finished "rm -rf test_reachable.git" &&
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 git -C test_reachable.git fetch origin "$main_sha"
402 test_expect_success 'test allowreachablesha1inwant with unreachable' '
403 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
405 #create unreachable sha
406 echo content >file2 &&
407 git add file2 &&
408 git commit -m two &&
409 git push public HEAD:refs/heads/doomed &&
410 git push public :refs/heads/doomed &&
412 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
413 main_sha=$(git -C "$server" rev-parse refs/heads/main) &&
414 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
416 git init --bare test_reachable.git &&
417 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
418 # Some protocol versions (e.g. 2) support fetching
419 # unadvertised objects, so restrict this test to v0.
420 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
421 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
424 test_expect_success 'test allowanysha1inwant with unreachable' '
425 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
427 #create unreachable sha
428 echo content >file2 &&
429 git add file2 &&
430 git commit -m two &&
431 git push public HEAD:refs/heads/doomed &&
432 git push public :refs/heads/doomed &&
434 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
435 main_sha=$(git -C "$server" rev-parse refs/heads/main) &&
436 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
438 git init --bare test_reachable.git &&
439 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
440 # Some protocol versions (e.g. 2) support fetching
441 # unadvertised objects, so restrict this test to v0.
442 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
443 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)" &&
445 git -C "$server" config uploadpack.allowanysha1inwant 1 &&
446 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
449 test_expect_success EXPENSIVE 'http can handle enormous ref negotiation' '
451 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
452 create_tags 2001 50000
453 ) &&
454 git -C too-many-refs fetch -q --tags &&
456 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
457 create_tags 50001 100000
458 ) &&
459 git -C too-many-refs fetch -q --tags &&
460 git -C too-many-refs for-each-ref refs/tags >tags &&
461 test_line_count = 100000 tags
464 test_expect_success 'custom http headers' '
465 test_must_fail git -c http.extraheader="x-magic-two: cadabra" \
466 fetch "$HTTPD_URL/smart_headers/repo.git" &&
467 git -c http.extraheader="x-magic-one: abra" \
468 -c http.extraheader="x-magic-two: cadabra" \
469 fetch "$HTTPD_URL/smart_headers/repo.git" &&
470 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
471 git config -f .gitmodules submodule.sub.path sub &&
472 git config -f .gitmodules submodule.sub.url \
473 "$HTTPD_URL/smart_headers/repo.git" &&
474 git submodule init sub &&
475 test_must_fail git submodule update sub &&
476 git -c http.extraheader="x-magic-one: abra" \
477 -c http.extraheader="x-magic-two: cadabra" \
478 submodule update sub
481 test_expect_success 'using fetch command in remote-curl updates refs' '
482 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/twobranch" &&
483 rm -rf "$SERVER" client &&
485 git init "$SERVER" &&
486 test_commit -C "$SERVER" foo &&
487 git -C "$SERVER" update-ref refs/heads/anotherbranch foo &&
489 git clone $HTTPD_URL/smart/twobranch client &&
491 test_commit -C "$SERVER" bar &&
492 git -C client -c protocol.version=0 fetch &&
494 git -C "$SERVER" rev-parse main >expect &&
495 git -C client rev-parse origin/main >actual &&
496 test_cmp expect actual
499 test_expect_success 'fetch by SHA-1 without tag following' '
500 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
501 rm -rf "$SERVER" client &&
503 git init "$SERVER" &&
504 test_commit -C "$SERVER" foo &&
506 git clone $HTTPD_URL/smart/server client &&
508 test_commit -C "$SERVER" bar &&
509 git -C "$SERVER" rev-parse bar >bar_hash &&
510 git -C client -c protocol.version=0 fetch \
511 --no-tags origin $(cat bar_hash)
514 test_expect_success 'cookies are redacted by default' '
515 rm -rf clone &&
516 echo "Set-Cookie: Foo=1" >cookies &&
517 echo "Set-Cookie: Bar=2" >>cookies &&
518 GIT_TRACE_CURL=true \
519 git -c "http.cookieFile=$(pwd)/cookies" clone \
520 $HTTPD_URL/smart/repo.git clone 2>err &&
521 grep -i "Cookie:.*Foo=<redacted>" err &&
522 grep -i "Cookie:.*Bar=<redacted>" err &&
523 ! grep -i "Cookie:.*Foo=1" err &&
524 ! grep -i "Cookie:.*Bar=2" err
527 test_expect_success 'empty values of cookies are also redacted' '
528 rm -rf clone &&
529 echo "Set-Cookie: Foo=" >cookies &&
530 GIT_TRACE_CURL=true \
531 git -c "http.cookieFile=$(pwd)/cookies" clone \
532 $HTTPD_URL/smart/repo.git clone 2>err &&
533 grep -i "Cookie:.*Foo=<redacted>" err
536 test_expect_success 'GIT_TRACE_REDACT=0 disables cookie redaction' '
537 rm -rf clone &&
538 echo "Set-Cookie: Foo=1" >cookies &&
539 echo "Set-Cookie: Bar=2" >>cookies &&
540 GIT_TRACE_REDACT=0 GIT_TRACE_CURL=true \
541 git -c "http.cookieFile=$(pwd)/cookies" clone \
542 $HTTPD_URL/smart/repo.git clone 2>err &&
543 grep -i "Cookie:.*Foo=1" err &&
544 grep -i "Cookie:.*Bar=2" err
547 test_expect_success 'GIT_TRACE_CURL_NO_DATA prevents data from being traced' '
548 rm -rf clone &&
549 GIT_TRACE_CURL=true \
550 git clone $HTTPD_URL/smart/repo.git clone 2>err &&
551 grep "=> Send data" err &&
553 rm -rf clone &&
554 GIT_TRACE_CURL=true GIT_TRACE_CURL_NO_DATA=1 \
555 git clone $HTTPD_URL/smart/repo.git clone 2>err &&
556 ! grep "=> Send data" err
559 test_expect_success 'server-side error detected' '
560 test_must_fail git clone $HTTPD_URL/error_smart/repo.git 2>actual &&
561 test_i18ngrep "server-side error" actual
564 test_expect_success 'http auth remembers successful credentials' '
565 rm -f .git-credentials &&
566 test_config credential.helper store &&
568 # the first request prompts the user...
569 set_askpass user@host pass@host &&
570 git ls-remote "$HTTPD_URL/auth/smart/repo.git" >/dev/null &&
571 expect_askpass both user@host &&
573 # ...and the second one uses the stored value rather than
574 # prompting the user.
575 set_askpass bogus-user bogus-pass &&
576 git ls-remote "$HTTPD_URL/auth/smart/repo.git" >/dev/null &&
577 expect_askpass none
580 test_expect_success 'http auth forgets bogus credentials' '
581 # seed credential store with bogus values. In real life,
582 # this would probably come from a password which worked
583 # for a previous request.
584 rm -f .git-credentials &&
585 test_config credential.helper store &&
587 echo "url=$HTTPD_URL" &&
588 echo "username=bogus" &&
589 echo "password=bogus"
590 } | git credential approve &&
592 # we expect this to use the bogus values and fail, never even
593 # prompting the user...
594 set_askpass user@host pass@host &&
595 test_must_fail git ls-remote "$HTTPD_URL/auth/smart/repo.git" >/dev/null &&
596 expect_askpass none &&
598 # ...but now we should have forgotten the bad value, causing
599 # us to prompt the user again.
600 set_askpass user@host pass@host &&
601 git ls-remote "$HTTPD_URL/auth/smart/repo.git" >/dev/null &&
602 expect_askpass both user@host
605 test_expect_success 'client falls back from v2 to v0 to match server' '
606 GIT_TRACE_PACKET=$PWD/trace \
607 GIT_TEST_PROTOCOL_VERSION=2 \
608 git clone $HTTPD_URL/smart_v0/repo.git repo-v0 &&
609 # check for v0; there the HEAD symref is communicated in the capability
610 # line; v2 uses a different syntax on each ref advertisement line
611 grep symref=HEAD:refs/heads/ trace
614 test_expect_success 'create empty http-accessible SHA-256 repository' '
615 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/sha256.git" &&
616 (cd "$HTTPD_DOCUMENT_ROOT_PATH/sha256.git" &&
617 git --bare init --object-format=sha256
621 test_expect_success 'clone empty SHA-256 repository with protocol v2' '
622 rm -fr sha256 &&
623 echo sha256 >expected &&
624 git -c protocol.version=2 clone "$HTTPD_URL/smart/sha256.git" &&
625 git -C sha256 rev-parse --show-object-format >actual &&
626 test_cmp actual expected &&
627 git ls-remote "$HTTPD_URL/smart/sha256.git" >actual &&
628 test_must_be_empty actual
631 test_expect_success 'clone empty SHA-256 repository with protocol v0' '
632 rm -fr sha256 &&
633 echo sha256 >expected &&
634 GIT_TRACE=1 GIT_TRACE_PACKET=1 git -c protocol.version=0 clone "$HTTPD_URL/smart/sha256.git" &&
635 git -C sha256 rev-parse --show-object-format >actual &&
636 test_cmp actual expected &&
637 git ls-remote "$HTTPD_URL/smart/sha256.git" >actual &&
638 test_must_be_empty actual
641 test_expect_success 'passing hostname resolution information works' '
642 BOGUS_HOST=gitbogusexamplehost.invalid &&
643 BOGUS_HTTPD_URL=$HTTPD_PROTO://$BOGUS_HOST:$LIB_HTTPD_PORT &&
644 test_must_fail git ls-remote "$BOGUS_HTTPD_URL/smart/repo.git" >/dev/null &&
645 git -c "http.curloptResolve=$BOGUS_HOST:$LIB_HTTPD_PORT:127.0.0.1" ls-remote "$BOGUS_HTTPD_URL/smart/repo.git" >/dev/null
648 # here user%40host is the URL-encoded version of user@host,
649 # which is our intentionally-odd username to catch parsing errors
650 url_user=$HTTPD_URL_USER/auth/smart/repo.git
651 url_userpass=$HTTPD_URL_USER_PASS/auth/smart/repo.git
652 url_userblank=$HTTPD_PROTO://user%40host:@$HTTPD_DEST/auth/smart/repo.git
653 message="URL .*:<redacted>@.* uses plaintext credentials"
655 test_expect_success 'clone warns or fails when using username:password' '
656 test_when_finished "rm -rf attempt*" &&
658 git -c transfer.credentialsInUrl=allow \
659 clone $url_userpass attempt1 2>err &&
660 ! grep "$message" err &&
662 git -c transfer.credentialsInUrl=warn \
663 clone $url_userpass attempt2 2>err &&
664 grep "warning: $message" err >warnings &&
665 test_line_count -ge 1 warnings &&
667 test_must_fail git -c transfer.credentialsInUrl=die \
668 clone $url_userpass attempt3 2>err &&
669 grep "fatal: $message" err >warnings &&
670 test_line_count -ge 1 warnings &&
672 test_must_fail git -c transfer.credentialsInUrl=die \
673 clone $url_userblank attempt4 2>err &&
674 grep "fatal: $message" err >warnings &&
675 test_line_count -ge 1 warnings
678 test_expect_success 'clone does not detect username:password when it is https://username@domain:port/' '
679 test_when_finished "rm -rf attempt1" &&
681 # we are relying on lib-httpd for url construction, so document our
682 # assumptions
683 case "$HTTPD_URL_USER" in
684 *:[0-9]*) : ok ;;
685 *) BUG "httpd url does not have port: $HTTPD_URL_USER"
686 esac &&
688 git -c transfer.credentialsInUrl=warn clone $url_user attempt1 2>err &&
689 ! grep "uses plaintext credentials" err
692 test_expect_success 'fetch warns or fails when using username:password' '
693 git -c transfer.credentialsInUrl=allow fetch $url_userpass 2>err &&
694 ! grep "$message" err &&
696 git -c transfer.credentialsInUrl=warn fetch $url_userpass 2>err &&
697 grep "warning: $message" err >warnings &&
698 test_line_count -ge 1 warnings &&
700 test_must_fail git -c transfer.credentialsInUrl=die \
701 fetch $url_userpass 2>err &&
702 grep "fatal: $message" err >warnings &&
703 test_line_count -ge 1 warnings &&
705 test_must_fail git -c transfer.credentialsInUrl=die \
706 fetch $url_userblank 2>err &&
707 grep "fatal: $message" err >warnings &&
708 test_line_count -ge 1 warnings
712 test_expect_success 'push warns or fails when using username:password' '
713 git -c transfer.credentialsInUrl=allow push $url_userpass 2>err &&
714 ! grep "$message" err &&
716 git -c transfer.credentialsInUrl=warn push $url_userpass 2>err &&
717 grep "warning: $message" err >warnings &&
719 test_must_fail git -c transfer.credentialsInUrl=die \
720 push $url_userpass 2>err &&
721 grep "fatal: $message" err >warnings &&
722 test_line_count -ge 1 warnings
725 test_expect_success 'no empty path components' '
726 # In the URL, add a trailing slash, and see if git appends yet another
727 # slash.
728 git clone $HTTPD_URL/smart/repo.git/ clone-with-slash &&
730 strip_access_log >log &&
731 ! grep "//" log
734 test_done