Blame


1 581fa623 2022-12-30 thomas #!/bin/sh
2 581fa623 2022-12-30 thomas #
3 581fa623 2022-12-30 thomas # Copyright (c) 2022 Mikhail Pchelin <misha@freebsd.org>
4 581fa623 2022-12-30 thomas #
5 581fa623 2022-12-30 thomas # Permission to use, copy, modify, and distribute this software for any
6 581fa623 2022-12-30 thomas # purpose with or without fee is hereby granted, provided that the above
7 581fa623 2022-12-30 thomas # copyright notice and this permission notice appear in all copies.
8 581fa623 2022-12-30 thomas #
9 581fa623 2022-12-30 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 581fa623 2022-12-30 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 581fa623 2022-12-30 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 581fa623 2022-12-30 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 581fa623 2022-12-30 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 581fa623 2022-12-30 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 581fa623 2022-12-30 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 581fa623 2022-12-30 thomas
17 581fa623 2022-12-30 thomas . ../cmdline/common.sh
18 581fa623 2022-12-30 thomas . ./common.sh
19 581fa623 2022-12-30 thomas
20 45b9d1e9 2022-12-30 thomas dummy_commit="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
21 45b9d1e9 2022-12-30 thomas
22 581fa623 2022-12-30 thomas # Non-existent commit
23 581fa623 2022-12-30 thomas test_request_bad_commit() {
24 581fa623 2022-12-30 thomas local testroot=`test_init request_bad_commit`
25 581fa623 2022-12-30 thomas
26 45b9d1e9 2022-12-30 thomas echo "0054want $dummy_commit multi_ack side-band-64k ofs-delta" \
27 45b9d1e9 2022-12-30 thomas | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
28 45b9d1e9 2022-12-30 thomas > $testroot/stdout 2>$testroot/stderr
29 581fa623 2022-12-30 thomas
30 45b9d1e9 2022-12-30 thomas echo -n "0041ERR object $dummy_commit not found" \
31 45b9d1e9 2022-12-30 thomas > $testroot/stdout.expected
32 581fa623 2022-12-30 thomas
33 45b9d1e9 2022-12-30 thomas echo "gotsh: object $dummy_commit not found" \
34 45b9d1e9 2022-12-30 thomas > $testroot/stderr.expected
35 581fa623 2022-12-30 thomas
36 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout 0 112
37 581fa623 2022-12-30 thomas ret=$?
38 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
39 581fa623 2022-12-30 thomas echo "unexpected stdout" >&2
40 581fa623 2022-12-30 thomas test_done "$testroot" "1"
41 581fa623 2022-12-30 thomas return 1
42 581fa623 2022-12-30 thomas fi
43 581fa623 2022-12-30 thomas
44 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
45 581fa623 2022-12-30 thomas ret=$?
46 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
47 581fa623 2022-12-30 thomas echo "unexpected stderr" >&2
48 45b9d1e9 2022-12-30 thomas diff -u $testroot/stderr.expected $testroot/stderr
49 581fa623 2022-12-30 thomas test_done "$testroot" "1"
50 581fa623 2022-12-30 thomas return 1
51 581fa623 2022-12-30 thomas fi
52 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
53 581fa623 2022-12-30 thomas }
54 581fa623 2022-12-30 thomas
55 581fa623 2022-12-30 thomas # Zero pkt-len (as flush packet with payload)
56 581fa623 2022-12-30 thomas test_request_bad_length_zero() {
57 581fa623 2022-12-30 thomas local testroot=`test_init test_request_bad_length_zero`
58 581fa623 2022-12-30 thomas
59 45b9d1e9 2022-12-30 thomas echo "0000want $dummy_commit multi_ack side-band-64k ofs-delta" \
60 45b9d1e9 2022-12-30 thomas | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
61 45b9d1e9 2022-12-30 thomas > $testroot/stdout 2>$testroot/stderr
62 581fa623 2022-12-30 thomas
63 581fa623 2022-12-30 thomas echo -n "00000028ERR unexpected flush packet received" \
64 581fa623 2022-12-30 thomas > $testroot/stdout.expected
65 581fa623 2022-12-30 thomas
66 581fa623 2022-12-30 thomas echo "gotsh: unexpected flush packet received" \
67 581fa623 2022-12-30 thomas > $testroot/stderr.expected
68 581fa623 2022-12-30 thomas
69 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout 0 108
70 581fa623 2022-12-30 thomas ret=$?
71 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
72 581fa623 2022-12-30 thomas echo "unexpected stdout" >&2
73 581fa623 2022-12-30 thomas test_done "$testroot" "1"
74 581fa623 2022-12-30 thomas return 1
75 581fa623 2022-12-30 thomas fi
76 581fa623 2022-12-30 thomas
77 581fa623 2022-12-30 thomas cmp -s $testroot/stderr $testroot/stderr.expected
78 581fa623 2022-12-30 thomas ret=$?
79 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
80 581fa623 2022-12-30 thomas echo "unexpected stderr" >&2
81 45b9d1e9 2022-12-30 thomas diff -u $testroot/stderr.expected $testroot/stderr
82 581fa623 2022-12-30 thomas test_done "$testroot" "1"
83 581fa623 2022-12-30 thomas return 1
84 581fa623 2022-12-30 thomas fi
85 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
86 581fa623 2022-12-30 thomas }
87 581fa623 2022-12-30 thomas
88 581fa623 2022-12-30 thomas # 0004 (empty)
89 581fa623 2022-12-30 thomas test_request_bad_length_empty() {
90 581fa623 2022-12-30 thomas local testroot=`test_init test_request_bad_length_empty`
91 581fa623 2022-12-30 thomas
92 45b9d1e9 2022-12-30 thomas echo "0004want $dummy_commit multi_ack side-band-64k ofs-delta" \
93 45b9d1e9 2022-12-30 thomas | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
94 45b9d1e9 2022-12-30 thomas > $testroot/stdout 2>$testroot/stderr
95 581fa623 2022-12-30 thomas
96 45b9d1e9 2022-12-30 thomas printf "00000008NAK\n0021ERR read: Bad file descriptor" \
97 581fa623 2022-12-30 thomas > $testroot/stdout.expected
98 581fa623 2022-12-30 thomas
99 581fa623 2022-12-30 thomas echo "gotsh: read: Bad file descriptor" > $testroot/stderr.expected
100 581fa623 2022-12-30 thomas
101 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout 0 108
102 581fa623 2022-12-30 thomas ret=$?
103 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
104 581fa623 2022-12-30 thomas echo "unexpected stdout" >&2
105 581fa623 2022-12-30 thomas test_done "$testroot" "1"
106 581fa623 2022-12-30 thomas return 1
107 581fa623 2022-12-30 thomas fi
108 581fa623 2022-12-30 thomas
109 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
110 581fa623 2022-12-30 thomas ret=$?
111 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
112 581fa623 2022-12-30 thomas echo "unexpected stderr" >&2
113 45b9d1e9 2022-12-30 thomas diff -u $testroot/stderr.expected $testroot/stderr
114 581fa623 2022-12-30 thomas test_done "$testroot" "1"
115 581fa623 2022-12-30 thomas return 1
116 581fa623 2022-12-30 thomas fi
117 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
118 581fa623 2022-12-30 thomas }
119 581fa623 2022-12-30 thomas
120 581fa623 2022-12-30 thomas # Pkt-len too small
121 581fa623 2022-12-30 thomas test_request_bad_length_small() {
122 581fa623 2022-12-30 thomas local testroot=`test_init test_request_bad_length_small`
123 581fa623 2022-12-30 thomas
124 45b9d1e9 2022-12-30 thomas echo "0002want $dummy_commit multi_ack side-band-64k ofs-delta" \
125 45b9d1e9 2022-12-30 thomas | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
126 45b9d1e9 2022-12-30 thomas > $testroot/stdout 2>$testroot/stderr
127 581fa623 2022-12-30 thomas
128 45b9d1e9 2022-12-30 thomas printf "00000008NAK\n0021ERR read: Bad file descriptor" \
129 581fa623 2022-12-30 thomas > $testroot/stdout.expected
130 581fa623 2022-12-30 thomas
131 581fa623 2022-12-30 thomas echo "gotsh: read: Bad file descriptor" > $testroot/stderr.expected
132 581fa623 2022-12-30 thomas
133 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout 0 108
134 581fa623 2022-12-30 thomas ret=$?
135 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
136 581fa623 2022-12-30 thomas echo "unexpected stdout" >&2
137 581fa623 2022-12-30 thomas test_done "$testroot" "1"
138 581fa623 2022-12-30 thomas return 1
139 581fa623 2022-12-30 thomas fi
140 581fa623 2022-12-30 thomas
141 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
142 581fa623 2022-12-30 thomas ret=$?
143 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
144 581fa623 2022-12-30 thomas echo "unexpected stderr" >&2
145 45b9d1e9 2022-12-30 thomas diff -u $testroot/stderr.expected $testroot/stderr
146 581fa623 2022-12-30 thomas test_done "$testroot" "1"
147 581fa623 2022-12-30 thomas return 1
148 581fa623 2022-12-30 thomas fi
149 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
150 581fa623 2022-12-30 thomas }
151 45b9d1e9 2022-12-30 thomas
152 581fa623 2022-12-30 thomas # Pkt-len too large
153 581fa623 2022-12-30 thomas test_request_bad_length_large() {
154 581fa623 2022-12-30 thomas local testroot=`test_init test_request_bad_length_large`
155 581fa623 2022-12-30 thomas
156 45b9d1e9 2022-12-30 thomas echo "ffffwant $dummy_commit multi_ack side-band-64k ofs-delta" \
157 45b9d1e9 2022-12-30 thomas | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
158 45b9d1e9 2022-12-30 thomas > $testroot/stdout 2>$testroot/stderr
159 581fa623 2022-12-30 thomas
160 45b9d1e9 2022-12-30 thomas printf "00000008NAK\n0021ERR read: Bad file descriptor" \
161 581fa623 2022-12-30 thomas > $testroot/stdout.expected
162 581fa623 2022-12-30 thomas
163 581fa623 2022-12-30 thomas echo "gotsh: read: Bad file descriptor" > $testroot/stderr.expected
164 581fa623 2022-12-30 thomas
165 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout 0 108
166 581fa623 2022-12-30 thomas ret=$?
167 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
168 581fa623 2022-12-30 thomas echo "unexpected stdout" >&2
169 581fa623 2022-12-30 thomas test_done "$testroot" "1"
170 581fa623 2022-12-30 thomas return 1
171 581fa623 2022-12-30 thomas fi
172 581fa623 2022-12-30 thomas
173 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
174 581fa623 2022-12-30 thomas ret=$?
175 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
176 581fa623 2022-12-30 thomas echo "unexpected stderr" >&2
177 45b9d1e9 2022-12-30 thomas diff -u $testroot/stderr.expected $testroot/stderr
178 581fa623 2022-12-30 thomas test_done "$testroot" "1"
179 581fa623 2022-12-30 thomas return 1
180 581fa623 2022-12-30 thomas fi
181 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
182 581fa623 2022-12-30 thomas }
183 581fa623 2022-12-30 thomas
184 581fa623 2022-12-30 thomas # Unknown feature
185 581fa623 2022-12-30 thomas test_request_bad_capabilities() {
186 581fa623 2022-12-30 thomas local testroot=`test_init test_request_bad_capabilities`
187 581fa623 2022-12-30 thomas
188 45b9d1e9 2022-12-30 thomas echo "0054want $dummy_commit aaaaaaaaa bbbbbbbbbbbbb ccccccccc" \
189 45b9d1e9 2022-12-30 thomas | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
190 45b9d1e9 2022-12-30 thomas > $testroot/stdout 2>$testroot/stderr
191 581fa623 2022-12-30 thomas
192 581fa623 2022-12-30 thomas echo -n "00000025ERR unexpected want-line received" \
193 581fa623 2022-12-30 thomas > $testroot/stdout.expected
194 581fa623 2022-12-30 thomas
195 581fa623 2022-12-30 thomas echo "gotsh: unexpected want-line received" > $testroot/stderr.expected
196 581fa623 2022-12-30 thomas
197 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout 0 108
198 581fa623 2022-12-30 thomas ret=$?
199 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
200 581fa623 2022-12-30 thomas echo "unexpected stdout" >&2
201 581fa623 2022-12-30 thomas test_done "$testroot" "1"
202 581fa623 2022-12-30 thomas return 1
203 581fa623 2022-12-30 thomas fi
204 581fa623 2022-12-30 thomas
205 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
206 581fa623 2022-12-30 thomas ret=$?
207 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
208 581fa623 2022-12-30 thomas echo "unexpected stderr" >&2
209 45b9d1e9 2022-12-30 thomas diff -u $testroot/stderr.expected $testroot/stderr
210 581fa623 2022-12-30 thomas test_done "$testroot" "1"
211 581fa623 2022-12-30 thomas return 1
212 581fa623 2022-12-30 thomas fi
213 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
214 581fa623 2022-12-30 thomas }
215 581fa623 2022-12-30 thomas
216 581fa623 2022-12-30 thomas # Unknown repository
217 581fa623 2022-12-30 thomas test_request_bad_repository() {
218 581fa623 2022-12-30 thomas local testroot=`test_init test_request_bad_repository`
219 581fa623 2022-12-30 thomas
220 45b9d1e9 2022-12-30 thomas echo "0054want $dummy_commit aaaaaaaaa bbbbbbbbbbbbb ccccccccc" \
221 45b9d1e9 2022-12-30 thomas | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/XXXX-XXXX' \
222 45b9d1e9 2022-12-30 thomas > $testroot/stdout 2>$testroot/stderr
223 581fa623 2022-12-30 thomas
224 581fa623 2022-12-30 thomas echo -n "001fERR no git repository found" > $testroot/stdout.expected
225 581fa623 2022-12-30 thomas
226 581fa623 2022-12-30 thomas echo "gotsh: no git repository found" > $testroot/stderr.expected
227 581fa623 2022-12-30 thomas
228 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout
229 581fa623 2022-12-30 thomas ret=$?
230 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
231 581fa623 2022-12-30 thomas echo "unexpected stdout" >&2
232 581fa623 2022-12-30 thomas test_done "$testroot" "1"
233 581fa623 2022-12-30 thomas return 1
234 581fa623 2022-12-30 thomas fi
235 581fa623 2022-12-30 thomas
236 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
237 581fa623 2022-12-30 thomas ret=$?
238 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
239 581fa623 2022-12-30 thomas echo "unexpected stderr" >&2
240 45b9d1e9 2022-12-30 thomas diff -u $testroot/stderr.expected $testroot/stderr
241 581fa623 2022-12-30 thomas test_done "$testroot" "1"
242 581fa623 2022-12-30 thomas return 1
243 581fa623 2022-12-30 thomas fi
244 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
245 581fa623 2022-12-30 thomas
246 581fa623 2022-12-30 thomas }
247 581fa623 2022-12-30 thomas
248 581fa623 2022-12-30 thomas # Repository with name of 255 symbols
249 581fa623 2022-12-30 thomas test_request_bad_large_repo_name() {
250 581fa623 2022-12-30 thomas local testroot=`test_init test_request_bad_large_repo_name`
251 581fa623 2022-12-30 thomas
252 45b9d1e9 2022-12-30 thomas # build a string of 255 "A": 63 "A" four times plus tree more "A"
253 45b9d1e9 2022-12-30 thomas local a=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
254 45b9d1e9 2022-12-30 thomas local repo_name="AAA$a$a$a$a"
255 581fa623 2022-12-30 thomas
256 45b9d1e9 2022-12-30 thomas echo "0054want $dummy_commit aaaaaaaaa bbbbbbbbbbbbb ccccccccc" \
257 45b9d1e9 2022-12-30 thomas | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack "/$repo_name" \
258 45b9d1e9 2022-12-30 thomas > $testroot/stdout 2>$testroot/stderr
259 45b9d1e9 2022-12-30 thomas
260 581fa623 2022-12-30 thomas echo -n "0018ERR buffer too small" > $testroot/stdout.expected
261 581fa623 2022-12-30 thomas
262 581fa623 2022-12-30 thomas echo "gotsh: buffer too small" > $testroot/stderr.expected
263 581fa623 2022-12-30 thomas
264 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout
265 581fa623 2022-12-30 thomas ret=$?
266 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
267 581fa623 2022-12-30 thomas echo "unexpected stdout" >&2
268 581fa623 2022-12-30 thomas test_done "$testroot" "1"
269 581fa623 2022-12-30 thomas return 1
270 581fa623 2022-12-30 thomas fi
271 581fa623 2022-12-30 thomas
272 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
273 581fa623 2022-12-30 thomas ret=$?
274 581fa623 2022-12-30 thomas if [ $ret -ne 0 ]; then
275 581fa623 2022-12-30 thomas echo "unexpected stderr" >&2
276 45b9d1e9 2022-12-30 thomas diff -u $testroot/stderr.expected $testroot/stderr
277 581fa623 2022-12-30 thomas test_done "$testroot" "1"
278 581fa623 2022-12-30 thomas return 1
279 581fa623 2022-12-30 thomas fi
280 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
281 581fa623 2022-12-30 thomas }
282 45b9d1e9 2022-12-30 thomas
283 581fa623 2022-12-30 thomas test_parseargs "$@"
284 581fa623 2022-12-30 thomas run_test test_request_bad_commit
285 581fa623 2022-12-30 thomas run_test test_request_bad_length_zero
286 581fa623 2022-12-30 thomas run_test test_request_bad_length_empty
287 581fa623 2022-12-30 thomas run_test test_request_bad_length_small
288 581fa623 2022-12-30 thomas run_test test_request_bad_length_large
289 581fa623 2022-12-30 thomas run_test test_request_bad_capabilities
290 581fa623 2022-12-30 thomas run_test test_request_bad_repository
291 581fa623 2022-12-30 thomas run_test test_request_bad_large_repo_name