Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2022 Mikhail Pchelin <misha@freebsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ../cmdline/common.sh
18 . ./common.sh
20 dummy_commit="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
22 # Non-existent commit
23 test_request_bad_commit() {
24 local testroot=`test_init request_bad_commit`
26 echo "0054want $dummy_commit multi_ack side-band-64k ofs-delta" \
27 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
28 > $testroot/stdout 2>$testroot/stderr
30 echo -n "0041ERR object $dummy_commit not found" \
31 > $testroot/stdout.expected
33 echo "gotsh: object $dummy_commit not found" \
34 > $testroot/stderr.expected
36 cmp -s $testroot/stdout.expected $testroot/stdout 0 112
37 ret=$?
38 if [ $ret -ne 0 ]; then
39 echo "unexpected stdout" >&2
40 test_done "$testroot" "1"
41 return 1
42 fi
44 cmp -s $testroot/stderr.expected $testroot/stderr
45 ret=$?
46 if [ $ret -ne 0 ]; then
47 echo "unexpected stderr" >&2
48 diff -u $testroot/stderr.expected $testroot/stderr
49 test_done "$testroot" "1"
50 return 1
51 fi
52 test_done "$testroot" "$ret"
53 }
55 # Zero pkt-len (as flush packet with payload)
56 test_request_bad_length_zero() {
57 local testroot=`test_init test_request_bad_length_zero`
59 echo "0000want $dummy_commit multi_ack side-band-64k ofs-delta" \
60 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
61 > $testroot/stdout 2>$testroot/stderr
63 echo -n "00000028ERR unexpected flush packet received" \
64 > $testroot/stdout.expected
66 echo "gotsh: unexpected flush packet received" \
67 > $testroot/stderr.expected
69 cmp -s $testroot/stdout.expected $testroot/stdout 0 108
70 ret=$?
71 if [ $ret -ne 0 ]; then
72 echo "unexpected stdout" >&2
73 test_done "$testroot" "1"
74 return 1
75 fi
77 cmp -s $testroot/stderr $testroot/stderr.expected
78 ret=$?
79 if [ $ret -ne 0 ]; then
80 echo "unexpected stderr" >&2
81 diff -u $testroot/stderr.expected $testroot/stderr
82 test_done "$testroot" "1"
83 return 1
84 fi
85 test_done "$testroot" "$ret"
86 }
88 # 0004 (empty)
89 test_request_bad_length_empty() {
90 local testroot=`test_init test_request_bad_length_empty`
92 echo "0004want $dummy_commit multi_ack side-band-64k ofs-delta" \
93 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
94 > $testroot/stdout 2>$testroot/stderr
96 echo -n '006c0000000000000000000000000000000000000000 ' \
97 > $testroot/stdout.expected
98 printf "capabilities^{}\0" >> $testroot/stdout.expected
99 echo -n " agent=got/${GOT_VERSION_STR} ofs-delta side-band-64k" \
100 >> $testroot/stdout.expected
101 echo -n '00000018ERR packet too short' >> $testroot/stdout.expected
103 echo "gotsh: packet too short" > $testroot/stderr.expected
105 cmp -s $testroot/stdout.expected $testroot/stdout
106 ret=$?
107 if [ $ret -ne 0 ]; then
108 echo "unexpected stdout" >&2
109 test_done "$testroot" "1"
110 return 1
111 fi
113 cmp -s $testroot/stderr.expected $testroot/stderr
114 ret=$?
115 if [ $ret -ne 0 ]; then
116 echo "unexpected stderr" >&2
117 diff -u $testroot/stderr.expected $testroot/stderr
118 test_done "$testroot" "1"
119 return 1
120 fi
121 test_done "$testroot" "$ret"
124 # Pkt-len too small
125 test_request_bad_length_small() {
126 local testroot=`test_init test_request_bad_length_small`
128 echo "0002want $dummy_commit multi_ack side-band-64k ofs-delta" \
129 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
130 > $testroot/stdout 2>$testroot/stderr
132 echo -n '006c0000000000000000000000000000000000000000 ' \
133 > $testroot/stdout.expected
134 printf "capabilities^{}\0" >> $testroot/stdout.expected
135 echo -n " agent=got/${GOT_VERSION_STR} ofs-delta side-band-64k" \
136 >> $testroot/stdout.expected
137 echo -n '00000018ERR packet too short' >> $testroot/stdout.expected
139 echo "gotsh: packet too short" > $testroot/stderr.expected
141 cmp -s $testroot/stdout.expected $testroot/stdout
142 ret=$?
143 if [ $ret -ne 0 ]; then
144 echo "unexpected stdout" >&2
145 test_done "$testroot" "1"
146 return 1
147 fi
149 cmp -s $testroot/stderr.expected $testroot/stderr
150 ret=$?
151 if [ $ret -ne 0 ]; then
152 echo "unexpected stderr" >&2
153 diff -u $testroot/stderr.expected $testroot/stderr
154 test_done "$testroot" "1"
155 return 1
156 fi
157 test_done "$testroot" "$ret"
160 # Pkt-len too large
161 test_request_bad_length_large() {
162 local testroot=`test_init test_request_bad_length_large`
164 echo "ffffwant $dummy_commit multi_ack side-band-64k ofs-delta" \
165 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
166 > $testroot/stdout 2>$testroot/stderr
168 echo -n '006c0000000000000000000000000000000000000000 ' \
169 > $testroot/stdout.expected
170 printf "capabilities^{}\0" >> $testroot/stdout.expected
171 echo -n " agent=got/${GOT_VERSION_STR} ofs-delta side-band-64k" \
172 >> $testroot/stdout.expected
173 echo -n '0000001eERR unexpected end of file' \
174 >> $testroot/stdout.expected
176 echo "gotsh: unexpected end of file" > $testroot/stderr.expected
178 cmp -s $testroot/stdout.expected $testroot/stdout
179 ret=$?
180 if [ $ret -ne 0 ]; then
181 echo "unexpected stdout" >&2
182 test_done "$testroot" "1"
183 return 1
184 fi
186 cmp -s $testroot/stderr.expected $testroot/stderr
187 ret=$?
188 if [ $ret -ne 0 ]; then
189 echo "unexpected stderr" >&2
190 diff -u $testroot/stderr.expected $testroot/stderr
191 test_done "$testroot" "1"
192 return 1
193 fi
194 test_done "$testroot" "$ret"
197 # Unknown feature
198 test_request_bad_capabilities() {
199 local testroot=`test_init test_request_bad_capabilities`
201 echo "0054want $dummy_commit aaaaaaaaa bbbbbbbbbbbbb ccccccccc" \
202 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
203 > $testroot/stdout 2>$testroot/stderr
205 echo -n "00000025ERR unexpected want-line received" \
206 > $testroot/stdout.expected
208 echo "gotsh: unexpected want-line received" > $testroot/stderr.expected
210 cmp -s $testroot/stdout.expected $testroot/stdout 0 108
211 ret=$?
212 if [ $ret -ne 0 ]; then
213 echo "unexpected stdout" >&2
214 test_done "$testroot" "1"
215 return 1
216 fi
218 cmp -s $testroot/stderr.expected $testroot/stderr
219 ret=$?
220 if [ $ret -ne 0 ]; then
221 echo "unexpected stderr" >&2
222 diff -u $testroot/stderr.expected $testroot/stderr
223 test_done "$testroot" "1"
224 return 1
225 fi
226 test_done "$testroot" "$ret"
229 # Unknown repository
230 test_request_bad_repository() {
231 local testroot=`test_init test_request_bad_repository`
233 echo "0054want $dummy_commit aaaaaaaaa bbbbbbbbbbbbb ccccccccc" \
234 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/XXXX-XXXX' \
235 > $testroot/stdout 2>$testroot/stderr
237 echo -n "001fERR no git repository found" > $testroot/stdout.expected
239 echo "gotsh: no git repository found" > $testroot/stderr.expected
241 cmp -s $testroot/stdout.expected $testroot/stdout
242 ret=$?
243 if [ $ret -ne 0 ]; then
244 echo "unexpected stdout" >&2
245 test_done "$testroot" "1"
246 return 1
247 fi
249 cmp -s $testroot/stderr.expected $testroot/stderr
250 ret=$?
251 if [ $ret -ne 0 ]; then
252 echo "unexpected stderr" >&2
253 diff -u $testroot/stderr.expected $testroot/stderr
254 test_done "$testroot" "1"
255 return 1
256 fi
257 test_done "$testroot" "$ret"
261 # Repository with name of 255 symbols
262 test_request_bad_large_repo_name() {
263 local testroot=`test_init test_request_bad_large_repo_name`
265 # build a string of 255 "A": 63 "A" four times plus tree more "A"
266 local a=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
267 local repo_name="AAA$a$a$a$a"
269 echo "0054want $dummy_commit aaaaaaaaa bbbbbbbbbbbbb ccccccccc" \
270 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack "/$repo_name" \
271 > $testroot/stdout 2>$testroot/stderr
273 echo -n "0018ERR buffer too small" > $testroot/stdout.expected
275 echo "gotsh: buffer too small" > $testroot/stderr.expected
277 cmp -s $testroot/stdout.expected $testroot/stdout
278 ret=$?
279 if [ $ret -ne 0 ]; then
280 echo "unexpected stdout" >&2
281 test_done "$testroot" "1"
282 return 1
283 fi
285 cmp -s $testroot/stderr.expected $testroot/stderr
286 ret=$?
287 if [ $ret -ne 0 ]; then
288 echo "unexpected stderr" >&2
289 diff -u $testroot/stderr.expected $testroot/stderr
290 test_done "$testroot" "1"
291 return 1
292 fi
293 test_done "$testroot" "$ret"
296 test_request_bad_no_repo() {
297 local testroot=`test_init test_request_bad_no_repo`
299 for i in `seq 10`; do
300 ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack \
301 >/dev/null 2>/dev/null </dev/null
302 done
304 # should still be able to clone; the repo is empty however
305 got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone \
306 2> $testroot/stderr
307 cat <<EOF > $testroot/stderr.expected
308 got-fetch-pack: could not find any branches to fetch
309 got: could not find any branches to fetch
310 EOF
312 if ! cmp -s "$testroot/stderr.expected" "$testroot/stderr"; then
313 echo "got clone failed for unexpected reason" >&2
314 diff -u "$testroot/stderr.expected" "$testroot/stderr"
315 test_done "$testroot" 1
316 return
317 fi
319 test_done "$testroot" 0
322 test_parseargs "$@"
323 run_test test_request_bad_commit
324 run_test test_request_bad_length_zero
325 run_test test_request_bad_length_empty
326 run_test test_request_bad_length_small
327 run_test test_request_bad_length_large
328 run_test test_request_bad_capabilities
329 run_test test_request_bad_repository
330 run_test test_request_bad_large_repo_name
331 run_test test_request_bad_no_repo