3 test_description
='test protocol v2 server commands'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'test capability advertisement' '
12 test_oid_cache <<-EOF &&
13 wrong_algo sha1:sha256
14 wrong_algo sha256:sha1
16 cat >expect.base <<-EOF &&
18 agent=git/$(git version | cut -d" " -f3)
20 fetch=shallow wait-for-done
22 object-format=$(test_oid algo)
24 cat >expect.trailer <<-EOF &&
27 cat expect.base expect.trailer >expect &&
29 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
30 --advertise-capabilities >out &&
31 test-tool pkt-line unpack <out >actual &&
32 test_cmp expect actual
35 test_expect_success
'stateless-rpc flag does not list capabilities' '
37 test-tool pkt-line pack >in <<-EOF &&
40 test-tool serve-v2 --stateless-rpc >out <in &&
41 test_must_be_empty out &&
44 test-tool serve-v2 --stateless-rpc >out &&
45 test_must_be_empty out
48 test_expect_success
'request invalid capability' '
49 test-tool pkt-line pack >in <<-EOF &&
53 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
54 test_grep "unknown capability" err
57 test_expect_success
'request with no command' '
58 test-tool pkt-line pack >in <<-EOF &&
60 object-format=$(test_oid algo)
63 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
64 test_grep "no command requested" err
67 test_expect_success
'request invalid command' '
68 test-tool pkt-line pack >in <<-EOF &&
70 object-format=$(test_oid algo)
74 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
75 test_grep "invalid command" err
78 test_expect_success
'request capability as command' '
79 test-tool pkt-line pack >in <<-EOF &&
81 object-format=$(test_oid algo)
84 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
85 grep invalid.command.*agent err
88 test_expect_success
'request command as capability' '
89 test-tool pkt-line pack >in <<-EOF &&
91 object-format=$(test_oid algo)
95 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
96 grep unknown.capability err
99 test_expect_success
'requested command is command=value' '
100 test-tool pkt-line pack >in <<-EOF &&
101 command=ls-refs=whatever
102 object-format=$(test_oid algo)
105 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
106 grep invalid.command.*ls-refs=whatever err
109 test_expect_success
'wrong object-format' '
110 test-tool pkt-line pack >in <<-EOF &&
113 object-format=$(test_oid wrong_algo)
116 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
117 test_grep "mismatched object format" err
120 # Test the basics of ls-refs
122 test_expect_success
'setup some refs and tags' '
124 git branch dev main &&
126 git symbolic-ref refs/heads/release refs/heads/main &&
127 git tag -a -m "annotated tag" annotated-tag
130 test_expect_success
'basics of ls-refs' '
131 test-tool pkt-line pack >in <<-EOF &&
133 object-format=$(test_oid algo)
137 cat >expect <<-EOF &&
138 $(git rev-parse HEAD) HEAD
139 $(git rev-parse refs/heads/dev) refs/heads/dev
140 $(git rev-parse refs/heads/main) refs/heads/main
141 $(git rev-parse refs/heads/release) refs/heads/release
142 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
143 $(git rev-parse refs/tags/one) refs/tags/one
144 $(git rev-parse refs/tags/two) refs/tags/two
148 test-tool serve-v2 --stateless-rpc <in >out &&
149 test-tool pkt-line unpack <out >actual &&
150 test_cmp expect actual
153 test_expect_success
'ls-refs complains about unknown options' '
154 test-tool pkt-line pack >in <<-EOF &&
156 object-format=$(test_oid algo)
162 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
163 grep unexpected.line.*no-such-arg err
166 test_expect_success
'basic ref-prefixes' '
167 test-tool pkt-line pack >in <<-EOF &&
169 object-format=$(test_oid algo)
171 ref-prefix refs/heads/main
172 ref-prefix refs/tags/one
176 cat >expect <<-EOF &&
177 $(git rev-parse refs/heads/main) refs/heads/main
178 $(git rev-parse refs/tags/one) refs/tags/one
182 test-tool serve-v2 --stateless-rpc <in >out &&
183 test-tool pkt-line unpack <out >actual &&
184 test_cmp expect actual
187 test_expect_success
'refs/heads prefix' '
188 test-tool pkt-line pack >in <<-EOF &&
190 object-format=$(test_oid algo)
192 ref-prefix refs/heads/
196 cat >expect <<-EOF &&
197 $(git rev-parse refs/heads/dev) refs/heads/dev
198 $(git rev-parse refs/heads/main) refs/heads/main
199 $(git rev-parse refs/heads/release) refs/heads/release
203 test-tool serve-v2 --stateless-rpc <in >out &&
204 test-tool pkt-line unpack <out >actual &&
205 test_cmp expect actual
208 test_expect_success
'ignore very large set of prefixes' '
209 # generate a large number of ref-prefixes that we expect
210 # to match nothing; the value here exceeds TOO_MANY_PREFIXES
213 echo command=ls-refs &&
214 echo object-format=$(test_oid algo) &&
216 perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" &&
219 test-tool pkt-line pack >in &&
221 # and then confirm that we see unmatched prefixes anyway (i.e.,
222 # that the prefix was not applied).
223 cat >expect <<-EOF &&
224 $(git rev-parse HEAD) HEAD
225 $(git rev-parse refs/heads/dev) refs/heads/dev
226 $(git rev-parse refs/heads/main) refs/heads/main
227 $(git rev-parse refs/heads/release) refs/heads/release
228 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
229 $(git rev-parse refs/tags/one) refs/tags/one
230 $(git rev-parse refs/tags/two) refs/tags/two
234 test-tool serve-v2 --stateless-rpc <in >out &&
235 test-tool pkt-line unpack <out >actual &&
236 test_cmp expect actual
239 test_expect_success
'peel parameter' '
240 test-tool pkt-line pack >in <<-EOF &&
242 object-format=$(test_oid algo)
245 ref-prefix refs/tags/
249 cat >expect <<-EOF &&
250 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
251 $(git rev-parse refs/tags/one) refs/tags/one
252 $(git rev-parse refs/tags/two) refs/tags/two
256 test-tool serve-v2 --stateless-rpc <in >out &&
257 test-tool pkt-line unpack <out >actual &&
258 test_cmp expect actual
261 test_expect_success
'symrefs parameter' '
262 test-tool pkt-line pack >in <<-EOF &&
264 object-format=$(test_oid algo)
267 ref-prefix refs/heads/
271 cat >expect <<-EOF &&
272 $(git rev-parse refs/heads/dev) refs/heads/dev
273 $(git rev-parse refs/heads/main) refs/heads/main
274 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/main
278 test-tool serve-v2 --stateless-rpc <in >out &&
279 test-tool pkt-line unpack <out >actual &&
280 test_cmp expect actual
283 test_expect_success
'sending server-options' '
284 test-tool pkt-line pack >in <<-EOF &&
286 object-format=$(test_oid algo)
294 cat >expect <<-EOF &&
295 $(git rev-parse HEAD) HEAD
299 test-tool serve-v2 --stateless-rpc <in >out &&
300 test-tool pkt-line unpack <out >actual &&
301 test_cmp expect actual
304 test_expect_success
'unexpected lines are not allowed in fetch request' '
307 test-tool pkt-line pack >in <<-EOF &&
309 object-format=$(test_oid algo)
311 this-is-not-a-command
317 test_must_fail test-tool serve-v2 --stateless-rpc
318 ) <in >/dev/null 2>err &&
319 grep "unexpected line: .this-is-not-a-command." err
322 # Test the basics of object-info
324 test_expect_success
'basics of object-info' '
325 test_config transfer.advertiseObjectInfo true &&
327 test-tool pkt-line pack >in <<-EOF &&
329 object-format=$(test_oid algo)
332 oid $(git rev-parse two:two.t)
333 oid $(git rev-parse two:two.t)
337 cat >expect <<-EOF &&
339 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
340 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
344 test-tool serve-v2 --stateless-rpc <in >out &&
345 test-tool pkt-line unpack <out >actual &&
346 test_cmp expect actual
349 test_expect_success
'test capability advertisement with uploadpack.advertiseBundleURIs' '
350 test_config uploadpack.advertiseBundleURIs true &&
352 cat >expect.extra <<-EOF &&
357 expect.trailer >expect &&
359 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
360 --advertise-capabilities >out &&
361 test-tool pkt-line unpack <out >actual &&
362 test_cmp expect actual
365 test_expect_success
'basics of bundle-uri: dies if not enabled' '
366 test-tool pkt-line pack >in <<-EOF &&
371 cat >err.expect <<-\EOF &&
372 fatal: invalid command '"'"'bundle-uri'"'"'
375 cat >expect <<-\EOF &&
376 ERR serve: invalid command '"'"'bundle-uri'"'"'
379 test_must_fail test-tool serve-v2 --stateless-rpc <in >out 2>err.actual &&
380 test_cmp err.expect err.actual &&
381 test_must_be_empty out
384 test_expect_success
'object-info missing from capabilities when disabled' '
385 test_config transfer.advertiseObjectInfo false &&
387 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
388 --advertise-capabilities >out &&
389 test-tool pkt-line unpack <out >actual &&
391 ! grep object.info actual
394 test_expect_success
'object-info commands rejected when disabled' '
395 test_config transfer.advertiseObjectInfo false &&
397 test-tool pkt-line pack >in <<-EOF &&
401 test_must_fail test-tool serve-v2 --stateless-rpc <in 2>err &&
402 grep invalid.command err