3 581fa623 2022-12-30 thomas # Copyright (c) 2022 Mikhail Pchelin <misha@freebsd.org>
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.
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.
17 581fa623 2022-12-30 thomas . ../cmdline/common.sh
18 581fa623 2022-12-30 thomas . ./common.sh
20 45b9d1e9 2022-12-30 thomas dummy_commit="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
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`
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
30 45b9d1e9 2022-12-30 thomas echo -n "0041ERR object $dummy_commit not found" \
31 45b9d1e9 2022-12-30 thomas > $testroot/stdout.expected
33 45b9d1e9 2022-12-30 thomas echo "gotsh: object $dummy_commit not found" \
34 45b9d1e9 2022-12-30 thomas > $testroot/stderr.expected
36 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout 0 112
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"
44 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
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"
52 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
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`
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
63 581fa623 2022-12-30 thomas echo -n "00000028ERR unexpected flush packet received" \
64 581fa623 2022-12-30 thomas > $testroot/stdout.expected
66 581fa623 2022-12-30 thomas echo "gotsh: unexpected flush packet received" \
67 581fa623 2022-12-30 thomas > $testroot/stderr.expected
69 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout 0 108
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"
77 581fa623 2022-12-30 thomas cmp -s $testroot/stderr $testroot/stderr.expected
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"
85 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
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`
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
96 45b9d1e9 2022-12-30 thomas printf "00000008NAK\n0021ERR read: Bad file descriptor" \
97 581fa623 2022-12-30 thomas > $testroot/stdout.expected
99 581fa623 2022-12-30 thomas echo "gotsh: read: Bad file descriptor" > $testroot/stderr.expected
101 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout 0 108
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"
109 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
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"
117 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
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`
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
128 45b9d1e9 2022-12-30 thomas printf "00000008NAK\n0021ERR read: Bad file descriptor" \
129 581fa623 2022-12-30 thomas > $testroot/stdout.expected
131 581fa623 2022-12-30 thomas echo "gotsh: read: Bad file descriptor" > $testroot/stderr.expected
133 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout 0 108
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"
141 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
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"
149 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
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`
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
160 45b9d1e9 2022-12-30 thomas printf "00000008NAK\n0021ERR read: Bad file descriptor" \
161 581fa623 2022-12-30 thomas > $testroot/stdout.expected
163 581fa623 2022-12-30 thomas echo "gotsh: read: Bad file descriptor" > $testroot/stderr.expected
165 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout 0 108
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"
173 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
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"
181 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
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`
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
192 581fa623 2022-12-30 thomas echo -n "00000025ERR unexpected want-line received" \
193 581fa623 2022-12-30 thomas > $testroot/stdout.expected
195 581fa623 2022-12-30 thomas echo "gotsh: unexpected want-line received" > $testroot/stderr.expected
197 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout 0 108
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"
205 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
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"
213 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
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`
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
224 581fa623 2022-12-30 thomas echo -n "001fERR no git repository found" > $testroot/stdout.expected
226 581fa623 2022-12-30 thomas echo "gotsh: no git repository found" > $testroot/stderr.expected
228 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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"
236 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
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"
244 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
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`
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"
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
260 581fa623 2022-12-30 thomas echo -n "0018ERR buffer too small" > $testroot/stdout.expected
262 581fa623 2022-12-30 thomas echo "gotsh: buffer too small" > $testroot/stderr.expected
264 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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"
272 45b9d1e9 2022-12-30 thomas cmp -s $testroot/stderr.expected $testroot/stderr
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"
280 581fa623 2022-12-30 thomas test_done "$testroot" "$ret"
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