]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5550-http-fetch-dumb.sh
The sixth batch
[thirdparty/git.git] / t / t5550-http-fetch-dumb.sh
CommitLineData
119c8eee
JK
1#!/bin/sh
2
7da4e228 3test_description='test dumb fetching over http via static file'
028cb644 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
119c8eee 7. ./test-lib.sh
7b6853a8
HWN
8
9if test_have_prereq !REFFILES
10then
11 skip_all='skipping test; dumb HTTP protocol not supported with reftable.'
12 test_done
13fi
14
55bc3dc4 15. "$TEST_DIRECTORY"/lib-httpd.sh
119c8eee
JK
16start_httpd
17
18test_expect_success 'setup repository' '
c9704aa7 19 git config push.default matching &&
5a9681f4 20 echo content1 >file &&
119c8eee 21 git add file &&
99094a7a 22 git commit -m one &&
5a9681f4
CB
23 echo content2 >file &&
24 git add file &&
25 git commit -m two
119c8eee
JK
26'
27
afa2c6dd
PS
28test_expect_success 'packfile without repository does not crash' '
29 echo "fatal: not a git repository" >expect &&
30 test_must_fail nongit git http-fetch --packfile=abc 2>err &&
31 test_cmp expect err
32'
33
f6db603c
ÆAB
34setup_post_update_server_info_hook () {
35 test_hook --setup -C "$1" post-update <<-\EOF &&
36 exec git update-server-info
37 EOF
38 git -C "$1" update-server-info
39}
40
5a9681f4 41test_expect_success 'create http-accessible bare repository with loose objects' '
d4a7ffaa 42 cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
f6db603c
ÆAB
43 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" config core.bare true &&
44 setup_post_update_server_info_hook "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
119c8eee 45 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
028cb644 46 git push public main:main
119c8eee
JK
47'
48
49test_expect_success 'clone http repository' '
6cfc0286
TRC
50 git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
51 cp -R clone-tmpl clone &&
119c8eee
JK
52 test_cmp file clone/file
53'
54
4b0c3c77
JN
55test_expect_success 'list refs from outside any repository' '
56 cat >expect <<-EOF &&
028cb644
JS
57 $(git rev-parse main) HEAD
58 $(git rev-parse main) refs/heads/main
4b0c3c77
JN
59 EOF
60 nongit git ls-remote "$HTTPD_URL/dumb/repo.git" >actual &&
61 test_cmp expect actual
62'
63
bd455cec
PS
64
65test_expect_success 'list detached HEAD from outside any repository' '
66 git clone --mirror "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
67 "$HTTPD_DOCUMENT_ROOT_PATH/repo-detached.git" &&
68 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo-detached.git" \
69 update-ref --no-deref HEAD refs/heads/main &&
70 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo-detached.git" update-server-info &&
71 cat >expect <<-EOF &&
72 $(git rev-parse main) HEAD
73 $(git rev-parse main) refs/heads/main
74 EOF
75 nongit git ls-remote "$HTTPD_URL/dumb/repo-detached.git" >actual &&
76 test_cmp expect actual
77'
78
5232586c 79test_expect_success 'create password-protected repository' '
726800a8 80 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
5232586c 81 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
726800a8 82 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
5232586c
JK
83'
84
ac093d07 85test_expect_success 'create empty remote repository' '
86 git init --bare "$HTTPD_DOCUMENT_ROOT_PATH/empty.git" &&
f6db603c 87 setup_post_update_server_info_hook "$HTTPD_DOCUMENT_ROOT_PATH/empty.git"
ac093d07 88'
89
18c9cb75 90test_expect_success 'empty dumb HTTP repository falls back to SHA1' '
ac093d07 91 test_when_finished "rm -fr clone-empty" &&
92 git clone $HTTPD_URL/dumb/empty.git clone-empty &&
93 git -C clone-empty rev-parse --show-object-format >empty-format &&
18c9cb75 94 test "$(cat empty-format)" = sha1
ac093d07 95'
96
e837936c 97setup_askpass_helper
148bb6a7 98
5232586c 99test_expect_success 'cloning password-protected repository can fail' '
e837936c 100 set_askpass wrong &&
726800a8 101 test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
148bb6a7 102 expect_askpass both wrong
5232586c
JK
103'
104
105test_expect_success 'http auth can use user/pass in URL' '
e837936c 106 set_askpass wrong &&
726800a8 107 git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
148bb6a7 108 expect_askpass none
5232586c
JK
109'
110
dfa1725a 111test_expect_success 'http auth can use just user in URL' '
afbf5ca5 112 set_askpass wrong pass@host &&
726800a8 113 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
7725b810 114 expect_askpass pass user%40host
5232586c
JK
115'
116
dfa1725a 117test_expect_success 'http auth can request both user and pass' '
afbf5ca5 118 set_askpass user@host pass@host &&
726800a8 119 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
7725b810 120 expect_askpass both user%40host
3cf8fe1d
GC
121'
122
dfa1725a 123test_expect_success 'http auth respects credential helper config' '
11825072
JK
124 test_config_global credential.helper "!f() {
125 cat >/dev/null
126 echo username=user@host
afbf5ca5 127 echo password=pass@host
11825072 128 }; f" &&
e837936c 129 set_askpass wrong &&
726800a8 130 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
11825072
JK
131 expect_askpass none
132'
133
dfa1725a 134test_expect_success 'http auth can get username from config' '
d5742425 135 test_config_global "credential.$HTTPD_URL.username" user@host &&
afbf5ca5 136 set_askpass wrong pass@host &&
726800a8 137 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
7725b810 138 expect_askpass pass user%40host
d5742425
JK
139'
140
dfa1725a 141test_expect_success 'configured username does not override URL' '
d5742425 142 test_config_global "credential.$HTTPD_URL.username" wrong &&
afbf5ca5 143 set_askpass wrong pass@host &&
726800a8 144 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
7725b810 145 expect_askpass pass user%40host
d5742425
JK
146'
147
455d22c1 148test_expect_success 'set up repo with http submodules' '
14111fc4
JK
149 git init super &&
150 set_askpass user@host pass@host &&
151 (
152 cd super &&
153 git submodule add "$HTTPD_URL/auth/dumb/repo.git" sub &&
154 git commit -m "add submodule"
455d22c1
JK
155 )
156'
157
158test_expect_success 'cmdline credential config passes to submodule via clone' '
14111fc4
JK
159 set_askpass wrong pass@host &&
160 test_must_fail git clone --recursive super super-clone &&
161 rm -rf super-clone &&
455d22c1 162
14111fc4 163 set_askpass wrong pass@host &&
1149ee21 164 git -c "credential.$HTTPD_URL.username=user@host" \
14111fc4 165 clone --recursive super super-clone &&
7725b810 166 expect_askpass pass user%40host
c12e8656
JK
167'
168
169test_expect_success 'cmdline credential config passes submodule via fetch' '
170 set_askpass wrong pass@host &&
171 test_must_fail git -C super-clone fetch --recurse-submodules &&
172
173 set_askpass wrong pass@host &&
174 git -C super-clone \
175 -c "credential.$HTTPD_URL.username=user@host" \
176 fetch --recurse-submodules &&
7725b810 177 expect_askpass pass user%40host
14111fc4
JK
178'
179
860cba61
JK
180test_expect_success 'cmdline credential config passes submodule update' '
181 # advance the submodule HEAD so that a fetch is required
182 git commit --allow-empty -m foo &&
183 git push "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git" HEAD &&
184 sha1=$(git rev-parse HEAD) &&
185 git -C super-clone update-index --cacheinfo 160000,$sha1,sub &&
186
187 set_askpass wrong pass@host &&
188 test_must_fail git -C super-clone submodule update &&
189
190 set_askpass wrong pass@host &&
191 git -C super-clone \
192 -c "credential.$HTTPD_URL.username=user@host" \
193 submodule update &&
7725b810 194 expect_askpass pass user%40host
860cba61
JK
195'
196
119c8eee
JK
197test_expect_success 'fetch changes via http' '
198 echo content >>file &&
199 git commit -a -m two &&
2bcd9ec5 200 git push public &&
119c8eee
JK
201 (cd clone && git pull) &&
202 test_cmp file clone/file
203'
204
6cfc0286
TRC
205test_expect_success 'fetch changes via manual http-fetch' '
206 cp -R clone-tmpl clone2 &&
207
208 HEAD=$(git rev-parse --verify HEAD) &&
209 (cd clone2 &&
028cb644
JS
210 git http-fetch -a -w heads/main-new $HEAD $(git config remote.origin.url) &&
211 git checkout main-new &&
6cfc0286
TRC
212 test $HEAD = $(git rev-parse --verify HEAD)) &&
213 test_cmp file clone2/file
214'
215
2e85a0c8
216test_expect_success 'manual http-fetch without -a works just as well' '
217 cp -R clone-tmpl clone3 &&
218
219 HEAD=$(git rev-parse --verify HEAD) &&
220 (cd clone3 &&
028cb644
JS
221 git http-fetch -w heads/main-new $HEAD $(git config remote.origin.url) &&
222 git checkout main-new &&
2e85a0c8
223 test $HEAD = $(git rev-parse --verify HEAD)) &&
224 test_cmp file clone3/file
225'
226
fbb074c2 227test_expect_success 'http remote detects correct HEAD' '
028cb644 228 git push public main:other &&
fbb074c2
JK
229 (cd clone &&
230 git remote set-head origin -d &&
231 git remote set-head origin -a &&
232 git symbolic-ref refs/remotes/origin/HEAD > output &&
028cb644 233 echo refs/remotes/origin/main > expect &&
fbb074c2
JK
234 test_cmp expect output
235 )
236'
237
96a4f187
TRC
238test_expect_success 'fetch packed objects' '
239 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
d761b2ac 240 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
1327d839 241 git --bare repack -a -d
d761b2ac 242 ) &&
024bb125 243 git clone $HTTPD_URL/dumb/repo_pack.git
96a4f187
TRC
244'
245
8d5d2a34
JT
246test_expect_success 'http-fetch --packfile' '
247 # Arbitrary hash. Use rev-parse so that we get one of the correct
248 # length.
249 ARBITRARY=$(git -C "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git rev-parse HEAD) &&
250
251 git init packfileclient &&
252 p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && ls objects/pack/pack-*.pack) &&
27e35ba6
JT
253 git -C packfileclient http-fetch --packfile=$ARBITRARY \
254 --index-pack-arg=index-pack --index-pack-arg=--stdin \
255 --index-pack-arg=--keep \
256 "$HTTPD_URL"/dumb/repo_pack.git/$p >out &&
8d5d2a34 257
a764c37b 258 grep -E "^keep.[0-9a-f]{16,}$" out &&
8d5d2a34
JT
259 cut -c6- out >packhash &&
260
261 # Ensure that the expected files are generated
262 test -e "packfileclient/.git/objects/pack/pack-$(cat packhash).pack" &&
263 test -e "packfileclient/.git/objects/pack/pack-$(cat packhash).idx" &&
264 test -e "packfileclient/.git/objects/pack/pack-$(cat packhash).keep" &&
265
266 # Ensure that it has the HEAD of repo_pack, at least
267 HASH=$(git -C "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git rev-parse HEAD) &&
268 git -C packfileclient cat-file -e "$HASH"
269'
270
fe72d420
SP
271test_expect_success 'fetch notices corrupt pack' '
272 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
273 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
bacb1c01 274 p=$(ls objects/pack/pack-*.pack) &&
fe72d420
SP
275 chmod u+w $p &&
276 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
277 ) &&
278 mkdir repo_bad1.git &&
279 (cd repo_bad1.git &&
280 git --bare init &&
281 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
bacb1c01 282 test 0 = $(ls objects/pack/pack-*.pack | wc -l)
fe72d420
SP
283 )
284'
285
8d5d2a34
JT
286test_expect_success 'http-fetch --packfile with corrupt pack' '
287 rm -rf packfileclient &&
288 git init packfileclient &&
289 p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git && ls objects/pack/pack-*.pack) &&
290 test_must_fail git -C packfileclient http-fetch --packfile \
291 "$HTTPD_URL"/dumb/repo_bad1.git/$p
292'
293
750ef425
SP
294test_expect_success 'fetch notices corrupt idx' '
295 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
296 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
bacb1c01 297 p=$(ls objects/pack/pack-*.idx) &&
750ef425
SP
298 chmod u+w $p &&
299 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
300 ) &&
301 mkdir repo_bad2.git &&
302 (cd repo_bad2.git &&
303 git --bare init &&
304 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
bacb1c01 305 test 0 = $(ls objects/pack | wc -l)
750ef425
SP
306 )
307'
308
019b21d4
JK
309# usage: count_fetches <nr> <extension> <trace_file>
310count_fetches () {
311 # ignore grep exit code; it may return non-zero if we are expecting no
312 # matches
313 grep "GET .*objects/pack/pack-[a-z0-9]*.$2" "$3" >trace.count
314 test_line_count = "$1" trace.count
315}
316
8b9c2dd4
JK
317test_expect_success 'fetch can handle previously-fetched .idx files' '
318 git checkout --orphan branch1 &&
319 echo base >file &&
320 git add file &&
321 git commit -m base &&
322 git --bare init "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git &&
323 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch1 &&
324 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
325 git checkout -b branch2 branch1 &&
326 echo b2 >>file &&
327 git commit -a -m b2 &&
328 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch2 &&
329 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
330 git --bare init clone_packed_branches.git &&
019b21d4
JK
331 GIT_TRACE_CURL=$PWD/one.trace git --git-dir=clone_packed_branches.git \
332 fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch1:branch1 &&
333 count_fetches 2 idx one.trace &&
334 count_fetches 1 pack one.trace &&
335 GIT_TRACE_CURL=$PWD/two.trace git --git-dir=clone_packed_branches.git \
336 fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch2:branch2 &&
63aca3f7 337 count_fetches 1 idx two.trace &&
019b21d4 338 count_fetches 1 pack two.trace
8b9c2dd4
JK
339'
340
7da4e228 341test_expect_success 'did not use upload-pack service' '
5a828bcf 342 ! grep "/git-upload-pack" "$HTTPD_ROOT_PATH/access.log"
7da4e228
SP
343'
344
dbcf2bd3
JK
345test_expect_success 'git client shows text/plain errors' '
346 test_must_fail git clone "$HTTPD_URL/error/text" 2>stderr &&
347 grep "this is the error message" stderr
348'
349
350test_expect_success 'git client does not show html errors' '
351 test_must_fail git clone "$HTTPD_URL/error/html" 2>stderr &&
352 ! grep "this is the error message" stderr
353'
354
bf197fd7
JK
355test_expect_success 'git client shows text/plain with a charset' '
356 test_must_fail git clone "$HTTPD_URL/error/charset" 2>stderr &&
357 grep "this is the error message" stderr
358'
359
df383b58 360test_expect_success ICONV 'http error messages are reencoded' '
fc1b774c
JK
361 test_must_fail git clone "$HTTPD_URL/error/utf16" 2>stderr &&
362 grep "this is the error message" stderr
363'
364
df383b58 365test_expect_success ICONV 'reencoding is robust to whitespace oddities' '
f34a655d
YE
366 test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr &&
367 grep "this is the error message" stderr
368'
369
f18604bb
YE
370check_language () {
371 case "$2" in
372 '')
373 >expect
374 ;;
375 ?*)
81590bf7 376 echo "=> Send header: Accept-Language: $1" >expect
f18604bb
YE
377 ;;
378 esac &&
81590bf7 379 GIT_TRACE_CURL=true \
f18604bb
YE
380 LANGUAGE=$2 \
381 git ls-remote "$HTTPD_URL/dumb/repo.git" >output 2>&1 &&
382 tr -d '\015' <output |
383 sort -u |
81590bf7 384 sed -ne '/^=> Send header: Accept-Language:/ p' >actual &&
f18604bb
YE
385 test_cmp expect actual
386}
387
388test_expect_success 'git client sends Accept-Language based on LANGUAGE' '
389 check_language "ko-KR, *;q=0.9" ko_KR.UTF-8'
390
391test_expect_success 'git client sends Accept-Language correctly with unordinary LANGUAGE' '
392 check_language "ko-KR, *;q=0.9" "ko_KR:" &&
393 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR::en_US" &&
394 check_language "ko-KR, *;q=0.9" ":::ko_KR" &&
395 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR!!:en_US" &&
396 check_language "ko-KR, ja-JP;q=0.9, *;q=0.8" "ko_KR en_US:ja_JP"'
397
398test_expect_success 'git client sends Accept-Language with many preferred languages' '
399 check_language "ko-KR, en-US;q=0.9, fr-CA;q=0.8, de;q=0.7, sr;q=0.6, \
400ja;q=0.5, zh;q=0.4, sv;q=0.3, pt;q=0.2, *;q=0.1" \
401 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt &&
402 check_language "ko-KR, en-US;q=0.99, fr-CA;q=0.98, de;q=0.97, sr;q=0.96, \
403ja;q=0.95, zh;q=0.94, sv;q=0.93, pt;q=0.92, nb;q=0.91, *;q=0.90" \
404 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt:nb
405'
406
b0c4adcd 407test_expect_success 'git client send an empty Accept-Language' '
81590bf7
EP
408 GIT_TRACE_CURL=true LANGUAGE= git ls-remote "$HTTPD_URL/dumb/repo.git" 2>stderr &&
409 ! grep "^=> Send header: Accept-Language:" stderr
f18604bb
YE
410'
411
d63ed6ef 412test_expect_success 'remote-http complains cleanly about malformed urls' '
c44088ec 413 test_must_fail git remote-http http::/example.com/repo.git 2>stderr &&
6789275d 414 test_grep "url has no scheme" stderr
d63ed6ef
JK
415'
416
e7fab62b
JN
417# NEEDSWORK: Writing commands to git-remote-curl can race against the latter
418# erroring out, producing SIGPIPE. Remove "ok=sigpipe" once transport-helper has
419# learned to handle early remote helper failures more cleanly.
420test_expect_success 'remote-http complains cleanly about empty scheme' '
421 test_must_fail ok=sigpipe git ls-remote \
422 http::${HTTPD_URL#http}/dumb/repo.git 2>stderr &&
6789275d 423 test_grep "url has no scheme" stderr
d63ed6ef
JK
424'
425
50d34137
JK
426test_expect_success 'redirects can be forbidden/allowed' '
427 test_must_fail git -c http.followRedirects=false \
428 clone $HTTPD_URL/dumb-redir/repo.git dumb-redir &&
429 git -c http.followRedirects=true \
430 clone $HTTPD_URL/dumb-redir/repo.git dumb-redir 2>stderr
431'
432
433test_expect_success 'redirects are reported to stderr' '
434 # just look for a snippet of the redirected-to URL
6789275d 435 test_grep /dumb/ stderr
50d34137
JK
436'
437
438test_expect_success 'non-initial redirects can be forbidden' '
439 test_must_fail git -c http.followRedirects=initial \
440 clone $HTTPD_URL/redir-objects/repo.git redir-objects &&
441 git -c http.followRedirects=true \
442 clone $HTTPD_URL/redir-objects/repo.git redir-objects
443'
444
445test_expect_success 'http.followRedirects defaults to "initial"' '
446 test_must_fail git clone $HTTPD_URL/redir-objects/repo.git default
447'
448
cb4d2d35
JK
449# The goal is for a clone of the "evil" repository, which has no objects
450# itself, to cause the client to fetch objects from the "victim" repository.
451test_expect_success 'set up evil alternates scheme' '
452 victim=$HTTPD_DOCUMENT_ROOT_PATH/victim.git &&
453 git init --bare "$victim" &&
454 git -C "$victim" --work-tree=. commit --allow-empty -m secret &&
455 git -C "$victim" repack -ad &&
456 git -C "$victim" update-server-info &&
457 sha1=$(git -C "$victim" rev-parse HEAD) &&
458
459 evil=$HTTPD_DOCUMENT_ROOT_PATH/evil.git &&
ce5369e3
ÆAB
460 git init --template= --bare "$evil" &&
461 mkdir "$evil/info" &&
cb4d2d35 462 # do this by hand to avoid object existence check
028cb644 463 printf "%s\\t%s\\n" $sha1 refs/heads/main >"$evil/info/refs"
cb4d2d35
JK
464'
465
466# Here we'll just redirect via HTTP. In a real-world attack these would be on
467# different servers, but we should reject it either way.
468test_expect_success 'http-alternates is a non-initial redirect' '
469 echo "$HTTPD_URL/dumb/victim.git/objects" \
470 >"$evil/objects/info/http-alternates" &&
471 test_must_fail git -c http.followRedirects=initial \
472 clone $HTTPD_URL/dumb/evil.git evil-initial &&
473 git -c http.followRedirects=true \
474 clone $HTTPD_URL/dumb/evil.git evil-initial
475'
476
477# Curl supports a lot of protocols that we'd prefer not to allow
478# http-alternates to use, but it's hard to test whether curl has
479# accessed, say, the SMTP protocol, because we are not running an SMTP server.
480# But we can check that it does not allow access to file://, which would
481# otherwise allow this clone to complete.
482test_expect_success 'http-alternates cannot point at funny protocols' '
483 echo "file://$victim/objects" >"$evil/objects/info/http-alternates" &&
484 test_must_fail git -c http.followRedirects=true \
485 clone "$HTTPD_URL/dumb/evil.git" evil-file
486'
487
abcbdc03
JK
488test_expect_success 'http-alternates triggers not-from-user protocol check' '
489 echo "$HTTPD_URL/dumb/victim.git/objects" \
490 >"$evil/objects/info/http-alternates" &&
491 test_config_global http.followRedirects true &&
492 test_must_fail git -c protocol.http.allow=user \
493 clone $HTTPD_URL/dumb/evil.git evil-user &&
494 git -c protocol.http.allow=always \
495 clone $HTTPD_URL/dumb/evil.git evil-user
496'
497
8e27391a
JT
498test_expect_success 'can redirect through non-"info/refs?service=git-upload-pack" URL' '
499 git clone "$HTTPD_URL/redir-to/dumb/repo.git"
500'
501
502test_expect_success 'print HTTP error when any intermediate redirect throws error' '
503 test_must_fail git clone "$HTTPD_URL/redir-to/502" 2> stderr &&
6789275d 504 test_grep "unable to access.*/redir-to/502" stderr
8e27391a
JT
505'
506
ccbbd8bf
JK
507test_expect_success 'fetching via http alternates works' '
508 parent=$HTTPD_DOCUMENT_ROOT_PATH/alt-parent.git &&
509 git init --bare "$parent" &&
510 git -C "$parent" --work-tree=. commit --allow-empty -m foo &&
511 git -C "$parent" update-server-info &&
512 commit=$(git -C "$parent" rev-parse HEAD) &&
513
514 child=$HTTPD_DOCUMENT_ROOT_PATH/alt-child.git &&
515 git init --bare "$child" &&
516 echo "../../alt-parent.git/objects" >"$child/objects/info/alternates" &&
517 git -C "$child" update-ref HEAD $commit &&
518 git -C "$child" update-server-info &&
519
520 git -c http.followredirects=true clone "$HTTPD_URL/dumb/alt-child.git"
521'
522
63aca3f7
JK
523test_expect_success 'dumb http can fetch index v1' '
524 server=$HTTPD_DOCUMENT_ROOT_PATH/idx-v1.git &&
525 git init --bare "$server" &&
526 git -C "$server" --work-tree=. commit --allow-empty -m foo &&
527 git -C "$server" -c pack.indexVersion=1 gc &&
528
529 git clone "$HTTPD_URL/dumb/idx-v1.git" &&
530 git -C idx-v1 fsck
531'
532
119c8eee 533test_done