]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ||
3 | test_description='test protocol v2 server commands' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'test capability advertisement' ' | |
8 | test_oid_cache <<-EOF && | |
9 | wrong_algo sha1:sha256 | |
10 | wrong_algo sha256:sha1 | |
11 | EOF | |
12 | cat >expect <<-EOF && | |
13 | version 2 | |
14 | agent=git/$(git version | cut -d" " -f3) | |
15 | ls-refs | |
16 | fetch=shallow | |
17 | server-option | |
18 | object-format=$(test_oid algo) | |
19 | 0000 | |
20 | EOF | |
21 | ||
22 | GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ | |
23 | --advertise-capabilities >out && | |
24 | test-tool pkt-line unpack <out >actual && | |
25 | test_cmp expect actual | |
26 | ' | |
27 | ||
28 | test_expect_success 'stateless-rpc flag does not list capabilities' ' | |
29 | # Empty request | |
30 | test-tool pkt-line pack >in <<-EOF && | |
31 | 0000 | |
32 | EOF | |
33 | test-tool serve-v2 --stateless-rpc >out <in && | |
34 | test_must_be_empty out && | |
35 | ||
36 | # EOF | |
37 | test-tool serve-v2 --stateless-rpc >out && | |
38 | test_must_be_empty out | |
39 | ' | |
40 | ||
41 | test_expect_success 'request invalid capability' ' | |
42 | test-tool pkt-line pack >in <<-EOF && | |
43 | foobar | |
44 | 0000 | |
45 | EOF | |
46 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && | |
47 | test_i18ngrep "unknown capability" err | |
48 | ' | |
49 | ||
50 | test_expect_success 'request with no command' ' | |
51 | test-tool pkt-line pack >in <<-EOF && | |
52 | agent=git/test | |
53 | object-format=$(test_oid algo) | |
54 | 0000 | |
55 | EOF | |
56 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && | |
57 | test_i18ngrep "no command requested" err | |
58 | ' | |
59 | ||
60 | test_expect_success 'request invalid command' ' | |
61 | test-tool pkt-line pack >in <<-EOF && | |
62 | command=foo | |
63 | object-format=$(test_oid algo) | |
64 | agent=git/test | |
65 | 0000 | |
66 | EOF | |
67 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && | |
68 | test_i18ngrep "invalid command" err | |
69 | ' | |
70 | ||
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 | ||
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' ' | |
93 | test-tool pkt-line pack >in <<-EOF && | |
94 | command=ls-refs | |
95 | object-format=$(test_oid algo) | |
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 | ||
110 | test-tool serve-v2 --stateless-rpc <in >out && | |
111 | test-tool pkt-line unpack <out >actual && | |
112 | test_cmp expect actual | |
113 | ' | |
114 | ||
115 | test_expect_success 'basic ref-prefixes' ' | |
116 | test-tool pkt-line pack >in <<-EOF && | |
117 | command=ls-refs | |
118 | object-format=$(test_oid algo) | |
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 | ||
131 | test-tool serve-v2 --stateless-rpc <in >out && | |
132 | test-tool pkt-line unpack <out >actual && | |
133 | test_cmp expect actual | |
134 | ' | |
135 | ||
136 | test_expect_success 'refs/heads prefix' ' | |
137 | test-tool pkt-line pack >in <<-EOF && | |
138 | command=ls-refs | |
139 | object-format=$(test_oid algo) | |
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 | ||
152 | test-tool serve-v2 --stateless-rpc <in >out && | |
153 | test-tool pkt-line unpack <out >actual && | |
154 | test_cmp expect actual | |
155 | ' | |
156 | ||
157 | test_expect_success 'peel parameter' ' | |
158 | test-tool pkt-line pack >in <<-EOF && | |
159 | command=ls-refs | |
160 | object-format=$(test_oid algo) | |
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 | ||
174 | test-tool serve-v2 --stateless-rpc <in >out && | |
175 | test-tool pkt-line unpack <out >actual && | |
176 | test_cmp expect actual | |
177 | ' | |
178 | ||
179 | test_expect_success 'symrefs parameter' ' | |
180 | test-tool pkt-line pack >in <<-EOF && | |
181 | command=ls-refs | |
182 | object-format=$(test_oid algo) | |
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 | ||
196 | test-tool serve-v2 --stateless-rpc <in >out && | |
197 | test-tool pkt-line unpack <out >actual && | |
198 | test_cmp expect actual | |
199 | ' | |
200 | ||
201 | test_expect_success 'sending server-options' ' | |
202 | test-tool pkt-line pack >in <<-EOF && | |
203 | command=ls-refs | |
204 | object-format=$(test_oid algo) | |
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 | ||
217 | test-tool serve-v2 --stateless-rpc <in >out && | |
218 | test-tool pkt-line unpack <out >actual && | |
219 | test_cmp expect actual | |
220 | ' | |
221 | ||
222 | test_expect_success 'unexpected lines are not allowed in fetch request' ' | |
223 | git init server && | |
224 | ||
225 | test-tool pkt-line pack >in <<-EOF && | |
226 | command=fetch | |
227 | object-format=$(test_oid algo) | |
228 | 0001 | |
229 | this-is-not-a-command | |
230 | 0000 | |
231 | EOF | |
232 | ||
233 | ( | |
234 | cd server && | |
235 | test_must_fail test-tool serve-v2 --stateless-rpc | |
236 | ) <in >/dev/null 2>err && | |
237 | grep "unexpected line: .this-is-not-a-command." err | |
238 | ' | |
239 | ||
240 | test_done |