]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5701-git-serve.sh
The third batch
[thirdparty/git.git] / t / t5701-git-serve.sh
CommitLineData
ed10cb95
BW
1#!/bin/sh
2
b7ce24d0 3test_description='test protocol v2 server commands'
ed10cb95 4
95cf2c01 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
d96fb140 8TEST_PASSES_SANITIZE_LEAK=true
ed10cb95
BW
9. ./test-lib.sh
10
11test_expect_success 'test capability advertisement' '
9de0dd36 12 test_oid_cache <<-EOF &&
13 wrong_algo sha1:sha256
14 wrong_algo sha256:sha1
15 EOF
8b8d9a22 16 cat >expect.base <<-EOF &&
ed10cb95
BW
17 version 2
18 agent=git/$(git version | cut -d" " -f3)
59e1205d 19 ls-refs=unborn
9c1e657a 20 fetch=shallow wait-for-done
ecc3e534 21 server-option
9de0dd36 22 object-format=$(test_oid algo)
8b8d9a22
ÆAB
23 EOF
24 cat >expect.trailer <<-EOF &&
ed10cb95
BW
25 0000
26 EOF
8b8d9a22 27 cat expect.base expect.trailer >expect &&
ed10cb95 28
b7ce24d0
JS
29 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
30 --advertise-capabilities >out &&
8ea40cc5 31 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 32 test_cmp expect actual
ed10cb95
BW
33'
34
35test_expect_success 'stateless-rpc flag does not list capabilities' '
36 # Empty request
8ea40cc5 37 test-tool pkt-line pack >in <<-EOF &&
ed10cb95
BW
38 0000
39 EOF
b7ce24d0 40 test-tool serve-v2 --stateless-rpc >out <in &&
ed10cb95
BW
41 test_must_be_empty out &&
42
43 # EOF
b7ce24d0 44 test-tool serve-v2 --stateless-rpc >out &&
ed10cb95
BW
45 test_must_be_empty out
46'
47
48test_expect_success 'request invalid capability' '
8ea40cc5 49 test-tool pkt-line pack >in <<-EOF &&
ed10cb95
BW
50 foobar
51 0000
52 EOF
b7ce24d0 53 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
6789275d 54 test_grep "unknown capability" err
ed10cb95
BW
55'
56
57test_expect_success 'request with no command' '
8ea40cc5 58 test-tool pkt-line pack >in <<-EOF &&
ed10cb95 59 agent=git/test
9de0dd36 60 object-format=$(test_oid algo)
ed10cb95
BW
61 0000
62 EOF
b7ce24d0 63 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
6789275d 64 test_grep "no command requested" err
ed10cb95
BW
65'
66
67test_expect_success 'request invalid command' '
8ea40cc5 68 test-tool pkt-line pack >in <<-EOF &&
ed10cb95 69 command=foo
9de0dd36 70 object-format=$(test_oid algo)
ed10cb95
BW
71 agent=git/test
72 0000
73 EOF
b7ce24d0 74 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
6789275d 75 test_grep "invalid command" err
ed10cb95
BW
76'
77
0ab7eecc
JK
78test_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
86'
87
88test_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
97'
98
108c265f
JK
99test_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
104 EOF
105 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
106 grep invalid.command.*ls-refs=whatever err
107'
108
9de0dd36 109test_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
115 EOF
116 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
6789275d 117 test_grep "mismatched object format" err
9de0dd36 118'
119
72d0ea00
BW
120# Test the basics of ls-refs
121#
122test_expect_success 'setup some refs and tags' '
123 test_commit one &&
95cf2c01 124 git branch dev main &&
72d0ea00 125 test_commit two &&
95cf2c01 126 git symbolic-ref refs/heads/release refs/heads/main &&
72d0ea00
BW
127 git tag -a -m "annotated tag" annotated-tag
128'
129
130test_expect_success 'basics of ls-refs' '
8ea40cc5 131 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 132 command=ls-refs
9de0dd36 133 object-format=$(test_oid algo)
72d0ea00
BW
134 0000
135 EOF
136
137 cat >expect <<-EOF &&
138 $(git rev-parse HEAD) HEAD
139 $(git rev-parse refs/heads/dev) refs/heads/dev
95cf2c01 140 $(git rev-parse refs/heads/main) refs/heads/main
72d0ea00
BW
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
146 EOF
147
b7ce24d0 148 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 149 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 150 test_cmp expect actual
72d0ea00
BW
151'
152
ccf09478
JK
153test_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
160 EOF
161
162 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
163 grep unexpected.line.*no-such-arg err
164'
165
72d0ea00 166test_expect_success 'basic ref-prefixes' '
8ea40cc5 167 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 168 command=ls-refs
9de0dd36 169 object-format=$(test_oid algo)
72d0ea00 170 0001
95cf2c01 171 ref-prefix refs/heads/main
72d0ea00
BW
172 ref-prefix refs/tags/one
173 0000
174 EOF
175
176 cat >expect <<-EOF &&
95cf2c01 177 $(git rev-parse refs/heads/main) refs/heads/main
72d0ea00
BW
178 $(git rev-parse refs/tags/one) refs/tags/one
179 0000
180 EOF
181
b7ce24d0 182 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 183 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 184 test_cmp expect actual
72d0ea00
BW
185'
186
187test_expect_success 'refs/heads prefix' '
8ea40cc5 188 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 189 command=ls-refs
9de0dd36 190 object-format=$(test_oid algo)
72d0ea00
BW
191 0001
192 ref-prefix refs/heads/
193 0000
194 EOF
195
196 cat >expect <<-EOF &&
197 $(git rev-parse refs/heads/dev) refs/heads/dev
95cf2c01 198 $(git rev-parse refs/heads/main) refs/heads/main
72d0ea00
BW
199 $(git rev-parse refs/heads/release) refs/heads/release
200 0000
201 EOF
202
b7ce24d0 203 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 204 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 205 test_cmp expect actual
72d0ea00
BW
206'
207
7f0e4f6a
JK
208test_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.
212 {
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
218 } |
219 test-tool pkt-line pack >in &&
220
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
232 EOF
233
234 test-tool serve-v2 --stateless-rpc <in >out &&
235 test-tool pkt-line unpack <out >actual &&
236 test_cmp expect actual
237'
238
72d0ea00 239test_expect_success 'peel parameter' '
8ea40cc5 240 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 241 command=ls-refs
9de0dd36 242 object-format=$(test_oid algo)
72d0ea00
BW
243 0001
244 peel
245 ref-prefix refs/tags/
246 0000
247 EOF
248
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
254 EOF
255
b7ce24d0 256 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 257 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 258 test_cmp expect actual
72d0ea00
BW
259'
260
261test_expect_success 'symrefs parameter' '
8ea40cc5 262 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 263 command=ls-refs
9de0dd36 264 object-format=$(test_oid algo)
72d0ea00
BW
265 0001
266 symrefs
267 ref-prefix refs/heads/
268 0000
269 EOF
270
271 cat >expect <<-EOF &&
272 $(git rev-parse refs/heads/dev) refs/heads/dev
95cf2c01
JS
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
72d0ea00
BW
275 0000
276 EOF
277
b7ce24d0 278 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 279 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 280 test_cmp expect actual
72d0ea00
BW
281'
282
ecc3e534 283test_expect_success 'sending server-options' '
8ea40cc5 284 test-tool pkt-line pack >in <<-EOF &&
ecc3e534 285 command=ls-refs
9de0dd36 286 object-format=$(test_oid algo)
ecc3e534
BW
287 server-option=hello
288 server-option=world
289 0001
290 ref-prefix HEAD
291 0000
292 EOF
293
294 cat >expect <<-EOF &&
295 $(git rev-parse HEAD) HEAD
296 0000
297 EOF
298
b7ce24d0 299 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 300 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 301 test_cmp expect actual
ecc3e534
BW
302'
303
7cc6ed2d
JT
304test_expect_success 'unexpected lines are not allowed in fetch request' '
305 git init server &&
306
8ea40cc5 307 test-tool pkt-line pack >in <<-EOF &&
7cc6ed2d 308 command=fetch
9de0dd36 309 object-format=$(test_oid algo)
7cc6ed2d
JT
310 0001
311 this-is-not-a-command
312 0000
313 EOF
314
b7ce24d0
JS
315 (
316 cd server &&
317 test_must_fail test-tool serve-v2 --stateless-rpc
318 ) <in >/dev/null 2>err &&
7cc6ed2d
JT
319 grep "unexpected line: .this-is-not-a-command." err
320'
321
a2ba162c
BA
322# Test the basics of object-info
323#
324test_expect_success 'basics of object-info' '
8c735b11
TB
325 test_config transfer.advertiseObjectInfo true &&
326
a2ba162c
BA
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
335 EOF
336
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
342 EOF
343
344 test-tool serve-v2 --stateless-rpc <in >out &&
345 test-tool pkt-line unpack <out >actual &&
346 test_cmp expect actual
347'
348
8b8d9a22
ÆAB
349test_expect_success 'test capability advertisement with uploadpack.advertiseBundleURIs' '
350 test_config uploadpack.advertiseBundleURIs true &&
351
352 cat >expect.extra <<-EOF &&
353 bundle-uri
354 EOF
355 cat expect.base \
356 expect.extra \
357 expect.trailer >expect &&
358
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
363'
364
365test_expect_success 'basics of bundle-uri: dies if not enabled' '
366 test-tool pkt-line pack >in <<-EOF &&
367 command=bundle-uri
368 0000
369 EOF
370
371 cat >err.expect <<-\EOF &&
372 fatal: invalid command '"'"'bundle-uri'"'"'
373 EOF
374
375 cat >expect <<-\EOF &&
376 ERR serve: invalid command '"'"'bundle-uri'"'"'
377 EOF
378
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
382'
383
8c735b11
TB
384test_expect_success 'object-info missing from capabilities when disabled' '
385 test_config transfer.advertiseObjectInfo false &&
386
387 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
388 --advertise-capabilities >out &&
389 test-tool pkt-line unpack <out >actual &&
390
391 ! grep object.info actual
392'
393
394test_expect_success 'object-info commands rejected when disabled' '
395 test_config transfer.advertiseObjectInfo false &&
396
397 test-tool pkt-line pack >in <<-EOF &&
398 command=object-info
399 EOF
400
401 test_must_fail test-tool serve-v2 --stateless-rpc <in 2>err &&
402 grep invalid.command err
403'
404
ed10cb95 405test_done