diff options
Diffstat (limited to 't/t5550-http-fetch-dumb.sh')
-rwxr-xr-x | t/t5550-http-fetch-dumb.sh | 78 |
1 files changed, 65 insertions, 13 deletions
diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh index ea2688bde5..6d9142afc3 100755 --- a/t/t5550-http-fetch-dumb.sh +++ b/t/t5550-http-fetch-dumb.sh @@ -1,6 +1,9 @@ #!/bin/sh test_description='test dumb fetching over http via static file' +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + . ./test-lib.sh . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd @@ -26,7 +29,7 @@ test_expect_success 'create http-accessible bare repository with loose objects' hooks/post-update ) && git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - git push public master:master + git push public main:main ' test_expect_success 'clone http repository' ' @@ -37,8 +40,8 @@ test_expect_success 'clone http repository' ' test_expect_success 'list refs from outside any repository' ' cat >expect <<-EOF && - $(git rev-parse master) HEAD - $(git rev-parse master) refs/heads/master + $(git rev-parse main) HEAD + $(git rev-parse main) refs/heads/main EOF nongit git ls-remote "$HTTPD_URL/dumb/repo.git" >actual && test_cmp expect actual @@ -50,6 +53,24 @@ test_expect_success 'create password-protected repository' ' "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git" ' +test_expect_success 'create empty remote repository' ' + git init --bare "$HTTPD_DOCUMENT_ROOT_PATH/empty.git" && + (cd "$HTTPD_DOCUMENT_ROOT_PATH/empty.git" && + mkdir -p hooks && + write_script "hooks/post-update" <<-\EOF && + exec git update-server-info + EOF + hooks/post-update + ) +' + +test_expect_success 'empty dumb HTTP repository has default hash algorithm' ' + test_when_finished "rm -fr clone-empty" && + git clone $HTTPD_URL/dumb/empty.git clone-empty && + git -C clone-empty rev-parse --show-object-format >empty-format && + test "$(cat empty-format)" = "$(test_oid algo)" +' + setup_askpass_helper test_expect_success 'cloning password-protected repository can fail' ' @@ -163,8 +184,8 @@ test_expect_success 'fetch changes via manual http-fetch' ' HEAD=$(git rev-parse --verify HEAD) && (cd clone2 && - git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) && - git checkout master-new && + git http-fetch -a -w heads/main-new $HEAD $(git config remote.origin.url) && + git checkout main-new && test $HEAD = $(git rev-parse --verify HEAD)) && test_cmp file clone2/file ' @@ -174,19 +195,19 @@ test_expect_success 'manual http-fetch without -a works just as well' ' HEAD=$(git rev-parse --verify HEAD) && (cd clone3 && - git http-fetch -w heads/master-new $HEAD $(git config remote.origin.url) && - git checkout master-new && + git http-fetch -w heads/main-new $HEAD $(git config remote.origin.url) && + git checkout main-new && test $HEAD = $(git rev-parse --verify HEAD)) && test_cmp file clone3/file ' test_expect_success 'http remote detects correct HEAD' ' - git push public master:other && + git push public main:other && (cd clone && git remote set-head origin -d && git remote set-head origin -a && git symbolic-ref refs/remotes/origin/HEAD > output && - echo refs/remotes/origin/master > expect && + echo refs/remotes/origin/main > expect && test_cmp expect output ) ' @@ -199,6 +220,31 @@ test_expect_success 'fetch packed objects' ' git clone $HTTPD_URL/dumb/repo_pack.git ' +test_expect_success 'http-fetch --packfile' ' + # Arbitrary hash. Use rev-parse so that we get one of the correct + # length. + ARBITRARY=$(git -C "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git rev-parse HEAD) && + + git init packfileclient && + p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && ls objects/pack/pack-*.pack) && + git -C packfileclient http-fetch --packfile=$ARBITRARY \ + --index-pack-arg=index-pack --index-pack-arg=--stdin \ + --index-pack-arg=--keep \ + "$HTTPD_URL"/dumb/repo_pack.git/$p >out && + + grep "^keep.[0-9a-f]\{16,\}$" out && + cut -c6- out >packhash && + + # Ensure that the expected files are generated + test -e "packfileclient/.git/objects/pack/pack-$(cat packhash).pack" && + test -e "packfileclient/.git/objects/pack/pack-$(cat packhash).idx" && + test -e "packfileclient/.git/objects/pack/pack-$(cat packhash).keep" && + + # Ensure that it has the HEAD of repo_pack, at least + HASH=$(git -C "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git rev-parse HEAD) && + git -C packfileclient cat-file -e "$HASH" +' + test_expect_success 'fetch notices corrupt pack' ' cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git && (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git && @@ -214,6 +260,14 @@ test_expect_success 'fetch notices corrupt pack' ' ) ' +test_expect_success 'http-fetch --packfile with corrupt pack' ' + rm -rf packfileclient && + git init packfileclient && + p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git && ls objects/pack/pack-*.pack) && + test_must_fail git -C packfileclient http-fetch --packfile \ + "$HTTPD_URL"/dumb/repo_bad1.git/$p +' + test_expect_success 'fetch notices corrupt idx' ' cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git && (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git && @@ -248,9 +302,7 @@ test_expect_success 'fetch can handle previously-fetched .idx files' ' ' test_expect_success 'did not use upload-pack service' ' - test_might_fail grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act && - : >exp && - test_cmp exp act + ! grep "/git-upload-pack" "$HTTPD_ROOT_PATH/access.log" ' test_expect_success 'git client shows text/plain errors' ' @@ -370,7 +422,7 @@ test_expect_success 'set up evil alternates scheme' ' evil=$HTTPD_DOCUMENT_ROOT_PATH/evil.git && git init --bare "$evil" && # do this by hand to avoid object existence check - printf "%s\\t%s\\n" $sha1 refs/heads/master >"$evil/info/refs" + printf "%s\\t%s\\n" $sha1 refs/heads/main >"$evil/info/refs" ' # Here we'll just redirect via HTTP. In a real-world attack these would be on |