]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5551-http-fetch-smart.sh
t5551: stop forcing clone to run with v0 protocol
[thirdparty/git.git] / t / t5551-http-fetch-smart.sh
CommitLineData
7da4e228
SP
1#!/bin/sh
2
8dfe36b0 3: ${HTTP_PROTO:=HTTP/1.1}
73c49a44 4test_description="test smart fetching over http via http-backend ($HTTP_PROTO)"
028cb644 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
7da4e228 8. ./test-lib.sh
7da4e228 9. "$TEST_DIRECTORY"/lib-httpd.sh
73c49a44 10test "$HTTP_PROTO" = "HTTP/2" && enable_http2
7da4e228
SP
11start_httpd
12
73c49a44
JK
13test_expect_success HTTP2 'enable client-side http/2' '
14 git config --global http.version HTTP/2
15'
16
7da4e228 17test_expect_success 'setup repository' '
bd7ac599 18 git config push.default matching &&
7da4e228
SP
19 echo content >file &&
20 git add file &&
21 git commit -m one
22'
23
24test_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" &&
028cb644 30 git push public main:main
7da4e228
SP
31'
32
6ac2b3ae
JK
33setup_askpass_helper
34
7da4e228 35test_expect_success 'clone http repository' '
8dfe36b0 36 cat >exp <<-EOF &&
92b7fd87 37 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
4a21230a
JK
38 > accept: */*
39 > accept-encoding: ENCODINGS
40 > accept-language: ko-KR, *;q=0.9
41 > pragma: no-cache
8dfe36b0 42 < $HTTP_PROTO 200 OK
4a21230a
JK
43 < pragma: no-cache
44 < cache-control: no-cache, max-age=0, must-revalidate
45 < content-type: application/x-git-upload-pack-advertisement
92b7fd87 46 > POST /smart/repo.git/git-upload-pack HTTP/1.1
4a21230a
JK
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
92b7fd87 52 < HTTP/1.1 200 OK
4a21230a
JK
53 < pragma: no-cache
54 < cache-control: no-cache, max-age=0, must-revalidate
55 < content-type: application/x-git-upload-pack-result
92b7fd87 56 EOF
b0c4adcd 57
2f87277d 58 GIT_TRACE_CURL=true LANGUAGE="ko_KR.UTF-8" \
8cbeba06 59 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
7da4e228
SP
60 test_cmp file clone/file &&
61 tr '\''\015'\'' Q <err |
4a21230a
JK
62 perl -pe '\''
63 s/(Send|Recv) header: ([A-Za-z0-9-]+):/
64 "$1 header: " . lc($2) . ":"
65 /e;
66 '\'' |
7da4e228
SP
67 sed -e "
68 s/Q\$//
69 /^[*] /d
14e24114
EP
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
0a8fcbdc
SP
79 /^$/d
80 /^< $/d
7da4e228
SP
81
82 /^[^><]/{
83 s/^/> /
84 }
85
8dfe36b0
JK
86 /^< HTTP/ {
87 s/200$/200 OK/
88 }
89 /^< HTTP\\/1.1 101/d
90 /^[><] connection: /d
91 /^[><] upgrade: /d
92 /^> http2-settings: /d
93
4a21230a
JK
94 /^> user-agent: /d
95 /^> host: /d
20366635
SP
96 /^> POST /,$ {
97 /^> Accept: [*]\\/[*]/d
98 }
4a21230a 99 s/^> content-length: .*/> content-length: xxx/
0a8fcbdc
SP
100 /^> 00..want /d
101 /^> 00.*done/d
7da4e228 102
4a21230a
JK
103 /^< server: /d
104 /^< expires: /d
105 /^< date: /d
106 /^< content-length: /d
107 /^< transfer-encoding: /d
1a53e692 108 " >actual &&
1a53e692 109
d790ee17
JT
110 # NEEDSWORK: If the overspecification of the expected result is reduced, we
111 # might be able to run this test in all protocol versions.
8a1b0978 112 if test "$GIT_TEST_PROTOCOL_VERSION" = 0
d790ee17 113 then
4a21230a 114 sed -e "s/^> accept-encoding: .*/> accept-encoding: ENCODINGS/" \
d790ee17
JT
115 actual >actual.smudged &&
116 test_cmp exp actual.smudged &&
117
4a21230a 118 grep "accept-encoding:.*gzip" actual >actual.gzip &&
a58f4d63 119 test_line_count = 2 actual.gzip
d790ee17 120 fi
7da4e228
SP
121'
122
123test_expect_success 'fetch changes via http' '
124 echo content >>file &&
125 git commit -a -m two &&
99094a7a 126 git push public &&
7da4e228
SP
127 (cd clone && git pull) &&
128 test_cmp file clone/file
129'
130
7da4e228 131test_expect_success 'used upload-pack service' '
92b7fd87
TG
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
137 EOF
d790ee17
JT
138
139 # NEEDSWORK: If the overspecification of the expected result is reduced, we
140 # might be able to run this test in all protocol versions.
8a1b0978 141 if test "$GIT_TEST_PROTOCOL_VERSION" = 0
d790ee17
JT
142 then
143 check_access_log exp
144 fi
7da4e228
SP
145'
146
311e2ea0
TRC
147test_expect_success 'follow redirects (301)' '
148 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
149'
150
151test_expect_success 'follow redirects (302)' '
152 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
153'
154
050ef365
JK
155test_expect_success 'redirects re-root further requests' '
156 git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
157'
158
6628eb41
JK
159test_expect_success 're-rooting dies on insane schemes' '
160 test_must_fail git clone $HTTPD_URL/insane-redir/repo.git insane
161'
162
6ac2b3ae
JK
163test_expect_success 'clone from password-protected repository' '
164 echo two >expect &&
afbf5ca5 165 set_askpass user@host pass@host &&
6ac2b3ae
JK
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
170'
171
4c71009d
JK
172test_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
179'
180
2e736fd5
JK
181test_expect_success 'clone from auth-only-for-objects repository' '
182 echo two >expect &&
afbf5ca5 183 set_askpass user@host pass@host &&
2e736fd5
JK
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
188'
189
190test_expect_success 'no-op half-auth fetch does not require a password' '
191 set_askpass wrong &&
3a9e1ad7
JT
192
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
5db92105
ÆAB
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.
3a9e1ad7 202 GIT_TEST_PROTOCOL_VERSION=0 git --git-dir=half-auth fetch &&
2e736fd5
JK
203 expect_askpass none
204'
205
050ef365 206test_expect_success 'redirects send auth to new location' '
afbf5ca5 207 set_askpass user@host pass@host &&
050ef365
JK
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
211'
212
b637a41e 213test_expect_success 'GIT_TRACE_CURL redacts auth details' '
373e9bd6
JT
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 &&
218
219 # Ensure that there is no "Basic" followed by a base64 string, but that
220 # the auth details are redacted
b66c77a6
JK
221 ! grep -i "Authorization: Basic [0-9a-zA-Z+/]" trace &&
222 grep -i "Authorization: Basic <redacted>" trace
373e9bd6
JT
223'
224
b637a41e 225test_expect_success 'GIT_CURL_VERBOSE redacts auth details' '
7167a62b
JT
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 &&
230
231 # Ensure that there is no "Basic" followed by a base64 string, but that
232 # the auth details are redacted
b66c77a6
JK
233 ! grep -i "Authorization: Basic [0-9a-zA-Z+/]" trace &&
234 grep -i "Authorization: Basic <redacted>" trace
7167a62b
JT
235'
236
827e7d4d
JT
237test_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 &&
243
b66c77a6 244 grep -i "Authorization: Basic [0-9a-zA-Z+/]" trace
827e7d4d
JT
245'
246
02572c2e
JK
247test_expect_success 'disable dumb http on server' '
248 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
249 config http.getanyfile false
250'
251
252test_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)
257'
258
4656bf47 259test_expect_success 'invalid Content-Type rejected' '
8fb26872 260 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
e532a90a 261 test_i18ngrep "not valid:" actual
4656bf47
SP
262'
263
6130f86d
JK
264test_expect_success 'create namespaced refs' '
265 test_commit namespaced &&
028cb644 266 git push public HEAD:refs/namespaces/ns/refs/heads/main &&
6130f86d 267 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
028cb644 268 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/main
6130f86d
JK
269'
270
271test_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
276'
277
278test_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
286'
287
912b2acf 288test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
92b7fd87
TG
289 cat >cookies.txt <<-\EOF &&
290 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
291 EOF
29e8dc50 292 sort >expect_cookies.txt <<-\EOF &&
92b7fd87
TG
293
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
296 EOF
912b2acf
DB
297 git config http.cookiefile cookies.txt &&
298 git config http.savecookies true &&
028cb644 299 git ls-remote $HTTPD_URL/smart_cookies/repo.git main &&
d790ee17
JT
300
301 # NEEDSWORK: If the overspecification of the expected result is reduced, we
302 # might be able to run this test in all protocol versions.
8a1b0978 303 if test "$GIT_TEST_PROTOCOL_VERSION" = 0
d790ee17
JT
304 then
305 tail -3 cookies.txt | sort >cookies_tail.txt &&
306 test_cmp expect_cookies.txt cookies_tail.txt
307 fi
912b2acf
DB
308'
309
e172755b
JK
310test_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
319'
320
cc969c8d
JK
321# create an arbitrary number of tags, numbered from tag-$1 to tag-$2
322create_tags () {
323 rm -f marks &&
324 for i in $(test_seq "$1" "$2")
7103d254 325 do
cc969c8d
JK
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" &&
7103d254
IT
335 # make every commit dangling by always
336 # rewinding the branch after each commit
cc969c8d
JK
337 echo "reset refs/heads/too-many-refs-$1" &&
338 echo "from :$1"
7103d254
IT
339 done | git fast-import --export-marks=marks &&
340
341 # now assign tags to all the dangling commits we created above
94221d22 342 tag=$(perl -e "print \"bla\" x 30") &&
5e2c7cd2 343 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
cc969c8d
JK
344}
345
7419a03f 346test_expect_success 'create 2,000 tags in the repo' '
cc969c8d
JK
347 (
348 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
7419a03f 349 create_tags 1 2000
7103d254
IT
350 )
351'
352
376e4b39
JK
353test_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 &&
5e2c7cd2
JH
356 (
357 cd too-many-refs &&
376e4b39
JK
358 git for-each-ref refs/tags >actual &&
359 test_line_count = 2000 actual
5e2c7cd2 360 )
7103d254
IT
361'
362
8d45ad8c 363test_expect_success 'large fetch-pack requests can be sent using chunked encoding' '
14e24114 364 GIT_TRACE_CURL=true git -c http.postbuffer=65536 \
376e4b39 365 clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
73c49a44
JK
366 {
367 test_have_prereq HTTP2 ||
368 grep "^=> Send header: Transfer-Encoding: chunked" err
369 }
376e4b39
JK
370'
371
296b847c
DT
372test_expect_success 'test allowreachablesha1inwant' '
373 test_when_finished "rm -rf test_reachable.git" &&
374 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
028cb644 375 main_sha=$(git -C "$server" rev-parse refs/heads/main) &&
296b847c
DT
376 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
377
378 git init --bare test_reachable.git &&
379 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
028cb644 380 git -C test_reachable.git fetch origin "$main_sha"
296b847c
DT
381'
382
383test_expect_success 'test allowreachablesha1inwant with unreachable' '
384 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
385
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 &&
392
393 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
028cb644 394 main_sha=$(git -C "$server" rev-parse refs/heads/main) &&
296b847c
DT
395 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
396
397 git init --bare test_reachable.git &&
398 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
ab0c5f50
JT
399 # Some protocol versions (e.g. 2) support fetching
400 # unadvertised objects, so restrict this test to v0.
8a1b0978 401 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
ab0c5f50 402 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
296b847c
DT
403'
404
f8edeaa0
DT
405test_expect_success 'test allowanysha1inwant with unreachable' '
406 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
407
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 &&
414
415 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
028cb644 416 main_sha=$(git -C "$server" rev-parse refs/heads/main) &&
f8edeaa0
DT
417 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
418
419 git init --bare test_reachable.git &&
420 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
ab0c5f50
JT
421 # Some protocol versions (e.g. 2) support fetching
422 # unadvertised objects, so restrict this test to v0.
8a1b0978 423 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
ab0c5f50 424 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)" &&
f8edeaa0
DT
425
426 git -C "$server" config uploadpack.allowanysha1inwant 1 &&
427 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
428'
429
6bc0cb51 430test_expect_success EXPENSIVE 'http can handle enormous ref negotiation' '
7419a03f
JH
431 (
432 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
433 create_tags 2001 50000
434 ) &&
6bc0cb51
JK
435 git -C too-many-refs fetch -q --tags &&
436 (
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
443'
444
8cb01e2f 445test_expect_success 'custom http headers' '
e31165ce
JS
446 test_must_fail git -c http.extraheader="x-magic-two: cadabra" \
447 fetch "$HTTPD_URL/smart_headers/repo.git" &&
8cb01e2f
JS
448 git -c http.extraheader="x-magic-one: abra" \
449 -c http.extraheader="x-magic-two: cadabra" \
0bbe7317
JS
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
8cb01e2f
JS
460'
461
e2842b39
JT
462test_expect_success 'using fetch command in remote-curl updates refs' '
463 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/twobranch" &&
464 rm -rf "$SERVER" client &&
465
466 git init "$SERVER" &&
467 test_commit -C "$SERVER" foo &&
468 git -C "$SERVER" update-ref refs/heads/anotherbranch foo &&
469
470 git clone $HTTPD_URL/smart/twobranch client &&
471
472 test_commit -C "$SERVER" bar &&
473 git -C client -c protocol.version=0 fetch &&
474
028cb644
JS
475 git -C "$SERVER" rev-parse main >expect &&
476 git -C client rev-parse origin/main >actual &&
e2842b39
JT
477 test_cmp expect actual
478'
479
e70a3030
JT
480test_expect_success 'fetch by SHA-1 without tag following' '
481 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
482 rm -rf "$SERVER" client &&
483
484 git init "$SERVER" &&
485 test_commit -C "$SERVER" foo &&
486
487 git clone $HTTPD_URL/smart/server client &&
488
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)
493'
494
b637a41e 495test_expect_success 'cookies are redacted by default' '
83411783
JT
496 rm -rf clone &&
497 echo "Set-Cookie: Foo=1" >cookies &&
498 echo "Set-Cookie: Bar=2" >>cookies &&
827e7d4d 499 GIT_TRACE_CURL=true \
7167a62b
JT
500 git -c "http.cookieFile=$(pwd)/cookies" clone \
501 $HTTPD_URL/smart/repo.git clone 2>err &&
b66c77a6
JK
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
7167a62b
JT
506'
507
827e7d4d 508test_expect_success 'empty values of cookies are also redacted' '
7167a62b 509 rm -rf clone &&
827e7d4d
JT
510 echo "Set-Cookie: Foo=" >cookies &&
511 GIT_TRACE_CURL=true \
83411783
JT
512 git -c "http.cookieFile=$(pwd)/cookies" clone \
513 $HTTPD_URL/smart/repo.git clone 2>err &&
b66c77a6 514 grep -i "Cookie:.*Foo=<redacted>" err
83411783
JT
515'
516
827e7d4d 517test_expect_success 'GIT_TRACE_REDACT=0 disables cookie redaction' '
83411783 518 rm -rf clone &&
827e7d4d
JT
519 echo "Set-Cookie: Foo=1" >cookies &&
520 echo "Set-Cookie: Bar=2" >>cookies &&
521 GIT_TRACE_REDACT=0 GIT_TRACE_CURL=true \
83411783
JT
522 git -c "http.cookieFile=$(pwd)/cookies" clone \
523 $HTTPD_URL/smart/repo.git clone 2>err &&
b66c77a6
JK
524 grep -i "Cookie:.*Foo=1" err &&
525 grep -i "Cookie:.*Bar=2" err
83411783
JT
526'
527
8ba18e6f
JT
528test_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 &&
533
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
538'
539
30dea565
JS
540test_expect_success 'server-side error detected' '
541 test_must_fail git clone $HTTPD_URL/error_smart/repo.git 2>actual &&
e532a90a 542 test_i18ngrep "server-side error" actual
30dea565
JS
543'
544
b694f1e4
JK
545test_expect_success 'http auth remembers successful credentials' '
546 rm -f .git-credentials &&
547 test_config credential.helper store &&
548
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 &&
553
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
559'
560
ecf7b129 561test_expect_success 'http auth forgets bogus credentials' '
b694f1e4
JK
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 &&
567 {
568 echo "url=$HTTPD_URL" &&
569 echo "username=bogus" &&
570 echo "password=bogus"
571 } | git credential approve &&
572
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 &&
578
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
584'
585
26146980
JK
586test_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
593'
594
511cfd3b
CC
595test_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
600'
601
762521e8
JK
602# here user%40host is the URL-encoded version of user@host,
603# which is our intentionally-odd username to catch parsing errors
604url_user=$HTTPD_URL_USER/auth/smart/repo.git
605url_userpass=$HTTPD_URL_USER_PASS/auth/smart/repo.git
606url_userblank=$HTTPD_PROTO://user%40host:@$HTTPD_DEST/auth/smart/repo.git
607message="URL .*:<redacted>@.* uses plaintext credentials"
608
609test_expect_success 'clone warns or fails when using username:password' '
610 test_when_finished "rm -rf attempt*" &&
611
612 git -c transfer.credentialsInUrl=allow \
613 clone $url_userpass attempt1 2>err &&
614 ! grep "$message" err &&
615
616 git -c transfer.credentialsInUrl=warn \
617 clone $url_userpass attempt2 2>err &&
618 grep "warning: $message" err >warnings &&
db8016b4 619 test_line_count -ge 1 warnings &&
762521e8
JK
620
621 test_must_fail git -c transfer.credentialsInUrl=die \
622 clone $url_userpass attempt3 2>err &&
623 grep "fatal: $message" err >warnings &&
db8016b4 624 test_line_count -ge 1 warnings &&
762521e8
JK
625
626 test_must_fail git -c transfer.credentialsInUrl=die \
627 clone $url_userblank attempt4 2>err &&
628 grep "fatal: $message" err >warnings &&
db8016b4 629 test_line_count -ge 1 warnings
762521e8
JK
630'
631
632test_expect_success 'clone does not detect username:password when it is https://username@domain:port/' '
633 test_when_finished "rm -rf attempt1" &&
634
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 &&
641
642 git -c transfer.credentialsInUrl=warn clone $url_user attempt1 2>err &&
643 ! grep "uses plaintext credentials" err
644'
645
646test_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 &&
649
650 git -c transfer.credentialsInUrl=warn fetch $url_userpass 2>err &&
651 grep "warning: $message" err >warnings &&
db8016b4 652 test_line_count -ge 1 warnings &&
762521e8
JK
653
654 test_must_fail git -c transfer.credentialsInUrl=die \
655 fetch $url_userpass 2>err &&
656 grep "fatal: $message" err >warnings &&
db8016b4 657 test_line_count -ge 1 warnings &&
762521e8
JK
658
659 test_must_fail git -c transfer.credentialsInUrl=die \
660 fetch $url_userblank 2>err &&
661 grep "fatal: $message" err >warnings &&
db8016b4 662 test_line_count -ge 1 warnings
762521e8
JK
663'
664
665
666test_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 &&
669
670 git -c transfer.credentialsInUrl=warn push $url_userpass 2>err &&
671 grep "warning: $message" err >warnings &&
672
673 test_must_fail git -c transfer.credentialsInUrl=die \
674 push $url_userpass 2>err &&
675 grep "fatal: $message" err >warnings &&
db8016b4 676 test_line_count -ge 1 warnings
762521e8
JK
677'
678
f1449a56
JK
679test_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 &&
683
684 strip_access_log >log &&
685 ! grep "//" log
686'
687
7da4e228 688test_done