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