Start the 2.46 cycle
[git/gitster.git] / t / t5701-git-serve.sh
blobc48830de8fe20448116f7988b450fe2d52d786e3
1 #!/bin/sh
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
9 . ./test-lib.sh
11 test_expect_success 'test capability advertisement' '
12 test_oid_cache <<-EOF &&
13 wrong_algo sha1:sha256
14 wrong_algo sha256:sha1
15 EOF
16 cat >expect.base <<-EOF &&
17 version 2
18 agent=git/$(git version | cut -d" " -f3)
19 ls-refs=unborn
20 fetch=shallow wait-for-done
21 server-option
22 object-format=$(test_oid algo)
23 EOF
24 cat >expect.trailer <<-EOF &&
25 0000
26 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' '
36 # Empty request
37 test-tool pkt-line pack >in <<-EOF &&
38 0000
39 EOF
40 test-tool serve-v2 --stateless-rpc >out <in &&
41 test_must_be_empty out &&
43 # EOF
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 &&
50 foobar
51 0000
52 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 &&
59 agent=git/test
60 object-format=$(test_oid algo)
61 0000
62 EOF
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 &&
69 command=foo
70 object-format=$(test_oid algo)
71 agent=git/test
72 0000
73 EOF
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 &&
80 command=agent
81 object-format=$(test_oid algo)
82 0000
83 EOF
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 &&
90 command=ls-refs
91 object-format=$(test_oid algo)
92 fetch
93 0000
94 EOF
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)
103 0000
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 &&
111 command=fetch
112 agent=git/test
113 object-format=$(test_oid wrong_algo)
114 0000
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' '
123 test_commit one &&
124 git branch dev main &&
125 test_commit two &&
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 &&
132 command=ls-refs
133 object-format=$(test_oid algo)
134 0000
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
145 0000
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 &&
155 command=ls-refs
156 object-format=$(test_oid algo)
157 0001
158 no-such-arg
159 0000
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 &&
168 command=ls-refs
169 object-format=$(test_oid algo)
170 0001
171 ref-prefix refs/heads/main
172 ref-prefix refs/tags/one
173 0000
176 cat >expect <<-EOF &&
177 $(git rev-parse refs/heads/main) refs/heads/main
178 $(git rev-parse refs/tags/one) refs/tags/one
179 0000
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 &&
189 command=ls-refs
190 object-format=$(test_oid algo)
191 0001
192 ref-prefix refs/heads/
193 0000
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
200 0000
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
211 # from ls-refs.c.
213 echo command=ls-refs &&
214 echo object-format=$(test_oid algo) &&
215 echo 0001 &&
216 perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" &&
217 echo 0000
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
231 0000
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 &&
241 command=ls-refs
242 object-format=$(test_oid algo)
243 0001
244 peel
245 ref-prefix refs/tags/
246 0000
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
253 0000
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 &&
263 command=ls-refs
264 object-format=$(test_oid algo)
265 0001
266 symrefs
267 ref-prefix refs/heads/
268 0000
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
275 0000
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 &&
285 command=ls-refs
286 object-format=$(test_oid algo)
287 server-option=hello
288 server-option=world
289 0001
290 ref-prefix HEAD
291 0000
294 cat >expect <<-EOF &&
295 $(git rev-parse HEAD) HEAD
296 0000
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' '
305 git init server &&
307 test-tool pkt-line pack >in <<-EOF &&
308 command=fetch
309 object-format=$(test_oid algo)
310 0001
311 this-is-not-a-command
312 0000
316 cd server &&
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 &&
328 command=object-info
329 object-format=$(test_oid algo)
330 0001
331 size
332 oid $(git rev-parse two:two.t)
333 oid $(git rev-parse two:two.t)
334 0000
337 cat >expect <<-EOF &&
338 size
339 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
340 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
341 0000
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 &&
353 bundle-uri
355 cat expect.base \
356 expect.extra \
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 &&
367 command=bundle-uri
368 0000
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 &&
398 command=object-info
401 test_must_fail test-tool serve-v2 --stateless-rpc <in 2>err &&
402 grep invalid.command err
405 test_done