]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t5702-protocol-v2.sh
Merge branch 'jk/fast-export-anonym-alt'
[thirdparty/git.git] / t / t5702-protocol-v2.sh
index 5b33f625dddeccce7ecd68b45f115a46f7fbe93a..1b54c35b01792f85e791f6d4614f25d543c47dfd 100755 (executable)
@@ -13,6 +13,7 @@ start_git_daemon --export-all --enable=receive-pack
 daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent
 
 test_expect_success 'create repo to be served by git-daemon' '
+       test_oid_init &&
        git init "$daemon_parent" &&
        test_commit -C "$daemon_parent" one
 '
@@ -32,7 +33,7 @@ test_expect_success 'list refs with git:// using protocol v2' '
        test_cmp expect actual
 '
 
-test_expect_success 'ref advertisment is filtered with ls-remote using protocol v2' '
+test_expect_success 'ref advertisement is filtered with ls-remote using protocol v2' '
        test_when_finished "rm -f log" &&
 
        GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
@@ -154,7 +155,7 @@ test_expect_success 'list refs with file:// using protocol v2' '
        test_cmp expect actual
 '
 
-test_expect_success 'ref advertisment is filtered with ls-remote using protocol v2' '
+test_expect_success 'ref advertisement is filtered with ls-remote using protocol v2' '
        test_when_finished "rm -f log" &&
 
        GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
@@ -225,7 +226,7 @@ test_expect_success 'fetch with file:// using protocol v2' '
        grep "fetch< version 2" log
 '
 
-test_expect_success 'ref advertisment is filtered during fetch using protocol v2' '
+test_expect_success 'ref advertisement is filtered during fetch using protocol v2' '
        test_when_finished "rm -f log" &&
 
        test_commit -C file_parent three &&
@@ -348,7 +349,6 @@ test_expect_success 'partial fetch' '
        rm -rf client "$(pwd)/trace" &&
        git init client &&
        SERVER="file://$(pwd)/server" &&
-       test_config -C client extensions.partialClone "$SERVER" &&
 
        GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
                fetch --filter=blob:none "$SERVER" master:refs/heads/other &&
@@ -394,6 +394,7 @@ test_expect_success 'even with handcrafted request, filter does not work if not
        # Custom request that tries to filter even though it is not advertised.
        test-tool pkt-line pack >in <<-EOF &&
        command=fetch
+       object-format=$(test_oid algo)
        0001
        want $(git -C server rev-parse master)
        filter blob:none
@@ -499,10 +500,7 @@ test_expect_success 'upload-pack respects client shallows' '
 
        # Add extra commits to the client so that the whole fetch takes more
        # than 1 request (due to negotiation)
-       for i in $(test_seq 1 32)
-       do
-               test_commit -C client c$i
-       done &&
+       test_commit_bulk -C client --id=c 32 &&
 
        git -C server checkout -b newbranch base &&
        test_commit -C server client_wants &&
@@ -589,6 +587,53 @@ test_expect_success 'clone with http:// using protocol v2' '
        ! grep "Send header: Transfer-Encoding: chunked" log
 '
 
+test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline length' '
+       test_when_finished "rm -f log" &&
+
+       git init "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_length" &&
+       test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_length" file &&
+
+       test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
+               clone "$HTTPD_URL/smart/incomplete_length" incomplete_length_child 2>err &&
+
+       # Client requested to use protocol v2
+       grep "Git-Protocol: version=2" log &&
+       # Server responded using protocol v2
+       grep "git< version 2" log &&
+       # Client reported appropriate failure
+       test_i18ngrep "bytes of length header were received" err
+'
+
+test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline body' '
+       test_when_finished "rm -f log" &&
+
+       git init "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_body" &&
+       test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_body" file &&
+
+       test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
+               clone "$HTTPD_URL/smart/incomplete_body" incomplete_body_child 2>err &&
+
+       # Client requested to use protocol v2
+       grep "Git-Protocol: version=2" log &&
+       # Server responded using protocol v2
+       grep "git< version 2" log &&
+       # Client reported appropriate failure
+       test_i18ngrep "bytes of body are still expected" err
+'
+
+test_expect_success 'clone with http:// using protocol v2 and invalid parameters' '
+       test_when_finished "rm -f log" &&
+
+       test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" \
+               git -c protocol.version=2 \
+               clone --shallow-since=20151012 "$HTTPD_URL/smart/http_parent" http_child_invalid &&
+
+       # Client requested to use protocol v2
+       grep "Git-Protocol: version=2" log &&
+       # Server responded using protocol v2
+       grep "git< version 2" log
+'
+
 test_expect_success 'clone big repository with http:// using protocol v2' '
        test_when_finished "rm -f log" &&
 
@@ -634,6 +679,19 @@ test_expect_success 'fetch with http:// using protocol v2' '
        grep "git< version 2" log
 '
 
+test_expect_success 'fetch with http:// by hash without tag following with protocol v2 does not list refs' '
+       test_when_finished "rm -f log" &&
+
+       test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two_a &&
+       git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" rev-parse two_a >two_a_hash &&
+
+       GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
+               fetch --no-tags origin $(cat two_a_hash) &&
+
+       grep "fetch< version 2" log &&
+       ! grep "fetch> command=ls-refs" log
+'
+
 test_expect_success 'fetch from namespaced repo respects namespaces' '
        test_when_finished "rm -f log" &&
 
@@ -655,6 +713,18 @@ test_expect_success 'fetch from namespaced repo respects namespaces' '
        test_cmp expect actual
 '
 
+test_expect_success 'ls-remote with v2 http sends only one POST' '
+       test_when_finished "rm -f log" &&
+
+       git ls-remote "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" >expect &&
+       GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
+               ls-remote "$HTTPD_URL/smart/http_parent" >actual &&
+       test_cmp expect actual &&
+
+       grep "Send header: POST" log >posts &&
+       test_line_count = 1 posts
+'
+
 test_expect_success 'push with http:// and a config of v2 does not request v2' '
        test_when_finished "rm -f log" &&
        # Till v2 for push is designed, make sure that if a client has
@@ -672,9 +742,9 @@ test_expect_success 'push with http:// and a config of v2 does not request v2' '
        git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s client_branch >expect &&
        test_cmp expect actual &&
 
-       # Client didnt request to use protocol v2
+       # Client did not request to use protocol v2
        ! grep "Git-Protocol: version=2" log &&
-       # Server didnt respond using protocol v2
+       # Server did not respond using protocol v2
        ! grep "git< version 2" log
 '
 
@@ -690,11 +760,11 @@ test_expect_success 'when server sends "ready", expect DELIM' '
 
        # After "ready" in the acknowledgments section, pretend that a FLUSH
        # (0000) was sent instead of a DELIM (0001).
-       printf "/ready/,$ s/0001/0000/" \
-               >"$HTTPD_ROOT_PATH/one-time-sed" &&
+       printf "\$ready = 1 if /ready/; \$ready && s/0001/0000/" \
+               >"$HTTPD_ROOT_PATH/one-time-perl" &&
 
        test_must_fail git -C http_child -c protocol.version=2 \
-               fetch "$HTTPD_URL/one_time_sed/http_parent" 2> err &&
+               fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
        test_i18ngrep "expected packfile to be sent after .ready." err
 '
 
@@ -711,22 +781,110 @@ test_expect_success 'when server does not send "ready", expect FLUSH' '
        # Create many commits to extend the negotiation phase across multiple
        # requests, so that the server does not send "ready" in the first
        # request.
-       for i in $(test_seq 1 32)
-       do
-               test_commit -C http_child c$i
-       done &&
+       test_commit_bulk -C http_child --id=c 32 &&
 
        # After the acknowledgments section, pretend that a DELIM
        # (0001) was sent instead of a FLUSH (0000).
-       printf "/acknowledgments/,$ s/0000/0001/" \
-               >"$HTTPD_ROOT_PATH/one-time-sed" &&
+       printf "\$ack = 1 if /acknowledgments/; \$ack && s/0000/0001/" \
+               >"$HTTPD_ROOT_PATH/one-time-perl" &&
 
        test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" git -C http_child \
                -c protocol.version=2 \
-               fetch "$HTTPD_URL/one_time_sed/http_parent" 2> err &&
+               fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
        grep "fetch< .*acknowledgments" log &&
        ! grep "fetch< .*ready" log &&
        test_i18ngrep "expected no other sections to be sent after no .ready." err
 '
 
+configure_exclusion () {
+       git -C "$1" hash-object "$2" >objh &&
+       git -C "$1" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh &&
+       git -C "$1" config --add \
+               "uploadpack.blobpackfileuri" \
+               "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" &&
+       cat objh
+}
+
+test_expect_success 'part of packfile response provided as URI' '
+       P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+       rm -rf "$P" http_child log &&
+
+       git init "$P" &&
+       git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+       echo my-blob >"$P/my-blob" &&
+       git -C "$P" add my-blob &&
+       echo other-blob >"$P/other-blob" &&
+       git -C "$P" add other-blob &&
+       git -C "$P" commit -m x &&
+
+       configure_exclusion "$P" my-blob >h &&
+       configure_exclusion "$P" other-blob >h2 &&
+
+       GIT_TRACE=1 GIT_TRACE_PACKET="$(pwd)/log" GIT_TEST_SIDEBAND_ALL=1 \
+       git -c protocol.version=2 \
+               -c fetch.uriprotocols=http,https \
+               clone "$HTTPD_URL/smart/http_parent" http_child &&
+
+       # Ensure that my-blob and other-blob are in separate packfiles.
+       for idx in http_child/.git/objects/pack/*.idx
+       do
+               git verify-pack --verbose $idx >out &&
+               {
+                       grep "^[0-9a-f]\{16,\} " out || :
+               } >out.objectlist &&
+               if test_line_count = 1 out.objectlist
+               then
+                       if grep $(cat h) out
+                       then
+                               >hfound
+                       fi &&
+                       if grep $(cat h2) out
+                       then
+                               >h2found
+                       fi
+               fi
+       done &&
+       test -f hfound &&
+       test -f h2found &&
+
+       # Ensure that there are exactly 6 files (3 .pack and 3 .idx).
+       ls http_child/.git/objects/pack/* >filelist &&
+       test_line_count = 6 filelist
+'
+
+test_expect_success 'fetching with valid packfile URI but invalid hash fails' '
+       P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+       rm -rf "$P" http_child log &&
+
+       git init "$P" &&
+       git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+       echo my-blob >"$P/my-blob" &&
+       git -C "$P" add my-blob &&
+       echo other-blob >"$P/other-blob" &&
+       git -C "$P" add other-blob &&
+       git -C "$P" commit -m x &&
+
+       configure_exclusion "$P" my-blob >h &&
+       # Configure a URL for other-blob. Just reuse the hash of the object as
+       # the hash of the packfile, since the hash does not matter for this
+       # test as long as it is not the hash of the pack, and it is of the
+       # expected length.
+       git -C "$P" hash-object other-blob >objh &&
+       git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh &&
+       git -C "$P" config --add \
+               "uploadpack.blobpackfileuri" \
+               "$(cat objh) $(cat objh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" &&
+
+       test_must_fail env GIT_TEST_SIDEBAND_ALL=1 \
+               git -c protocol.version=2 \
+               -c fetch.uriprotocols=http,https \
+               clone "$HTTPD_URL/smart/http_parent" http_child 2>err &&
+       test_i18ngrep "pack downloaded from.*does not match expected hash" err
+'
+
+# DO NOT add non-httpd-specific tests here, because the last part of this
+# test script is only executed when httpd is available and enabled.
+
 test_done