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 # Replace embedded NUL from Git protocol with \n and then strip
31 # off the initial capabilities advertisement header.
32 tr '\0' '\n' < $testroot/stdout | tail -n 1 > $testroot/stdout.filtered
34 echo -n " agent=got/${GOT_VERSION_STR} ofs-delta side-band-64k0000" \
35 > $testroot/stdout.expected
36 echo -n "0041ERR object $dummy_commit not found" \
37 >> $testroot/stdout.expected
39 echo "gotsh: object $dummy_commit not found" \
40 > $testroot/stderr.expected
42 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
43 ret=$?
44 if [ $ret -ne 0 ]; then
45 echo "unexpected stdout" >&2
46 test_done "$testroot" "1"
47 return 1
48 fi
50 cmp -s $testroot/stderr.expected $testroot/stderr
51 ret=$?
52 if [ $ret -ne 0 ]; then
53 echo "unexpected stderr" >&2
54 diff -u $testroot/stderr.expected $testroot/stderr
55 test_done "$testroot" "1"
56 return 1
57 fi
58 test_done "$testroot" "$ret"
59 }
61 # Zero pkt-len (as flush packet with payload)
62 test_request_bad_length_zero() {
63 local testroot=`test_init request_bad_length_zero`
65 echo "0000want $dummy_commit multi_ack side-band-64k ofs-delta" \
66 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
67 > $testroot/stdout 2>$testroot/stderr
69 tr '\0' '\n' < $testroot/stdout | tail -n 1 > $testroot/stdout.filtered
71 echo -n " agent=got/${GOT_VERSION_STR} ofs-delta side-band-64k0000" \
72 > $testroot/stdout.expected
73 echo -n "0028ERR unexpected flush packet received" \
74 >> $testroot/stdout.expected
76 echo "gotsh: unexpected flush packet received" \
77 > $testroot/stderr.expected
79 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
80 ret=$?
81 if [ $ret -ne 0 ]; then
82 echo "unexpected stdout" >&2
83 test_done "$testroot" "1"
84 return 1
85 fi
87 cmp -s $testroot/stderr $testroot/stderr.expected
88 ret=$?
89 if [ $ret -ne 0 ]; then
90 echo "unexpected stderr" >&2
91 diff -u $testroot/stderr.expected $testroot/stderr
92 test_done "$testroot" "1"
93 return 1
94 fi
95 test_done "$testroot" "$ret"
96 }
98 # 0004 (empty)
99 test_request_bad_length_empty() {
100 local testroot=`test_init request_bad_length_empty`
102 echo "0004want $dummy_commit multi_ack side-band-64k ofs-delta" \
103 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
104 > $testroot/stdout 2>$testroot/stderr
106 tr '\0' '\n' < $testroot/stdout | tail -n 1 > $testroot/stdout.filtered
108 echo -n " agent=got/${GOT_VERSION_STR} ofs-delta side-band-64k0000" \
109 > $testroot/stdout.expected
110 echo -n '0018ERR packet too short' >> $testroot/stdout.expected
112 echo "gotsh: packet too short" > $testroot/stderr.expected
114 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
115 ret=$?
116 if [ $ret -ne 0 ]; then
117 echo "unexpected stdout" >&2
118 test_done "$testroot" "1"
119 return 1
120 fi
122 cmp -s $testroot/stderr.expected $testroot/stderr
123 ret=$?
124 if [ $ret -ne 0 ]; then
125 echo "unexpected stderr" >&2
126 diff -u $testroot/stderr.expected $testroot/stderr
127 test_done "$testroot" "1"
128 return 1
129 fi
130 test_done "$testroot" "$ret"
133 # Pkt-len too small
134 test_request_bad_length_small() {
135 local testroot=`test_init request_bad_length_small`
137 echo "0002want $dummy_commit multi_ack side-band-64k ofs-delta" \
138 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
139 > $testroot/stdout 2>$testroot/stderr
141 tr '\0' '\n' < $testroot/stdout | tail -n 1 > $testroot/stdout.filtered
143 echo -n " agent=got/${GOT_VERSION_STR} ofs-delta side-band-64k0000" \
144 > $testroot/stdout.expected
145 echo -n '0018ERR packet too short' >> $testroot/stdout.expected
147 echo "gotsh: packet too short" > $testroot/stderr.expected
149 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
150 ret=$?
151 if [ $ret -ne 0 ]; then
152 echo "unexpected stdout" >&2
153 test_done "$testroot" "1"
154 return 1
155 fi
157 cmp -s $testroot/stderr.expected $testroot/stderr
158 ret=$?
159 if [ $ret -ne 0 ]; then
160 echo "unexpected stderr" >&2
161 diff -u $testroot/stderr.expected $testroot/stderr
162 test_done "$testroot" "1"
163 return 1
164 fi
165 test_done "$testroot" "$ret"
168 # Pkt-len too large
169 test_request_bad_length_large() {
170 local testroot=`test_init request_bad_length_large`
172 echo "ffffwant $dummy_commit multi_ack side-band-64k ofs-delta" \
173 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
174 > $testroot/stdout 2>$testroot/stderr
176 tr '\0' '\n' < $testroot/stdout | tail -n 1 > $testroot/stdout.filtered
178 echo -n " agent=got/${GOT_VERSION_STR} ofs-delta side-band-64k0000" \
179 > $testroot/stdout.expected
180 echo -n '001eERR unexpected end of file' \
181 >> $testroot/stdout.expected
183 echo "gotsh: unexpected end of file" > $testroot/stderr.expected
185 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
186 ret=$?
187 if [ $ret -ne 0 ]; then
188 echo "unexpected stdout" >&2
189 test_done "$testroot" "1"
190 return 1
191 fi
193 cmp -s $testroot/stderr.expected $testroot/stderr
194 ret=$?
195 if [ $ret -ne 0 ]; then
196 echo "unexpected stderr" >&2
197 diff -u $testroot/stderr.expected $testroot/stderr
198 test_done "$testroot" "1"
199 return 1
200 fi
201 test_done "$testroot" "$ret"
204 # Unknown feature
205 test_request_bad_capabilities() {
206 local testroot=`test_init request_bad_capabilities`
208 echo "0054want $dummy_commit aaaaaaaaa bbbbbbbbbbbbb ccccccccc" \
209 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
210 > $testroot/stdout 2>$testroot/stderr
212 tr '\0' '\n' < $testroot/stdout | tail -n 1 > $testroot/stdout.filtered
214 echo -n " agent=got/${GOT_VERSION_STR} ofs-delta side-band-64k0000" \
215 > $testroot/stdout.expected
216 echo -n "0025ERR unexpected want-line received" \
217 >> $testroot/stdout.expected
219 echo "gotsh: unexpected want-line received" > $testroot/stderr.expected
221 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
222 ret=$?
223 if [ $ret -ne 0 ]; then
224 echo "unexpected stdout" >&2
225 test_done "$testroot" "1"
226 return 1
227 fi
229 cmp -s $testroot/stderr.expected $testroot/stderr
230 ret=$?
231 if [ $ret -ne 0 ]; then
232 echo "unexpected stderr" >&2
233 diff -u $testroot/stderr.expected $testroot/stderr
234 test_done "$testroot" "1"
235 return 1
236 fi
237 test_done "$testroot" "$ret"
240 # Unknown repository
241 test_request_bad_repository() {
242 local testroot=`test_init request_bad_repository`
244 echo "0054want $dummy_commit aaaaaaaaa bbbbbbbbbbbbb ccccccccc" \
245 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/XXXX-XXXX' \
246 > $testroot/stdout 2>$testroot/stderr
248 echo -n "001fERR no git repository found" > $testroot/stdout.expected
250 echo "gotsh: no git repository found" > $testroot/stderr.expected
252 cmp -s $testroot/stdout.expected $testroot/stdout
253 ret=$?
254 if [ $ret -ne 0 ]; then
255 echo "unexpected stdout" >&2
256 test_done "$testroot" "1"
257 return 1
258 fi
260 cmp -s $testroot/stderr.expected $testroot/stderr
261 ret=$?
262 if [ $ret -ne 0 ]; then
263 echo "unexpected stderr" >&2
264 diff -u $testroot/stderr.expected $testroot/stderr
265 test_done "$testroot" "1"
266 return 1
267 fi
268 test_done "$testroot" "$ret"
272 # Repository with name of 255 symbols
273 test_request_bad_large_repo_name() {
274 local testroot=`test_init request_bad_large_repo_name`
276 # build a string of 255 "A": 63 "A" four times plus tree more "A"
277 local a=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
278 local repo_name="AAA$a$a$a$a"
280 echo "0054want $dummy_commit aaaaaaaaa bbbbbbbbbbbbb ccccccccc" \
281 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack "/$repo_name" \
282 > $testroot/stdout 2>$testroot/stderr
284 echo -n "0018ERR buffer too small" > $testroot/stdout.expected
286 echo "gotsh: buffer too small" > $testroot/stderr.expected
288 cmp -s $testroot/stdout.expected $testroot/stdout
289 ret=$?
290 if [ $ret -ne 0 ]; then
291 echo "unexpected stdout" >&2
292 test_done "$testroot" "1"
293 return 1
294 fi
296 cmp -s $testroot/stderr.expected $testroot/stderr
297 ret=$?
298 if [ $ret -ne 0 ]; then
299 echo "unexpected stderr" >&2
300 diff -u $testroot/stderr.expected $testroot/stderr
301 test_done "$testroot" "1"
302 return 1
303 fi
304 test_done "$testroot" "$ret"
307 test_request_bad_no_repo() {
308 local testroot=`test_init request_bad_no_repo`
310 for i in `seq 10`; do
311 ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack \
312 >/dev/null 2>/dev/null </dev/null
313 done
315 # should still be able to clone; the repo is empty however
316 got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone \
317 2> $testroot/stderr
318 cat <<EOF > $testroot/stderr.expected
319 got-fetch-pack: could not find any branches to fetch
320 got: could not find any branches to fetch
321 EOF
323 if ! cmp -s "$testroot/stderr.expected" "$testroot/stderr"; then
324 echo "got clone failed for unexpected reason" >&2
325 diff -u "$testroot/stderr.expected" "$testroot/stderr"
326 test_done "$testroot" 1
327 return
328 fi
330 test_done "$testroot" 0
333 test_parseargs "$@"
334 run_test test_request_bad_commit
335 run_test test_request_bad_length_zero
336 run_test test_request_bad_length_empty
337 run_test test_request_bad_length_small
338 run_test test_request_bad_length_large
339 run_test test_request_bad_capabilities
340 run_test test_request_bad_repository
341 run_test test_request_bad_large_repo_name
342 run_test test_request_bad_no_repo