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 printf "00000008NAK\n0021ERR read: Bad file descriptor" \
97 > $testroot/stdout.expected
99 echo "gotsh: read: Bad file descriptor" > $testroot/stderr.expected
101 cmp -s $testroot/stdout.expected $testroot/stdout 0 108
102 ret=$?
103 if [ $ret -ne 0 ]; then
104 echo "unexpected stdout" >&2
105 test_done "$testroot" "1"
106 return 1
107 fi
109 cmp -s $testroot/stderr.expected $testroot/stderr
110 ret=$?
111 if [ $ret -ne 0 ]; then
112 echo "unexpected stderr" >&2
113 diff -u $testroot/stderr.expected $testroot/stderr
114 test_done "$testroot" "1"
115 return 1
116 fi
117 test_done "$testroot" "$ret"
120 # Pkt-len too small
121 test_request_bad_length_small() {
122 local testroot=`test_init test_request_bad_length_small`
124 echo "0002want $dummy_commit multi_ack side-band-64k ofs-delta" \
125 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
126 > $testroot/stdout 2>$testroot/stderr
128 printf "00000008NAK\n0021ERR read: Bad file descriptor" \
129 > $testroot/stdout.expected
131 echo "gotsh: read: Bad file descriptor" > $testroot/stderr.expected
133 cmp -s $testroot/stdout.expected $testroot/stdout 0 108
134 ret=$?
135 if [ $ret -ne 0 ]; then
136 echo "unexpected stdout" >&2
137 test_done "$testroot" "1"
138 return 1
139 fi
141 cmp -s $testroot/stderr.expected $testroot/stderr
142 ret=$?
143 if [ $ret -ne 0 ]; then
144 echo "unexpected stderr" >&2
145 diff -u $testroot/stderr.expected $testroot/stderr
146 test_done "$testroot" "1"
147 return 1
148 fi
149 test_done "$testroot" "$ret"
152 # Pkt-len too large
153 test_request_bad_length_large() {
154 local testroot=`test_init test_request_bad_length_large`
156 echo "ffffwant $dummy_commit multi_ack side-band-64k ofs-delta" \
157 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
158 > $testroot/stdout 2>$testroot/stderr
160 printf "00000008NAK\n0021ERR read: Bad file descriptor" \
161 > $testroot/stdout.expected
163 echo "gotsh: read: Bad file descriptor" > $testroot/stderr.expected
165 cmp -s $testroot/stdout.expected $testroot/stdout 0 108
166 ret=$?
167 if [ $ret -ne 0 ]; then
168 echo "unexpected stdout" >&2
169 test_done "$testroot" "1"
170 return 1
171 fi
173 cmp -s $testroot/stderr.expected $testroot/stderr
174 ret=$?
175 if [ $ret -ne 0 ]; then
176 echo "unexpected stderr" >&2
177 diff -u $testroot/stderr.expected $testroot/stderr
178 test_done "$testroot" "1"
179 return 1
180 fi
181 test_done "$testroot" "$ret"
184 # Unknown feature
185 test_request_bad_capabilities() {
186 local testroot=`test_init test_request_bad_capabilities`
188 echo "0054want $dummy_commit aaaaaaaaa bbbbbbbbbbbbb ccccccccc" \
189 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/test-repo' \
190 > $testroot/stdout 2>$testroot/stderr
192 echo -n "00000025ERR unexpected want-line received" \
193 > $testroot/stdout.expected
195 echo "gotsh: unexpected want-line received" > $testroot/stderr.expected
197 cmp -s $testroot/stdout.expected $testroot/stdout 0 108
198 ret=$?
199 if [ $ret -ne 0 ]; then
200 echo "unexpected stdout" >&2
201 test_done "$testroot" "1"
202 return 1
203 fi
205 cmp -s $testroot/stderr.expected $testroot/stderr
206 ret=$?
207 if [ $ret -ne 0 ]; then
208 echo "unexpected stderr" >&2
209 diff -u $testroot/stderr.expected $testroot/stderr
210 test_done "$testroot" "1"
211 return 1
212 fi
213 test_done "$testroot" "$ret"
216 # Unknown repository
217 test_request_bad_repository() {
218 local testroot=`test_init test_request_bad_repository`
220 echo "0054want $dummy_commit aaaaaaaaa bbbbbbbbbbbbb ccccccccc" \
221 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack '/XXXX-XXXX' \
222 > $testroot/stdout 2>$testroot/stderr
224 echo -n "001fERR no git repository found" > $testroot/stdout.expected
226 echo "gotsh: no git repository found" > $testroot/stderr.expected
228 cmp -s $testroot/stdout.expected $testroot/stdout
229 ret=$?
230 if [ $ret -ne 0 ]; then
231 echo "unexpected stdout" >&2
232 test_done "$testroot" "1"
233 return 1
234 fi
236 cmp -s $testroot/stderr.expected $testroot/stderr
237 ret=$?
238 if [ $ret -ne 0 ]; then
239 echo "unexpected stderr" >&2
240 diff -u $testroot/stderr.expected $testroot/stderr
241 test_done "$testroot" "1"
242 return 1
243 fi
244 test_done "$testroot" "$ret"
248 # Repository with name of 255 symbols
249 test_request_bad_large_repo_name() {
250 local testroot=`test_init test_request_bad_large_repo_name`
252 # build a string of 255 "A": 63 "A" four times plus tree more "A"
253 local a=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
254 local repo_name="AAA$a$a$a$a"
256 echo "0054want $dummy_commit aaaaaaaaa bbbbbbbbbbbbb ccccccccc" \
257 | ssh ${GOTD_DEVUSER}@127.0.0.1 git-upload-pack "/$repo_name" \
258 > $testroot/stdout 2>$testroot/stderr
260 echo -n "0018ERR buffer too small" > $testroot/stdout.expected
262 echo "gotsh: buffer too small" > $testroot/stderr.expected
264 cmp -s $testroot/stdout.expected $testroot/stdout
265 ret=$?
266 if [ $ret -ne 0 ]; then
267 echo "unexpected stdout" >&2
268 test_done "$testroot" "1"
269 return 1
270 fi
272 cmp -s $testroot/stderr.expected $testroot/stderr
273 ret=$?
274 if [ $ret -ne 0 ]; then
275 echo "unexpected stderr" >&2
276 diff -u $testroot/stderr.expected $testroot/stderr
277 test_done "$testroot" "1"
278 return 1
279 fi
280 test_done "$testroot" "$ret"
283 test_parseargs "$@"
284 run_test test_request_bad_commit
285 run_test test_request_bad_length_zero
286 run_test test_request_bad_length_empty
287 run_test test_request_bad_length_small
288 run_test test_request_bad_length_large
289 run_test test_request_bad_capabilities
290 run_test test_request_bad_repository
291 run_test test_request_bad_large_repo_name