interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t5701-git-serve.sh

534 lines · 12449 bytes Raw Blame History
1#!/bin/sh
2
3test_description='test protocol v2 server commands'
4
5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8. ./test-lib.sh
9
10unknown_oid=$(printf "test" | git hash-object --stdin)
11
12test_expect_success 'setup to generate files with expected content' '
13 printf "agent=git/%s" "$(git version | cut -d" " -f3)" >agent_capability &&
14
15 test_oid_cache <<-EOF &&
16 wrong_algo sha1:sha256
17 wrong_algo sha256:sha1
18 EOF
19
20 if test_have_prereq WINDOWS
21 then
22 printf "agent=FAKE\n" >agent_capability
23 else
24 printf -- "-%s\n" $(uname -s | test_redact_non_printables) >>agent_capability
25 fi &&
26 cat >expect.base <<-EOF &&
27 version 2
28 $(cat agent_capability)
29 ls-refs=unborn
30 fetch=shallow wait-for-done
31 server-option
32 object-format=$(test_oid algo)
33 EOF
34 cat >expect.trailer <<-EOF
35 0000
36 EOF
37'
38
39test_expect_success 'test capability advertisement' '
40 cat expect.base expect.trailer >expect &&
41
42 if test_have_prereq WINDOWS
43 then
44 GIT_USER_AGENT=FAKE && export GIT_USER_AGENT
45 fi &&
46 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
47 --advertise-capabilities >out &&
48 test-tool pkt-line unpack <out >actual &&
49 test_cmp expect actual
50'
51
52test_expect_success 'stateless-rpc flag does not list capabilities' '
53 # Empty request
54 test-tool pkt-line pack >in <<-EOF &&
55 0000
56 EOF
57 test-tool serve-v2 --stateless-rpc >out <in &&
58 test_must_be_empty out &&
59
60 # EOF
61 test-tool serve-v2 --stateless-rpc >out &&
62 test_must_be_empty out
63'
64
65test_expect_success 'request invalid capability' '
66 test-tool pkt-line pack >in <<-EOF &&
67 foobar
68 0000
69 EOF
70 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
71 test_grep "unknown capability" err
72'
73
74test_expect_success 'promisor-remote capability requires an argument' '
75 test-tool pkt-line pack >in <<-EOF &&
76 command=ls-refs
77 object-format=$(test_oid algo)
78 promisor-remote
79 0000
80 EOF
81 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
82 test_grep "promisor-remote capability requires an argument" err
83'
84
85test_expect_success 'request with no command' '
86 test-tool pkt-line pack >in <<-EOF &&
87 agent=git/test
88 object-format=$(test_oid algo)
89 0000
90 EOF
91 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
92 test_grep "no command requested" err
93'
94
95test_expect_success 'request invalid command' '
96 test-tool pkt-line pack >in <<-EOF &&
97 command=foo
98 object-format=$(test_oid algo)
99 agent=git/test
100 0000
101 EOF
102 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
103 test_grep "invalid command" err
104'
105
106test_expect_success 'request capability as command' '
107 test-tool pkt-line pack >in <<-EOF &&
108 command=agent
109 object-format=$(test_oid algo)
110 0000
111 EOF
112 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
113 test_grep invalid.command.*agent err
114'
115
116test_expect_success 'request command as capability' '
117 test-tool pkt-line pack >in <<-EOF &&
118 command=ls-refs
119 object-format=$(test_oid algo)
120 fetch
121 0000
122 EOF
123 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
124 test_grep unknown.capability err
125'
126
127test_expect_success 'requested command is command=value' '
128 test-tool pkt-line pack >in <<-EOF &&
129 command=ls-refs=whatever
130 object-format=$(test_oid algo)
131 0000
132 EOF
133 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
134 test_grep invalid.command.*ls-refs=whatever err
135'
136
137test_expect_success 'wrong object-format' '
138 test-tool pkt-line pack >in <<-EOF &&
139 command=fetch
140 agent=git/test
141 object-format=$(test_oid wrong_algo)
142 0000
143 EOF
144 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
145 test_grep "mismatched object format" err
146'
147
148# Test the basics of ls-refs
149#
150test_expect_success 'setup some refs and tags' '
151 test_commit one &&
152 git branch dev main &&
153 test_commit two &&
154 git symbolic-ref refs/heads/release refs/heads/main &&
155 git tag -a -m "annotated tag" annotated-tag
156'
157
158test_expect_success 'basics of ls-refs' '
159 test-tool pkt-line pack >in <<-EOF &&
160 command=ls-refs
161 object-format=$(test_oid algo)
162 0000
163 EOF
164
165 cat >expect <<-EOF &&
166 $(git rev-parse HEAD) HEAD
167 $(git rev-parse refs/heads/dev) refs/heads/dev
168 $(git rev-parse refs/heads/main) refs/heads/main
169 $(git rev-parse refs/heads/release) refs/heads/release
170 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
171 $(git rev-parse refs/tags/one) refs/tags/one
172 $(git rev-parse refs/tags/two) refs/tags/two
173 0000
174 EOF
175
176 test-tool serve-v2 --stateless-rpc <in >out &&
177 test-tool pkt-line unpack <out >actual &&
178 test_cmp expect actual
179'
180
181test_expect_success 'ls-refs complains about unknown options' '
182 test-tool pkt-line pack >in <<-EOF &&
183 command=ls-refs
184 object-format=$(test_oid algo)
185 0001
186 no-such-arg
187 0000
188 EOF
189
190 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
191 test_grep unexpected.line.*no-such-arg err
192'
193
194test_expect_success 'basic ref-prefixes' '
195 test-tool pkt-line pack >in <<-EOF &&
196 command=ls-refs
197 object-format=$(test_oid algo)
198 0001
199 ref-prefix refs/heads/main
200 ref-prefix refs/tags/one
201 0000
202 EOF
203
204 cat >expect <<-EOF &&
205 $(git rev-parse refs/heads/main) refs/heads/main
206 $(git rev-parse refs/tags/one) refs/tags/one
207 0000
208 EOF
209
210 test-tool serve-v2 --stateless-rpc <in >out &&
211 test-tool pkt-line unpack <out >actual &&
212 test_cmp expect actual
213'
214
215test_expect_success 'refs/heads prefix' '
216 test-tool pkt-line pack >in <<-EOF &&
217 command=ls-refs
218 object-format=$(test_oid algo)
219 0001
220 ref-prefix refs/heads/
221 0000
222 EOF
223
224 cat >expect <<-EOF &&
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 0000
229 EOF
230
231 test-tool serve-v2 --stateless-rpc <in >out &&
232 test-tool pkt-line unpack <out >actual &&
233 test_cmp expect actual
234'
235
236test_expect_success 'ignore very large set of prefixes' '
237 # generate a large number of ref-prefixes that we expect
238 # to match nothing; the value here exceeds TOO_MANY_PREFIXES
239 # from ls-refs.c.
240 {
241 echo command=ls-refs &&
242 echo object-format=$(test_oid algo) &&
243 echo 0001 &&
244 awk "{
245 for (i = 1; i <= 65536; i++)
246 print \"ref-prefix refs/heads/\", \$i
247 }" &&
248 echo 0000
249 } |
250 test-tool pkt-line pack >in &&
251
252 # and then confirm that we see unmatched prefixes anyway (i.e.,
253 # that the prefix was not applied).
254 cat >expect <<-EOF &&
255 $(git rev-parse HEAD) HEAD
256 $(git rev-parse refs/heads/dev) refs/heads/dev
257 $(git rev-parse refs/heads/main) refs/heads/main
258 $(git rev-parse refs/heads/release) refs/heads/release
259 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
260 $(git rev-parse refs/tags/one) refs/tags/one
261 $(git rev-parse refs/tags/two) refs/tags/two
262 0000
263 EOF
264
265 test-tool serve-v2 --stateless-rpc <in >out &&
266 test-tool pkt-line unpack <out >actual &&
267 test_cmp expect actual
268'
269
270test_expect_success 'peel parameter' '
271 test-tool pkt-line pack >in <<-EOF &&
272 command=ls-refs
273 object-format=$(test_oid algo)
274 0001
275 peel
276 ref-prefix refs/tags/
277 0000
278 EOF
279
280 cat >expect <<-EOF &&
281 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
282 $(git rev-parse refs/tags/one) refs/tags/one
283 $(git rev-parse refs/tags/two) refs/tags/two
284 0000
285 EOF
286
287 test-tool serve-v2 --stateless-rpc <in >out &&
288 test-tool pkt-line unpack <out >actual &&
289 test_cmp expect actual
290'
291
292test_expect_success 'symrefs parameter' '
293 test-tool pkt-line pack >in <<-EOF &&
294 command=ls-refs
295 object-format=$(test_oid algo)
296 0001
297 symrefs
298 ref-prefix refs/heads/
299 0000
300 EOF
301
302 cat >expect <<-EOF &&
303 $(git rev-parse refs/heads/dev) refs/heads/dev
304 $(git rev-parse refs/heads/main) refs/heads/main
305 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/main
306 0000
307 EOF
308
309 test-tool serve-v2 --stateless-rpc <in >out &&
310 test-tool pkt-line unpack <out >actual &&
311 test_cmp expect actual
312'
313
314test_expect_success 'sending server-options' '
315 test-tool pkt-line pack >in <<-EOF &&
316 command=ls-refs
317 object-format=$(test_oid algo)
318 server-option=hello
319 server-option=world
320 0001
321 ref-prefix HEAD
322 0000
323 EOF
324
325 cat >expect <<-EOF &&
326 $(git rev-parse HEAD) HEAD
327 0000
328 EOF
329
330 test-tool serve-v2 --stateless-rpc <in >out &&
331 test-tool pkt-line unpack <out >actual &&
332 test_cmp expect actual
333'
334
335test_expect_success 'unexpected lines are not allowed in fetch request' '
336 git init server &&
337
338 test-tool pkt-line pack >in <<-EOF &&
339 command=fetch
340 object-format=$(test_oid algo)
341 0001
342 this-is-not-a-command
343 0000
344 EOF
345
346 (
347 cd server &&
348 test_must_fail test-tool serve-v2 --stateless-rpc
349 ) <in >/dev/null 2>err &&
350 test_grep "unexpected line: .this-is-not-a-command." err
351'
352
353# Test the basics of object-info
354#
355test_expect_success 'basics of object-info' '
356 test_config transfer.advertiseObjectInfo true &&
357
358 two_oid=$(git rev-parse two:two.t) &&
359 two_size=$(test_file_size two.t) &&
360
361 test-tool pkt-line pack >in <<-EOF &&
362 command=object-info
363 object-format=$(test_oid algo)
364 0001
365 size
366 oid $two_oid
367 oid $two_oid
368 0000
369 EOF
370
371 cat >expect <<-EOF &&
372 size
373 $two_oid $two_size
374 $two_oid $two_size
375 0000
376 EOF
377
378 test-tool serve-v2 --stateless-rpc <in >out &&
379 test-tool pkt-line unpack <out >actual &&
380 test_cmp expect actual
381'
382
383test_expect_success 'object-info supports type' '
384 test_config transfer.advertiseObjectInfo true &&
385
386 two_oid=$(git rev-parse two:two.t) &&
387 two_size=$(test_file_size two.t) &&
388
389 test-tool pkt-line pack >in <<-EOF &&
390 command=object-info
391 object-format=$(test_oid algo)
392 0001
393 size
394 type
395 oid $two_oid
396 oid $two_oid
397 0000
398 EOF
399
400 cat >expect <<-EOF &&
401 size
402 type
403 $two_oid $two_size blob
404 $two_oid $two_size blob
405 0000
406 EOF
407
408 test-tool serve-v2 --stateless-rpc <in >out &&
409 test-tool pkt-line unpack <out >actual &&
410 test_cmp expect actual
411'
412
413test_expect_success 'bare OID request' '
414 test_config transfer.advertiseObjectInfo true &&
415
416 test-tool pkt-line pack >in <<-EOF &&
417 command=object-info
418 object-format=$(test_oid algo)
419 0001
420 oid $(git rev-parse two:two.t)
421 0000
422 EOF
423
424 cat >expect <<-EOF &&
425 $(git rev-parse two:two.t)
426 0000
427 EOF
428
429 test-tool serve-v2 --stateless-rpc <in >out &&
430 test-tool pkt-line unpack <out >actual &&
431 test_cmp expect actual
432'
433
434test_expect_success 'object-info with bare unrecognized OID' '
435 test_config transfer.advertiseObjectInfo true &&
436
437 test-tool pkt-line pack >in <<-EOF &&
438 command=object-info
439 object-format=$(test_oid algo)
440 0001
441 oid $unknown_oid
442 0000
443 EOF
444
445 printf "%s \n" "$unknown_oid" >expect &&
446 printf "0000\n" >>expect &&
447
448 test-tool serve-v2 --stateless-rpc <in >out &&
449 test-tool pkt-line unpack <out >actual &&
450 test_cmp expect actual
451'
452
453test_expect_success 'object-info with size for unrecognized OID' '
454 test_config transfer.advertiseObjectInfo true &&
455
456 test-tool pkt-line pack >in <<-EOF &&
457 command=object-info
458 object-format=$(test_oid algo)
459 0001
460 size
461 oid $unknown_oid
462 0000
463 EOF
464
465 printf "size\n" >expect &&
466 printf "%s \n" "$unknown_oid" >>expect &&
467 printf "0000\n" >>expect &&
468
469 test-tool serve-v2 --stateless-rpc <in >out &&
470 test-tool pkt-line unpack <out >actual &&
471 test_cmp expect actual
472'
473
474test_expect_success 'test capability advertisement with uploadpack.advertiseBundleURIs' '
475 test_config uploadpack.advertiseBundleURIs true &&
476
477 cat >expect.extra <<-EOF &&
478 bundle-uri
479 EOF
480 cat expect.base \
481 expect.extra \
482 expect.trailer >expect &&
483
484 if test_have_prereq WINDOWS
485 then
486 GIT_USER_AGENT=FAKE && export GIT_USER_AGENT
487 fi &&
488 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
489 --advertise-capabilities >out &&
490 test-tool pkt-line unpack <out >actual &&
491 test_cmp expect actual
492'
493
494test_expect_success 'basics of bundle-uri: dies if not enabled' '
495 test-tool pkt-line pack >in <<-EOF &&
496 command=bundle-uri
497 0000
498 EOF
499
500 cat >err.expect <<-\EOF &&
501 fatal: invalid command '"'"'bundle-uri'"'"'
502 EOF
503
504 cat >expect <<-\EOF &&
505 ERR serve: invalid command '"'"'bundle-uri'"'"'
506 EOF
507
508 test_must_fail test-tool serve-v2 --stateless-rpc <in >out 2>err.actual &&
509 test_cmp err.expect err.actual &&
510 test_must_be_empty out
511'
512
513test_expect_success 'object-info missing from capabilities when disabled' '
514 test_config transfer.advertiseObjectInfo false &&
515
516 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
517 --advertise-capabilities >out &&
518 test-tool pkt-line unpack <out >actual &&
519
520 test_grep ! object.info actual
521'
522
523test_expect_success 'object-info commands rejected when disabled' '
524 test_config transfer.advertiseObjectInfo false &&
525
526 test-tool pkt-line pack >in <<-EOF &&
527 command=object-info
528 EOF
529
530 test_must_fail test-tool serve-v2 --stateless-rpc <in 2>err &&
531 test_grep invalid.command err
532'
533
534test_done