]>
Commit | Line | Data |
---|---|---|
ed10cb95 BW |
1 | #!/bin/sh |
2 | ||
b7ce24d0 | 3 | test_description='test protocol v2 server commands' |
ed10cb95 BW |
4 | |
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'test capability advertisement' ' | |
9de0dd36 | 8 | test_oid_cache <<-EOF && |
9 | wrong_algo sha1:sha256 | |
10 | wrong_algo sha256:sha1 | |
11 | EOF | |
ed10cb95 BW |
12 | cat >expect <<-EOF && |
13 | version 2 | |
14 | agent=git/$(git version | cut -d" " -f3) | |
72d0ea00 | 15 | ls-refs |
685fbd32 | 16 | fetch=shallow |
ecc3e534 | 17 | server-option |
9de0dd36 | 18 | object-format=$(test_oid algo) |
ed10cb95 BW |
19 | 0000 |
20 | EOF | |
21 | ||
b7ce24d0 JS |
22 | GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ |
23 | --advertise-capabilities >out && | |
8ea40cc5 | 24 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 25 | test_cmp expect actual |
ed10cb95 BW |
26 | ' |
27 | ||
28 | test_expect_success 'stateless-rpc flag does not list capabilities' ' | |
29 | # Empty request | |
8ea40cc5 | 30 | test-tool pkt-line pack >in <<-EOF && |
ed10cb95 BW |
31 | 0000 |
32 | EOF | |
b7ce24d0 | 33 | test-tool serve-v2 --stateless-rpc >out <in && |
ed10cb95 BW |
34 | test_must_be_empty out && |
35 | ||
36 | # EOF | |
b7ce24d0 | 37 | test-tool serve-v2 --stateless-rpc >out && |
ed10cb95 BW |
38 | test_must_be_empty out |
39 | ' | |
40 | ||
41 | test_expect_success 'request invalid capability' ' | |
8ea40cc5 | 42 | test-tool pkt-line pack >in <<-EOF && |
ed10cb95 BW |
43 | foobar |
44 | 0000 | |
45 | EOF | |
b7ce24d0 | 46 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
ed10cb95 BW |
47 | test_i18ngrep "unknown capability" err |
48 | ' | |
49 | ||
50 | test_expect_success 'request with no command' ' | |
8ea40cc5 | 51 | test-tool pkt-line pack >in <<-EOF && |
ed10cb95 | 52 | agent=git/test |
9de0dd36 | 53 | object-format=$(test_oid algo) |
ed10cb95 BW |
54 | 0000 |
55 | EOF | |
b7ce24d0 | 56 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
ed10cb95 BW |
57 | test_i18ngrep "no command requested" err |
58 | ' | |
59 | ||
60 | test_expect_success 'request invalid command' ' | |
8ea40cc5 | 61 | test-tool pkt-line pack >in <<-EOF && |
ed10cb95 | 62 | command=foo |
9de0dd36 | 63 | object-format=$(test_oid algo) |
ed10cb95 BW |
64 | agent=git/test |
65 | 0000 | |
66 | EOF | |
b7ce24d0 | 67 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
ed10cb95 BW |
68 | test_i18ngrep "invalid command" err |
69 | ' | |
70 | ||
9de0dd36 | 71 | test_expect_success 'wrong object-format' ' |
72 | test-tool pkt-line pack >in <<-EOF && | |
73 | command=fetch | |
74 | agent=git/test | |
75 | object-format=$(test_oid wrong_algo) | |
76 | 0000 | |
77 | EOF | |
78 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && | |
79 | test_i18ngrep "mismatched object format" err | |
80 | ' | |
81 | ||
72d0ea00 BW |
82 | # Test the basics of ls-refs |
83 | # | |
84 | test_expect_success 'setup some refs and tags' ' | |
85 | test_commit one && | |
86 | git branch dev master && | |
87 | test_commit two && | |
88 | git symbolic-ref refs/heads/release refs/heads/master && | |
89 | git tag -a -m "annotated tag" annotated-tag | |
90 | ' | |
91 | ||
92 | test_expect_success 'basics of ls-refs' ' | |
8ea40cc5 | 93 | test-tool pkt-line pack >in <<-EOF && |
72d0ea00 | 94 | command=ls-refs |
9de0dd36 | 95 | object-format=$(test_oid algo) |
72d0ea00 BW |
96 | 0000 |
97 | EOF | |
98 | ||
99 | cat >expect <<-EOF && | |
100 | $(git rev-parse HEAD) HEAD | |
101 | $(git rev-parse refs/heads/dev) refs/heads/dev | |
102 | $(git rev-parse refs/heads/master) refs/heads/master | |
103 | $(git rev-parse refs/heads/release) refs/heads/release | |
104 | $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag | |
105 | $(git rev-parse refs/tags/one) refs/tags/one | |
106 | $(git rev-parse refs/tags/two) refs/tags/two | |
107 | 0000 | |
108 | EOF | |
109 | ||
b7ce24d0 | 110 | test-tool serve-v2 --stateless-rpc <in >out && |
8ea40cc5 | 111 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 112 | test_cmp expect actual |
72d0ea00 BW |
113 | ' |
114 | ||
115 | test_expect_success 'basic ref-prefixes' ' | |
8ea40cc5 | 116 | test-tool pkt-line pack >in <<-EOF && |
72d0ea00 | 117 | command=ls-refs |
9de0dd36 | 118 | object-format=$(test_oid algo) |
72d0ea00 BW |
119 | 0001 |
120 | ref-prefix refs/heads/master | |
121 | ref-prefix refs/tags/one | |
122 | 0000 | |
123 | EOF | |
124 | ||
125 | cat >expect <<-EOF && | |
126 | $(git rev-parse refs/heads/master) refs/heads/master | |
127 | $(git rev-parse refs/tags/one) refs/tags/one | |
128 | 0000 | |
129 | EOF | |
130 | ||
b7ce24d0 | 131 | test-tool serve-v2 --stateless-rpc <in >out && |
8ea40cc5 | 132 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 133 | test_cmp expect actual |
72d0ea00 BW |
134 | ' |
135 | ||
136 | test_expect_success 'refs/heads prefix' ' | |
8ea40cc5 | 137 | test-tool pkt-line pack >in <<-EOF && |
72d0ea00 | 138 | command=ls-refs |
9de0dd36 | 139 | object-format=$(test_oid algo) |
72d0ea00 BW |
140 | 0001 |
141 | ref-prefix refs/heads/ | |
142 | 0000 | |
143 | EOF | |
144 | ||
145 | cat >expect <<-EOF && | |
146 | $(git rev-parse refs/heads/dev) refs/heads/dev | |
147 | $(git rev-parse refs/heads/master) refs/heads/master | |
148 | $(git rev-parse refs/heads/release) refs/heads/release | |
149 | 0000 | |
150 | EOF | |
151 | ||
b7ce24d0 | 152 | test-tool serve-v2 --stateless-rpc <in >out && |
8ea40cc5 | 153 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 154 | test_cmp expect actual |
72d0ea00 BW |
155 | ' |
156 | ||
157 | test_expect_success 'peel parameter' ' | |
8ea40cc5 | 158 | test-tool pkt-line pack >in <<-EOF && |
72d0ea00 | 159 | command=ls-refs |
9de0dd36 | 160 | object-format=$(test_oid algo) |
72d0ea00 BW |
161 | 0001 |
162 | peel | |
163 | ref-prefix refs/tags/ | |
164 | 0000 | |
165 | EOF | |
166 | ||
167 | cat >expect <<-EOF && | |
168 | $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{}) | |
169 | $(git rev-parse refs/tags/one) refs/tags/one | |
170 | $(git rev-parse refs/tags/two) refs/tags/two | |
171 | 0000 | |
172 | EOF | |
173 | ||
b7ce24d0 | 174 | test-tool serve-v2 --stateless-rpc <in >out && |
8ea40cc5 | 175 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 176 | test_cmp expect actual |
72d0ea00 BW |
177 | ' |
178 | ||
179 | test_expect_success 'symrefs parameter' ' | |
8ea40cc5 | 180 | test-tool pkt-line pack >in <<-EOF && |
72d0ea00 | 181 | command=ls-refs |
9de0dd36 | 182 | object-format=$(test_oid algo) |
72d0ea00 BW |
183 | 0001 |
184 | symrefs | |
185 | ref-prefix refs/heads/ | |
186 | 0000 | |
187 | EOF | |
188 | ||
189 | cat >expect <<-EOF && | |
190 | $(git rev-parse refs/heads/dev) refs/heads/dev | |
191 | $(git rev-parse refs/heads/master) refs/heads/master | |
192 | $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/master | |
193 | 0000 | |
194 | EOF | |
195 | ||
b7ce24d0 | 196 | test-tool serve-v2 --stateless-rpc <in >out && |
8ea40cc5 | 197 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 198 | test_cmp expect actual |
72d0ea00 BW |
199 | ' |
200 | ||
ecc3e534 | 201 | test_expect_success 'sending server-options' ' |
8ea40cc5 | 202 | test-tool pkt-line pack >in <<-EOF && |
ecc3e534 | 203 | command=ls-refs |
9de0dd36 | 204 | object-format=$(test_oid algo) |
ecc3e534 BW |
205 | server-option=hello |
206 | server-option=world | |
207 | 0001 | |
208 | ref-prefix HEAD | |
209 | 0000 | |
210 | EOF | |
211 | ||
212 | cat >expect <<-EOF && | |
213 | $(git rev-parse HEAD) HEAD | |
214 | 0000 | |
215 | EOF | |
216 | ||
b7ce24d0 | 217 | test-tool serve-v2 --stateless-rpc <in >out && |
8ea40cc5 | 218 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 219 | test_cmp expect actual |
ecc3e534 BW |
220 | ' |
221 | ||
7cc6ed2d JT |
222 | test_expect_success 'unexpected lines are not allowed in fetch request' ' |
223 | git init server && | |
224 | ||
8ea40cc5 | 225 | test-tool pkt-line pack >in <<-EOF && |
7cc6ed2d | 226 | command=fetch |
9de0dd36 | 227 | object-format=$(test_oid algo) |
7cc6ed2d JT |
228 | 0001 |
229 | this-is-not-a-command | |
230 | 0000 | |
231 | EOF | |
232 | ||
b7ce24d0 JS |
233 | ( |
234 | cd server && | |
235 | test_must_fail test-tool serve-v2 --stateless-rpc | |
236 | ) <in >/dev/null 2>err && | |
7cc6ed2d JT |
237 | grep "unexpected line: .this-is-not-a-command." err |
238 | ' | |
239 | ||
ed10cb95 | 240 | test_done |