]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5701-git-serve.sh
Merge branch 'jk/bundle-progress'
[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)
a2ba162c 23 object-info
8b8d9a22
ÆAB
24 EOF
25 cat >expect.trailer <<-EOF &&
ed10cb95
BW
26 0000
27 EOF
8b8d9a22 28 cat expect.base expect.trailer >expect &&
ed10cb95 29
b7ce24d0
JS
30 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
31 --advertise-capabilities >out &&
8ea40cc5 32 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 33 test_cmp expect actual
ed10cb95
BW
34'
35
36test_expect_success 'stateless-rpc flag does not list capabilities' '
37 # Empty request
8ea40cc5 38 test-tool pkt-line pack >in <<-EOF &&
ed10cb95
BW
39 0000
40 EOF
b7ce24d0 41 test-tool serve-v2 --stateless-rpc >out <in &&
ed10cb95
BW
42 test_must_be_empty out &&
43
44 # EOF
b7ce24d0 45 test-tool serve-v2 --stateless-rpc >out &&
ed10cb95
BW
46 test_must_be_empty out
47'
48
49test_expect_success 'request invalid capability' '
8ea40cc5 50 test-tool pkt-line pack >in <<-EOF &&
ed10cb95
BW
51 foobar
52 0000
53 EOF
b7ce24d0 54 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
ed10cb95
BW
55 test_i18ngrep "unknown capability" err
56'
57
58test_expect_success 'request with no command' '
8ea40cc5 59 test-tool pkt-line pack >in <<-EOF &&
ed10cb95 60 agent=git/test
9de0dd36 61 object-format=$(test_oid algo)
ed10cb95
BW
62 0000
63 EOF
b7ce24d0 64 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
ed10cb95
BW
65 test_i18ngrep "no command requested" err
66'
67
68test_expect_success 'request invalid command' '
8ea40cc5 69 test-tool pkt-line pack >in <<-EOF &&
ed10cb95 70 command=foo
9de0dd36 71 object-format=$(test_oid algo)
ed10cb95
BW
72 agent=git/test
73 0000
74 EOF
b7ce24d0 75 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
ed10cb95
BW
76 test_i18ngrep "invalid command" err
77'
78
0ab7eecc
JK
79test_expect_success 'request capability as command' '
80 test-tool pkt-line pack >in <<-EOF &&
81 command=agent
82 object-format=$(test_oid algo)
83 0000
84 EOF
85 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
86 grep invalid.command.*agent err
87'
88
89test_expect_success 'request command as capability' '
90 test-tool pkt-line pack >in <<-EOF &&
91 command=ls-refs
92 object-format=$(test_oid algo)
93 fetch
94 0000
95 EOF
96 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
97 grep unknown.capability err
98'
99
108c265f
JK
100test_expect_success 'requested command is command=value' '
101 test-tool pkt-line pack >in <<-EOF &&
102 command=ls-refs=whatever
103 object-format=$(test_oid algo)
104 0000
105 EOF
106 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
107 grep invalid.command.*ls-refs=whatever err
108'
109
9de0dd36 110test_expect_success 'wrong object-format' '
111 test-tool pkt-line pack >in <<-EOF &&
112 command=fetch
113 agent=git/test
114 object-format=$(test_oid wrong_algo)
115 0000
116 EOF
117 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
118 test_i18ngrep "mismatched object format" err
119'
120
72d0ea00
BW
121# Test the basics of ls-refs
122#
123test_expect_success 'setup some refs and tags' '
124 test_commit one &&
95cf2c01 125 git branch dev main &&
72d0ea00 126 test_commit two &&
95cf2c01 127 git symbolic-ref refs/heads/release refs/heads/main &&
72d0ea00
BW
128 git tag -a -m "annotated tag" annotated-tag
129'
130
131test_expect_success 'basics of ls-refs' '
8ea40cc5 132 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 133 command=ls-refs
9de0dd36 134 object-format=$(test_oid algo)
72d0ea00
BW
135 0000
136 EOF
137
138 cat >expect <<-EOF &&
139 $(git rev-parse HEAD) HEAD
140 $(git rev-parse refs/heads/dev) refs/heads/dev
95cf2c01 141 $(git rev-parse refs/heads/main) refs/heads/main
72d0ea00
BW
142 $(git rev-parse refs/heads/release) refs/heads/release
143 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
144 $(git rev-parse refs/tags/one) refs/tags/one
145 $(git rev-parse refs/tags/two) refs/tags/two
146 0000
147 EOF
148
b7ce24d0 149 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 150 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 151 test_cmp expect actual
72d0ea00
BW
152'
153
ccf09478
JK
154test_expect_success 'ls-refs complains about unknown options' '
155 test-tool pkt-line pack >in <<-EOF &&
156 command=ls-refs
157 object-format=$(test_oid algo)
158 0001
159 no-such-arg
160 0000
161 EOF
162
163 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
164 grep unexpected.line.*no-such-arg err
165'
166
72d0ea00 167test_expect_success 'basic ref-prefixes' '
8ea40cc5 168 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 169 command=ls-refs
9de0dd36 170 object-format=$(test_oid algo)
72d0ea00 171 0001
95cf2c01 172 ref-prefix refs/heads/main
72d0ea00
BW
173 ref-prefix refs/tags/one
174 0000
175 EOF
176
177 cat >expect <<-EOF &&
95cf2c01 178 $(git rev-parse refs/heads/main) refs/heads/main
72d0ea00
BW
179 $(git rev-parse refs/tags/one) refs/tags/one
180 0000
181 EOF
182
b7ce24d0 183 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 184 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 185 test_cmp expect actual
72d0ea00
BW
186'
187
188test_expect_success 'refs/heads prefix' '
8ea40cc5 189 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 190 command=ls-refs
9de0dd36 191 object-format=$(test_oid algo)
72d0ea00
BW
192 0001
193 ref-prefix refs/heads/
194 0000
195 EOF
196
197 cat >expect <<-EOF &&
198 $(git rev-parse refs/heads/dev) refs/heads/dev
95cf2c01 199 $(git rev-parse refs/heads/main) refs/heads/main
72d0ea00
BW
200 $(git rev-parse refs/heads/release) refs/heads/release
201 0000
202 EOF
203
b7ce24d0 204 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 205 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 206 test_cmp expect actual
72d0ea00
BW
207'
208
7f0e4f6a
JK
209test_expect_success 'ignore very large set of prefixes' '
210 # generate a large number of ref-prefixes that we expect
211 # to match nothing; the value here exceeds TOO_MANY_PREFIXES
212 # from ls-refs.c.
213 {
214 echo command=ls-refs &&
215 echo object-format=$(test_oid algo) &&
216 echo 0001 &&
217 perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" &&
218 echo 0000
219 } |
220 test-tool pkt-line pack >in &&
221
222 # and then confirm that we see unmatched prefixes anyway (i.e.,
223 # that the prefix was not applied).
224 cat >expect <<-EOF &&
225 $(git rev-parse HEAD) HEAD
226 $(git rev-parse refs/heads/dev) refs/heads/dev
227 $(git rev-parse refs/heads/main) refs/heads/main
228 $(git rev-parse refs/heads/release) refs/heads/release
229 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
230 $(git rev-parse refs/tags/one) refs/tags/one
231 $(git rev-parse refs/tags/two) refs/tags/two
232 0000
233 EOF
234
235 test-tool serve-v2 --stateless-rpc <in >out &&
236 test-tool pkt-line unpack <out >actual &&
237 test_cmp expect actual
238'
239
72d0ea00 240test_expect_success 'peel parameter' '
8ea40cc5 241 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 242 command=ls-refs
9de0dd36 243 object-format=$(test_oid algo)
72d0ea00
BW
244 0001
245 peel
246 ref-prefix refs/tags/
247 0000
248 EOF
249
250 cat >expect <<-EOF &&
251 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
252 $(git rev-parse refs/tags/one) refs/tags/one
253 $(git rev-parse refs/tags/two) refs/tags/two
254 0000
255 EOF
256
b7ce24d0 257 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 258 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 259 test_cmp expect actual
72d0ea00
BW
260'
261
262test_expect_success 'symrefs parameter' '
8ea40cc5 263 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 264 command=ls-refs
9de0dd36 265 object-format=$(test_oid algo)
72d0ea00
BW
266 0001
267 symrefs
268 ref-prefix refs/heads/
269 0000
270 EOF
271
272 cat >expect <<-EOF &&
273 $(git rev-parse refs/heads/dev) refs/heads/dev
95cf2c01
JS
274 $(git rev-parse refs/heads/main) refs/heads/main
275 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/main
72d0ea00
BW
276 0000
277 EOF
278
b7ce24d0 279 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 280 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 281 test_cmp expect actual
72d0ea00
BW
282'
283
ecc3e534 284test_expect_success 'sending server-options' '
8ea40cc5 285 test-tool pkt-line pack >in <<-EOF &&
ecc3e534 286 command=ls-refs
9de0dd36 287 object-format=$(test_oid algo)
ecc3e534
BW
288 server-option=hello
289 server-option=world
290 0001
291 ref-prefix HEAD
292 0000
293 EOF
294
295 cat >expect <<-EOF &&
296 $(git rev-parse HEAD) HEAD
297 0000
298 EOF
299
b7ce24d0 300 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 301 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 302 test_cmp expect actual
ecc3e534
BW
303'
304
7cc6ed2d
JT
305test_expect_success 'unexpected lines are not allowed in fetch request' '
306 git init server &&
307
8ea40cc5 308 test-tool pkt-line pack >in <<-EOF &&
7cc6ed2d 309 command=fetch
9de0dd36 310 object-format=$(test_oid algo)
7cc6ed2d
JT
311 0001
312 this-is-not-a-command
313 0000
314 EOF
315
b7ce24d0
JS
316 (
317 cd server &&
318 test_must_fail test-tool serve-v2 --stateless-rpc
319 ) <in >/dev/null 2>err &&
7cc6ed2d
JT
320 grep "unexpected line: .this-is-not-a-command." err
321'
322
a2ba162c
BA
323# Test the basics of object-info
324#
325test_expect_success 'basics of object-info' '
326 test-tool pkt-line pack >in <<-EOF &&
327 command=object-info
328 object-format=$(test_oid algo)
329 0001
330 size
331 oid $(git rev-parse two:two.t)
332 oid $(git rev-parse two:two.t)
333 0000
334 EOF
335
336 cat >expect <<-EOF &&
337 size
338 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
339 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
340 0000
341 EOF
342
343 test-tool serve-v2 --stateless-rpc <in >out &&
344 test-tool pkt-line unpack <out >actual &&
345 test_cmp expect actual
346'
347
8b8d9a22
ÆAB
348test_expect_success 'test capability advertisement with uploadpack.advertiseBundleURIs' '
349 test_config uploadpack.advertiseBundleURIs true &&
350
351 cat >expect.extra <<-EOF &&
352 bundle-uri
353 EOF
354 cat expect.base \
355 expect.extra \
356 expect.trailer >expect &&
357
358 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
359 --advertise-capabilities >out &&
360 test-tool pkt-line unpack <out >actual &&
361 test_cmp expect actual
362'
363
364test_expect_success 'basics of bundle-uri: dies if not enabled' '
365 test-tool pkt-line pack >in <<-EOF &&
366 command=bundle-uri
367 0000
368 EOF
369
370 cat >err.expect <<-\EOF &&
371 fatal: invalid command '"'"'bundle-uri'"'"'
372 EOF
373
374 cat >expect <<-\EOF &&
375 ERR serve: invalid command '"'"'bundle-uri'"'"'
376 EOF
377
378 test_must_fail test-tool serve-v2 --stateless-rpc <in >out 2>err.actual &&
379 test_cmp err.expect err.actual &&
380 test_must_be_empty out
381'
382
ed10cb95 383test_done