3 # Copyright (c) 2022 Mikhail Pchelin <misha@freebsd.org>
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.
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
20 dummy_commit="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
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
38 if [ $ret -ne 0 ]; then
39 echo "unexpected stdout" >&2
40 test_done "$testroot" "1"
44 cmp -s $testroot/stderr.expected $testroot/stderr
46 if [ $ret -ne 0 ]; then
47 echo "unexpected stderr" >&2
48 diff -u $testroot/stderr.expected $testroot/stderr
49 test_done "$testroot" "1"
52 test_done "$testroot" "$ret"
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
71 if [ $ret -ne 0 ]; then
72 echo "unexpected stdout" >&2
73 test_done "$testroot" "1"
77 cmp -s $testroot/stderr $testroot/stderr.expected
79 if [ $ret -ne 0 ]; then
80 echo "unexpected stderr" >&2
81 diff -u $testroot/stderr.expected $testroot/stderr
82 test_done "$testroot" "1"
85 test_done "$testroot" "$ret"
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
107 if [ $ret -ne 0 ]; then
108 echo "unexpected stdout" >&2
109 test_done "$testroot" "1"
113 cmp -s $testroot/stderr.expected $testroot/stderr
115 if [ $ret -ne 0 ]; then
116 echo "unexpected stderr" >&2
117 diff -u $testroot/stderr.expected $testroot/stderr
118 test_done "$testroot" "1"
121 test_done "$testroot" "$ret"
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
143 if [ $ret -ne 0 ]; then
144 echo "unexpected stdout" >&2
145 test_done "$testroot" "1"
149 cmp -s $testroot/stderr.expected $testroot/stderr
151 if [ $ret -ne 0 ]; then
152 echo "unexpected stderr" >&2
153 diff -u $testroot/stderr.expected $testroot/stderr
154 test_done "$testroot" "1"
157 test_done "$testroot" "$ret"
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
180 if [ $ret -ne 0 ]; then
181 echo "unexpected stdout" >&2
182 test_done "$testroot" "1"
186 cmp -s $testroot/stderr.expected $testroot/stderr
188 if [ $ret -ne 0 ]; then
189 echo "unexpected stderr" >&2
190 diff -u $testroot/stderr.expected $testroot/stderr
191 test_done "$testroot" "1"
194 test_done "$testroot" "$ret"
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
212 if [ $ret -ne 0 ]; then
213 echo "unexpected stdout" >&2
214 test_done "$testroot" "1"
218 cmp -s $testroot/stderr.expected $testroot/stderr
220 if [ $ret -ne 0 ]; then
221 echo "unexpected stderr" >&2
222 diff -u $testroot/stderr.expected $testroot/stderr
223 test_done "$testroot" "1"
226 test_done "$testroot" "$ret"
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
243 if [ $ret -ne 0 ]; then
244 echo "unexpected stdout" >&2
245 test_done "$testroot" "1"
249 cmp -s $testroot/stderr.expected $testroot/stderr
251 if [ $ret -ne 0 ]; then
252 echo "unexpected stderr" >&2
253 diff -u $testroot/stderr.expected $testroot/stderr
254 test_done "$testroot" "1"
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
279 if [ $ret -ne 0 ]; then
280 echo "unexpected stdout" >&2
281 test_done "$testroot" "1"
285 cmp -s $testroot/stderr.expected $testroot/stderr
287 if [ $ret -ne 0 ]; then
288 echo "unexpected stderr" >&2
289 diff -u $testroot/stderr.expected $testroot/stderr
290 test_done "$testroot" "1"
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
304 # should still be able to clone; the repo is empty however
305 got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone \
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
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
319 test_done "$testroot" 0
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