Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t5550-http-fetch-dumb.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t5550-http-fetch-dumb.sh` 782 lines ยท 27317 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='test dumb fetching over http via static file' 4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 6 7 . ./test-lib.sh 8 9 if test_have_prereq !REFFILES 10 then 11 skip_all='skipping test; dumb HTTP protocol not supported with reftable.' 12 test_done 13 fi 14 15 . "$TEST_DIRECTORY"/lib-httpd.sh 16 start_httpd 17 18 test_expect_success 'setup repository' ' 19 git config push.default matching && 20 echo content1 >file && 21 git add file && 22 git commit -m one && 23 echo content2 >file && 24 git add file && 25 git commit -m two 26 ' 27 28 test_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 34 setup_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 41 test_expect_success 'create http-accessible bare repository with loose objects' ' 42 cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && 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" && 45 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && 46 git push public main:main 47 ' 48 49 test_expect_success 'clone http repository' ' 50 git clone $HTTPD_URL/dumb/repo.git clone-tmpl && 51 cp -R clone-tmpl clone && 52 test_cmp file clone/file 53 ' 54 55 test_expect_success 'list refs from outside any repository' ' 56 cat >expect <<-EOF && 57 $(git rev-parse main) HEAD 58 $(git rev-parse main) refs/heads/main 59 EOF 60 nongit git ls-remote "$HTTPD_URL/dumb/repo.git" >actual && 61 test_cmp expect actual 62 ' 63 64 65 test_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 79 test_expect_success 'create password-protected repository' ' 80 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" && 81 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \ 82 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git" 83 ' 84 85 test_expect_success 'create empty remote repository' ' 86 git init --bare "$HTTPD_DOCUMENT_ROOT_PATH/empty.git" && 87 setup_post_update_server_info_hook "$HTTPD_DOCUMENT_ROOT_PATH/empty.git" 88 ' 89 90 test_expect_success 'empty dumb HTTP repository falls back to SHA1' ' 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 && 94 test "$(cat empty-format)" = sha1 95 ' 96 97 setup_askpass_helper 98 99 test_expect_success 'cloning password-protected repository can fail' ' 100 set_askpass wrong && 101 test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail && 102 expect_askpass both wrong 103 ' 104 105 test_expect_success 'using credentials from netrc to clone successfully' ' 106 test_when_finished clear_netrc && 107 set_askpass wrong && 108 set_netrc 127.0.0.1 user@host pass@host && 109 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-netrc && 110 expect_askpass none 111 ' 112 113 test_expect_success 'netrc unauthorized credentials (prompt after 401)' ' 114 test_when_finished clear_netrc && 115 set_askpass wrong && 116 set_netrc 127.0.0.1 user@host pass@wrong && 117 test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-netrc-401 && 118 expect_askpass both wrong 119 ' 120 121 test_expect_success 'netrc authorized but forbidden credentials (fail on 403)' ' 122 test_when_finished clear_netrc && 123 set_askpass wrong && 124 set_netrc 127.0.0.1 forbidden-user@host pass@host && 125 test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-netrc-403 2>err && 126 expect_askpass none && 127 test_grep "The requested URL returned error: 403" err 128 ' 129 130 test_expect_success 'http auth can use user/pass in URL' ' 131 set_askpass wrong && 132 git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none && 133 expect_askpass none 134 ' 135 136 test_expect_success 'http auth can use just user in URL' ' 137 set_askpass wrong pass@host && 138 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass && 139 expect_askpass pass user%40host 140 ' 141 142 test_expect_success 'http auth can request both user and pass' ' 143 set_askpass user@host pass@host && 144 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both && 145 expect_askpass both user%40host 146 ' 147 148 test_expect_success 'http auth respects credential helper config' ' 149 test_config_global credential.helper "!f() { 150 cat >/dev/null 151 echo username=user@host 152 echo password=pass@host 153 }; f" && 154 set_askpass wrong && 155 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper && 156 expect_askpass none 157 ' 158 159 test_expect_success 'http auth can get username from config' ' 160 test_config_global "credential.$HTTPD_URL.username" user@host && 161 set_askpass wrong pass@host && 162 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user && 163 expect_askpass pass user%40host 164 ' 165 166 test_expect_success 'configured username does not override URL' ' 167 test_config_global "credential.$HTTPD_URL.username" wrong && 168 set_askpass wrong pass@host && 169 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 && 170 expect_askpass pass user%40host 171 ' 172 173 test_expect_success 'set up repo with http submodules' ' 174 git init super && 175 set_askpass user@host pass@host && 176 ( 177 cd super && 178 git submodule add "$HTTPD_URL/auth/dumb/repo.git" sub && 179 git commit -m "add submodule" 180 ) 181 ' 182 183 test_expect_success 'cmdline credential config passes to submodule via clone' ' 184 set_askpass wrong pass@host && 185 test_must_fail git clone --recursive super super-clone && 186 rm -rf super-clone && 187 188 set_askpass wrong pass@host && 189 git -c "credential.$HTTPD_URL.username=user@host" \ 190 clone --recursive super super-clone && 191 expect_askpass pass user%40host 192 ' 193 194 test_expect_success 'cmdline credential config passes submodule via fetch' ' 195 set_askpass wrong pass@host && 196 test_must_fail git -C super-clone fetch --recurse-submodules && 197 198 set_askpass wrong pass@host && 199 git -C super-clone \ 200 -c "credential.$HTTPD_URL.username=user@host" \ 201 fetch --recurse-submodules && 202 expect_askpass pass user%40host 203 ' 204 205 test_expect_success 'cmdline credential config passes submodule update' ' 206 # advance the submodule HEAD so that a fetch is required 207 git commit --allow-empty -m foo && 208 git push "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git" HEAD && 209 sha1=$(git rev-parse HEAD) && 210 git -C super-clone update-index --cacheinfo 160000,$sha1,sub && 211 212 set_askpass wrong pass@host && 213 test_must_fail git -C super-clone submodule update && 214 215 set_askpass wrong pass@host && 216 git -C super-clone \ 217 -c "credential.$HTTPD_URL.username=user@host" \ 218 submodule update && 219 expect_askpass pass user%40host 220 ' 221 222 test_expect_success 'fetch changes via http' ' 223 echo content >>file && 224 git commit -a -m two && 225 git push public && 226 (cd clone && git pull) && 227 test_cmp file clone/file 228 ' 229 230 test_expect_success 'fetch changes via manual http-fetch' ' 231 cp -R clone-tmpl clone2 && 232 233 HEAD=$(git rev-parse --verify HEAD) && 234 (cd clone2 && 235 git http-fetch -a -w heads/main-new $HEAD $(git config remote.origin.url) && 236 git checkout main-new && 237 test $HEAD = $(git rev-parse --verify HEAD)) && 238 test_cmp file clone2/file 239 ' 240 241 test_expect_success 'manual http-fetch without -a works just as well' ' 242 cp -R clone-tmpl clone3 && 243 244 HEAD=$(git rev-parse --verify HEAD) && 245 (cd clone3 && 246 git http-fetch -w heads/main-new $HEAD $(git config remote.origin.url) && 247 git checkout main-new && 248 test $HEAD = $(git rev-parse --verify HEAD)) && 249 test_cmp file clone3/file 250 ' 251 252 test_expect_success 'http remote detects correct HEAD' ' 253 git push public main:other && 254 (cd clone && 255 git remote set-head origin -d && 256 git remote set-head origin -a && 257 git symbolic-ref refs/remotes/origin/HEAD > output && 258 echo refs/remotes/origin/main > expect && 259 test_cmp expect output 260 ) 261 ' 262 263 test_expect_success 'fetch packed objects' ' 264 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && 265 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && 266 git --bare repack -a -d 267 ) && 268 git clone $HTTPD_URL/dumb/repo_pack.git 269 ' 270 271 test_expect_success 'http-fetch --packfile' ' 272 # Arbitrary hash. Use rev-parse so that we get one of the correct 273 # length. 274 ARBITRARY=$(git -C "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git rev-parse HEAD) && 275 276 git init packfileclient && 277 p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && ls objects/pack/pack-*.pack) && 278 git -C packfileclient http-fetch --packfile=$ARBITRARY \ 279 --index-pack-arg=index-pack --index-pack-arg=--stdin \ 280 --index-pack-arg=--keep \ 281 "$HTTPD_URL"/dumb/repo_pack.git/$p >out && 282 283 test_grep -E "^keep.[0-9a-f]{16,}$" out && 284 cut -c6- out >packhash && 285 286 # Ensure that the expected files are generated 287 test -e "packfileclient/.git/objects/pack/pack-$(cat packhash).pack" && 288 test -e "packfileclient/.git/objects/pack/pack-$(cat packhash).idx" && 289 test -e "packfileclient/.git/objects/pack/pack-$(cat packhash).keep" && 290 291 # Ensure that it has the HEAD of repo_pack, at least 292 HASH=$(git -C "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git rev-parse HEAD) && 293 git -C packfileclient cat-file -e "$HASH" 294 ' 295 296 test_expect_success 'http-fetch --packfile accepts an already complete partial' ' 297 git init packfileclient-complete && 298 p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && 299 ls objects/pack/pack-*.pack) && 300 packhash=$(basename "$p" .pack) && 301 packhash=${packhash#pack-} && 302 tmpfile="packfileclient-complete/.git/objects/pack/pack-$packhash.pack.temp" && 303 cp "$HTTPD_DOCUMENT_ROOT_PATH/repo_pack.git/$p" "$tmpfile" && 304 chmod u+w "$tmpfile" && 305 GIT_TRACE_CURL="$TRASH_DIRECTORY/complete.trace" \ 306 git -C packfileclient-complete http-fetch --packfile="$packhash" \ 307 --index-pack-arg=index-pack \ 308 --index-pack-arg=--stdin --index-pack-arg=--keep \ 309 "$HTTPD_URL/dumb/repo_pack.git/$p" >out && 310 test_grep "416 Requested Range Not Satisfiable" complete.trace && 311 test_path_is_missing "$tmpfile" && 312 git -C packfileclient-complete cat-file -e "$HASH" 313 ' 314 315 test_expect_success 'http-fetch --packfile resumes a partial download' ' 316 git init packfileclient-resume && 317 p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && 318 ls objects/pack/pack-*.pack) && 319 tmpfile="packfileclient-resume/.git/objects/pack/pack-$ARBITRARY.pack.temp" && 320 test_copy_bytes 64 <"$HTTPD_DOCUMENT_ROOT_PATH/repo_pack.git/$p" >"$tmpfile" && 321 GIT_TRACE_CURL="$TRASH_DIRECTORY/resume.trace" \ 322 git -C packfileclient-resume http-fetch --packfile="$ARBITRARY" \ 323 --index-pack-arg=index-pack --index-pack-arg=--stdin \ 324 --index-pack-arg=--keep \ 325 "$HTTPD_URL/dumb/repo_pack.git/$p" >out && 326 test_grep "Range: bytes=64-" resume.trace && 327 test_path_is_missing "$tmpfile" && 328 git -C packfileclient-resume cat-file -e "$HASH" 329 ' 330 331 test_expect_success 'http-fetch --packfile permits unlink while indexing' ' 332 git init packfileclient-unlink && 333 p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && 334 ls objects/pack/pack-*.pack) && 335 tmpfile="packfileclient-unlink/.git/objects/pack/pack-$ARBITRARY.pack.temp" && 336 write_script git-unlink-index-pack <<-\EOF && 337 test -f "$GIT_TEST_PACK_TEMP" || exit 1 338 rm "$GIT_TEST_PACK_TEMP" || exit 1 339 exec git index-pack "$@" 340 EOF 341 test_when_finished "rm -f git-unlink-index-pack" && 342 PATH="$TRASH_DIRECTORY:$PATH" \ 343 GIT_TEST_PACK_TEMP="$TRASH_DIRECTORY/$tmpfile" \ 344 git -C packfileclient-unlink http-fetch --packfile="$ARBITRARY" \ 345 --index-pack-arg=unlink-index-pack \ 346 --index-pack-arg=--stdin --index-pack-arg=--keep \ 347 "$HTTPD_URL/dumb/repo_pack.git/$p" >out && 348 test_path_is_missing "$tmpfile" && 349 git -C packfileclient-unlink cat-file -e "$HASH" 350 ' 351 352 test_expect_success PERL,PIPE 'concurrent http-fetch --packfile cannot corrupt an overlapping download' ' 353 git init packfileclient-overlap && 354 blob=$(test-tool genrandom pack-overlap 2m | 355 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git \ 356 hash-object -w --stdin) && 357 packhash=$(printf "%s\n" "$blob" | 358 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git \ 359 pack-objects "$TRASH_DIRECTORY/overlap-pack") && 360 pack="$TRASH_DIRECTORY/overlap-pack-$packhash.pack" && 361 tmpfile="packfileclient-overlap/.git/objects/pack/pack-$packhash.pack.temp" && 362 mkfifo server-ready first-ready && 363 exec 7<>server-ready && 364 exec 8<>first-ready && 365 write_script slow-pack-server "$PERL_PATH" <<-\EOF && 366 use strict; 367 use warnings; 368 use IO::Socket::INET; 369 370 my ($packfile, $server_ready, $first_ready) = @ARGV; 371 my $completed = 0; 372 END { 373 if (!$completed) { 374 signal_ready($server_ready, "failed"); 375 signal_ready($first_ready, "failed"); 376 } 377 } 378 379 $SIG{ALRM} = sub { die "timed out serving concurrent pack requests\n" }; 380 alarm 60; 381 382 open(my $in, "<:raw", $packfile) or die "open $packfile: $!"; 383 my $pack = do { local $/; <$in> }; 384 close($in) or die "close $packfile: $!"; 385 my $server = IO::Socket::INET->new(LocalAddr => "127.0.0.1", 386 LocalPort => 0, Proto => "tcp", Listen => 2, ReuseAddr => 1) 387 or die "listen: $!"; 388 389 sub signal_ready { 390 my ($file, $value) = @_; 391 open(my $out, ">", $file) or die "open $file: $!"; 392 print $out "$value\n" or die "write $file: $!"; 393 close($out) or die "close $file: $!"; 394 } 395 396 sub write_all { 397 my ($out, $data) = @_; 398 my $offset = 0; 399 while ($offset < length($data)) { 400 my $written = syswrite($out, $data, 401 length($data) - $offset, $offset); 402 defined($written) && $written or die "write response: $!"; 403 $offset += $written; 404 } 405 } 406 407 sub start_response { 408 my $out = $server->accept() or die "accept: $!"; 409 <$out> or die "read request: $!"; 410 my $start = 0; 411 while (<$out>) { 412 last if /^\r?\n$/; 413 $start = $1 if /^Range: bytes=(\d+)-/i; 414 } 415 $start < length($pack) or die "invalid range $start"; 416 my $length = length($pack) - $start; 417 my $middle = int($length / 2); 418 my $status = $start ? "206 Partial Content" : "200 OK"; 419 my $headers = "HTTP/1.1 $status\r\n" . 420 "Content-Length: $length\r\n" . 421 ($start ? "Content-Range: bytes $start-" . 422 (length($pack) - 1) . "/" . length($pack) . "\r\n" : "") . 423 "Connection: close\r\n\r\n"; 424 write_all($out, $headers); 425 write_all($out, substr($pack, $start, $middle)); 426 return ($out, $start + $middle); 427 } 428 429 signal_ready($server_ready, $server->sockport()); 430 my ($first, $first_pos) = start_response(); 431 signal_ready($first_ready, "ready"); 432 my ($second, $second_pos) = start_response(); 433 write_all($first, substr($pack, $first_pos)); 434 write_all($second, substr($pack, $second_pos)); 435 close($first) or die "close first response: $!"; 436 close($second) or die "close second response: $!"; 437 $completed = 1; 438 alarm 0; 439 EOF 440 { 441 "$TRASH_DIRECTORY/slow-pack-server" "$pack" \ 442 "$TRASH_DIRECTORY/server-ready" \ 443 "$TRASH_DIRECTORY/first-ready" >server.log 2>&1 & 444 server_pid=$! 445 } && 446 test_when_finished " 447 kill $server_pid 2>/dev/null || : 448 wait $server_pid 2>/dev/null || : 449 exec 7>&- 450 exec 8>&- 451 rm -f server-ready first-ready slow-pack-server 452 " && 453 read port <&7 && 454 url="http://127.0.0.1:$port/pack" && 455 { 456 ( 457 if ! GIT_TRACE_CURL="$TRASH_DIRECTORY/overlap-first.trace" \ 458 GIT_TRACE_CURL_NO_DATA=1 \ 459 git -C packfileclient-overlap http-fetch --packfile="$packhash" \ 460 --index-pack-arg=index-pack \ 461 --index-pack-arg=--stdin --index-pack-arg=--keep \ 462 "$url" >first.out 463 then 464 echo failed >"$TRASH_DIRECTORY/first-ready" && 465 exit 1 466 fi 467 ) & 468 first_pid=$! 469 } && 470 test_when_finished " 471 kill $first_pid 2>/dev/null || : 472 wait $first_pid 2>/dev/null || : 473 " && 474 read ready <&8 && 475 test "$ready" = ready && 476 test_path_is_file "$tmpfile" && 477 { 478 GIT_TRACE_CURL="$TRASH_DIRECTORY/overlap-second.trace" \ 479 GIT_TRACE_CURL_NO_DATA=1 \ 480 git -C packfileclient-overlap http-fetch --packfile="$packhash" \ 481 --index-pack-arg=index-pack \ 482 --index-pack-arg=--stdin --index-pack-arg=--keep \ 483 "$url" >second.out & 484 second_pid=$! 485 } && 486 test_when_finished " 487 kill $second_pid 2>/dev/null || : 488 wait $second_pid 2>/dev/null || : 489 " && 490 wait "$second_pid" && 491 wait "$first_pid" && 492 wait "$server_pid" && 493 printf "keep\t%s\npack\t%s\n" "$packhash" "$packhash" | sort >expect && 494 sort first.out second.out >actual && 495 test_cmp expect actual && 496 test_path_is_missing "$tmpfile" && 497 git -C packfileclient-overlap cat-file -e "$blob" 498 ' 499 500 test_expect_success 'fetch notices corrupt pack' ' 501 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git && 502 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git && 503 p=$(ls objects/pack/pack-*.pack) && 504 chmod u+w $p && 505 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc 506 ) && 507 mkdir repo_bad1.git && 508 (cd repo_bad1.git && 509 git --bare init && 510 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git && 511 test 0 = $(ls objects/pack/pack-*.pack | wc -l) 512 ) 513 ' 514 515 test_expect_success 'http-fetch --packfile with corrupt pack' ' 516 rm -rf packfileclient && 517 git init packfileclient && 518 p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git && ls objects/pack/pack-*.pack) && 519 test_must_fail git -C packfileclient http-fetch --packfile \ 520 "$HTTPD_URL"/dumb/repo_bad1.git/$p 521 ' 522 523 test_expect_success 'fetch notices corrupt idx' ' 524 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git && 525 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git && 526 p=$(ls objects/pack/pack-*.idx) && 527 chmod u+w $p && 528 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc 529 ) && 530 mkdir repo_bad2.git && 531 (cd repo_bad2.git && 532 git --bare init && 533 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git && 534 test 0 = $(ls objects/pack | wc -l) 535 ) 536 ' 537 538 # usage: count_fetches 539 count_fetches () { 540 # ignore grep exit code; it may return non-zero if we are expecting no 541 # matches 542 grep "GET .*objects/pack/pack-[a-z0-9]*.$2" "$3" >trace.count 543 test_line_count = "$1" trace.count 544 } 545 546 test_expect_success 'fetch can handle previously-fetched .idx files' ' 547 git checkout --orphan branch1 && 548 echo base >file && 549 git add file && 550 git commit -m base && 551 git --bare init "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git && 552 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch1 && 553 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d && 554 git checkout -b branch2 branch1 && 555 echo b2 >>file && 556 git commit -a -m b2 && 557 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch2 && 558 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d && 559 git --bare init clone_packed_branches.git && 560 GIT_TRACE_CURL=$PWD/one.trace git --git-dir=clone_packed_branches.git \ 561 fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch1:branch1 && 562 count_fetches 2 idx one.trace && 563 count_fetches 1 pack one.trace && 564 GIT_TRACE_CURL=$PWD/two.trace git --git-dir=clone_packed_branches.git \ 565 fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch2:branch2 && 566 count_fetches 1 idx two.trace && 567 count_fetches 1 pack two.trace 568 ' 569 570 test_expect_success 'did not use upload-pack service' ' 571 test_grep ! "/git-upload-pack" "$HTTPD_ROOT_PATH/access.log" 572 ' 573 574 test_expect_success ICONV 'git client shows text/plain errors' ' 575 test_must_fail git clone "$HTTPD_URL/error/text" 2>stderr && 576 test_grep "this is the error message" stderr 577 ' 578 579 test_expect_success ICONV 'git client does not show html errors' ' 580 test_must_fail git clone "$HTTPD_URL/error/html" 2>stderr && 581 test_grep ! "this is the error message" stderr 582 ' 583 584 test_expect_success ICONV 'git client shows text/plain with a charset' ' 585 test_must_fail git clone "$HTTPD_URL/error/charset" 2>stderr && 586 test_grep "this is the error message" stderr 587 ' 588 589 test_expect_success ICONV 'http error messages are reencoded' ' 590 test_must_fail git clone "$HTTPD_URL/error/utf16" 2>stderr && 591 test_grep "this is the error message" stderr 592 ' 593 594 test_expect_success ICONV 'reencoding is robust to whitespace oddities' ' 595 test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr && 596 test_grep "this is the error message" stderr 597 ' 598 599 check_language () { 600 case "$2" in 601 '') 602 >expect 603 ;; 604 ?*) 605 echo "=> Send header: Accept-Language: $1" >expect 606 ;; 607 esac && 608 GIT_TRACE_CURL=true \ 609 LANGUAGE=$2 \ 610 git ls-remote "$HTTPD_URL/dumb/repo.git" >output 2>&1 && 611 tr -d '\015' Send header: Accept-Language:/ p' >actual && 614 test_cmp expect actual 615 } 616 617 test_expect_success 'git client sends Accept-Language based on LANGUAGE' ' 618 check_language "ko-KR, *;q=0.9" ko_KR.UTF-8' 619 620 test_expect_success 'git client sends Accept-Language correctly with unordinary LANGUAGE' ' 621 check_language "ko-KR, *;q=0.9" "ko_KR:" && 622 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR::en_US" && 623 check_language "ko-KR, *;q=0.9" ":::ko_KR" && 624 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR!!:en_US" && 625 check_language "ko-KR, ja-JP;q=0.9, *;q=0.8" "ko_KR en_US:ja_JP"' 626 627 test_expect_success 'git client sends Accept-Language with many preferred languages' ' 628 check_language "ko-KR, en-US;q=0.9, fr-CA;q=0.8, de;q=0.7, sr;q=0.6, \ 629 ja;q=0.5, zh;q=0.4, sv;q=0.3, pt;q=0.2, *;q=0.1" \ 630 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt && 631 check_language "ko-KR, en-US;q=0.99, fr-CA;q=0.98, de;q=0.97, sr;q=0.96, \ 632 ja;q=0.95, zh;q=0.94, sv;q=0.93, pt;q=0.92, nb;q=0.91, *;q=0.90" \ 633 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt:nb 634 ' 635 636 test_expect_success 'git client send an empty Accept-Language' ' 637 GIT_TRACE_CURL=true LANGUAGE= git ls-remote "$HTTPD_URL/dumb/repo.git" 2>stderr && 638 test_grep ! "^=> Send header: Accept-Language:" stderr 639 ' 640 641 test_expect_success 'remote-http complains cleanly about malformed urls' ' 642 test_must_fail git remote-http http::/example.com/repo.git 2>stderr && 643 test_grep "url has no scheme" stderr 644 ' 645 646 # NEEDSWORK: Writing commands to git-remote-curl can race against the latter 647 # erroring out, producing SIGPIPE. Remove "ok=sigpipe" once transport-helper has 648 # learned to handle early remote helper failures more cleanly. 649 test_expect_success 'remote-http complains cleanly about empty scheme' ' 650 test_must_fail ok=sigpipe git ls-remote \ 651 http::${HTTPD_URL#http}/dumb/repo.git 2>stderr && 652 test_grep "url has no scheme" stderr 653 ' 654 655 test_expect_success 'redirects can be forbidden/allowed' ' 656 test_must_fail git -c http.followRedirects=false \ 657 clone $HTTPD_URL/dumb-redir/repo.git dumb-redir && 658 git -c http.followRedirects=true \ 659 clone $HTTPD_URL/dumb-redir/repo.git dumb-redir 2>stderr 660 ' 661 662 test_expect_success 'redirects are reported to stderr' ' 663 # just look for a snippet of the redirected-to URL 664 test_grep /dumb/ stderr 665 ' 666 667 test_expect_success 'non-initial redirects can be forbidden' ' 668 test_must_fail git -c http.followRedirects=initial \ 669 clone $HTTPD_URL/redir-objects/repo.git redir-objects && 670 git -c http.followRedirects=true \ 671 clone $HTTPD_URL/redir-objects/repo.git redir-objects 672 ' 673 674 test_expect_success 'http.followRedirects defaults to "initial"' ' 675 test_must_fail git clone $HTTPD_URL/redir-objects/repo.git default 676 ' 677 678 # The goal is for a clone of the "evil" repository, which has no objects 679 # itself, to cause the client to fetch objects from the "victim" repository. 680 test_expect_success 'set up evil alternates scheme' ' 681 victim=$HTTPD_DOCUMENT_ROOT_PATH/victim.git && 682 git init --bare "$victim" && 683 git -C "$victim" --work-tree=. commit --allow-empty -m secret && 684 git -C "$victim" repack -ad && 685 git -C "$victim" update-server-info && 686 sha1=$(git -C "$victim" rev-parse HEAD) && 687 688 evil=$HTTPD_DOCUMENT_ROOT_PATH/evil.git && 689 git init --template= --bare "$evil" && 690 mkdir "$evil/info" && 691 # do this by hand to avoid object existence check 692 printf "%s\\t%s\\n" $sha1 refs/heads/main >"$evil/info/refs" 693 ' 694 695 # Here we'll just redirect via HTTP. In a real-world attack these would be on 696 # different servers, but we should reject it either way. 697 test_expect_success 'http-alternates is a non-initial redirect' ' 698 echo "$HTTPD_URL/dumb/victim.git/objects" \ 699 >"$evil/objects/info/http-alternates" && 700 test_must_fail git -c http.followRedirects=initial \ 701 clone $HTTPD_URL/dumb/evil.git evil-initial && 702 git -c http.followRedirects=true \ 703 clone $HTTPD_URL/dumb/evil.git evil-initial 704 ' 705 706 # Curl supports a lot of protocols that we'd prefer not to allow 707 # http-alternates to use, but it's hard to test whether curl has 708 # accessed, say, the SMTP protocol, because we are not running an SMTP server. 709 # But we can check that it does not allow access to file://, which would 710 # otherwise allow this clone to complete. 711 test_expect_success 'http-alternates cannot point at funny protocols' ' 712 echo "file://$victim/objects" >"$evil/objects/info/http-alternates" && 713 test_must_fail git -c http.followRedirects=true \ 714 clone "$HTTPD_URL/dumb/evil.git" evil-file 715 ' 716 717 test_expect_success 'http-alternates triggers not-from-user protocol check' ' 718 echo "$HTTPD_URL/dumb/victim.git/objects" \ 719 >"$evil/objects/info/http-alternates" && 720 test_config_global http.followRedirects true && 721 test_must_fail git -c protocol.http.allow=user \ 722 clone $HTTPD_URL/dumb/evil.git evil-user && 723 git -c protocol.http.allow=always \ 724 clone $HTTPD_URL/dumb/evil.git evil-user 725 ' 726 727 test_expect_success 'can redirect through non-"info/refs?service=git-upload-pack" URL' ' 728 git clone "$HTTPD_URL/redir-to/dumb/repo.git" 729 ' 730 731 test_expect_success 'print HTTP error when any intermediate redirect throws error' ' 732 test_must_fail git clone "$HTTPD_URL/redir-to/502" 2> stderr && 733 test_grep "unable to access.*/redir-to/502" stderr 734 ' 735 736 test_expect_success 'fetching via http alternates works' ' 737 parent=$HTTPD_DOCUMENT_ROOT_PATH/alt-parent.git && 738 git init --bare "$parent" && 739 git -C "$parent" --work-tree=. commit --allow-empty -m foo && 740 git -C "$parent" update-server-info && 741 commit=$(git -C "$parent" rev-parse HEAD) && 742 743 child=$HTTPD_DOCUMENT_ROOT_PATH/alt-child.git && 744 git init --bare "$child" && 745 echo "../../alt-parent.git/objects" >"$child/objects/info/alternates" && 746 git -C "$child" update-ref HEAD $commit && 747 git -C "$child" update-server-info && 748 749 git -c http.followredirects=true clone "$HTTPD_URL/dumb/alt-child.git" 750 ' 751 752 test_expect_success 'dumb http can fetch index v1' ' 753 server=$HTTPD_DOCUMENT_ROOT_PATH/idx-v1.git && 754 git init --bare "$server" && 755 git -C "$server" --work-tree=. commit --allow-empty -m foo && 756 git -C "$server" -c pack.indexVersion=1 gc && 757 758 git clone "$HTTPD_URL/dumb/idx-v1.git" && 759 git -C idx-v1 fsck 760 ' 761 762 test_expect_success 'absolute-path alternate when url has no path' ' 763 src=$HTTPD_DOCUMENT_ROOT_PATH/repo.git && 764 alt=absolute-alt.git && 765 git clone --bare --shared "$src" "$alt" && 766 767 # Our repo has an alternate pointing to the absolute filesystem path, 768 # but that will not make any sense to an http client. So we will 769 # manually give it the equivalent path that the http server will 770 # understand. 771 echo "/dumb/repo.git/objects" >"$alt/objects/info/http-alternates" && 772 773 # Now make our alt repository available at the root of the http 774 # server without any path (i.e., just http://localhost:1234). 775 git -C "$alt" update-server-info && 776 mv absolute-alt.git/* "$HTTPD_DOCUMENT_ROOT_PATH" && 777 778 git -c http.followRedirects=true clone "$HTTPD_URL" alt-clone.git 2>err && 779 test_grep "adding alternate object store: $HTTPD_URL/dumb/repo.git" err 780 ' 781 782 test_done