summaryrefslogtreecommitdiff
path: root/rts.tests
blob: ba8477b32147fbddbcab3afee9260954ed26d796 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# Assumes that there is no port named nonexistentport.
# Assumes that there is no listener for TCP port 16 at 127.0.0.1.
# Assumes that there is no listener for TCP port 50016 at 127.0.0.1.
# Assumes that there is no use of TCP port 50017 at 127.0.0.1.
# Assumes that DNS lookup on nonexistent.local. will give hard error.

# Not tested:
#   who@
#   date@
#   finger@
#   http@
#   tcpclient handles temporary DNS errors
#   tcpserver handles temporary DNS errors
#   tcpclient -i
#   tcpclient -r
#   tcpclient -h
#   tcpclient -d
#   tcpclient -D
#   tcpclient -T
#   tcpclient -t
#   tcpserver -1
#   tcpserver -p
#   tcpserver -r
#   tcpserver -h
#   tcpserver -o
#   tcpserver -O
#   tcpserver -d
#   tcpserver -D
#   tcpserver -v
#   tcpserver -c
#   tcpserver -g
#   tcpserver -u
#   tcpserver -b
#   tcpserver -t
#   tcpserver -x


echo '--- tcpclient prints usage message without enough arguments'
tcpclient 0 0; echo $?

echo '--- tcpclient prints error message with unknown port name'
tcpclient 0 nonexistentport echo wrong; echo $?

echo '--- tcpclient prints error message when connection fails'
tcpclient 0 016 echo wrong; echo $?

echo '--- tcpclient -q does not print error message when connection fails'
tcpclient -q 0 016 echo wrong; echo $?

echo '--- tcpclient understands empty host name as synonym for 0'
tcpclient '' 016 echo wrong; echo $?

echo '--- tcpclient understands unbracketed IP address'
tcpclient '127.000.000.001' 016 echo wrong; echo $?

echo '--- tcpclient understands bracketed IP address'
tcpclient '[127.000.000.001]' 016 echo wrong; echo $?

echo '--- tcpclient prints error message with unknown host name'
tcpclient nonexistent.local. 016 echo wrong; echo $?

echo '--- tcpserver prints usage message without enough arguments'
tcpserver 0 0; echo $?

echo '--- tcpserver prints error message with unknown port name'
tcpserver 0 nonexistentport echo wrong; echo $?

echo '--- tcpserver prints error message with unknown host name'
tcpserver nonexistent.local. 016 echo wrong; echo $?

echo '--- tcpserver prints error message with non-local host name'
tcpserver 1.2.3.4 016 echo wrong; echo $?

tcpserver -q -R -H -l Local 127.0.0.1 50016 sh -c '
  echo PROTO="$PROTO"
  echo TCPLOCALHOST="$TCPLOCALHOST"
  echo TCPLOCALIP="$TCPLOCALIP"
  echo TCPLOCALPORT="$TCPLOCALPORT"
  echo TCPREMOTEHOST="$TCPREMOTEHOST"
  echo TCPREMOTEIP="$TCPREMOTEIP"
  echo TCPREMOTEPORT="$TCPREMOTEPORT"
  echo TCPREMOTEINFO="$TCPREMOTEINFO"
' &
pid=$!
sleep 1 #XXX

echo '--- tcpserver sets basic environment variables' 
tcpclient -p 50017 -R -H -l Local 0 50016 sh -c 'cat <&6'
echo $?

echo '--- tcpclient sets basic environment variables' 
tcpclient -p 50017 -R -H -l Local 0 50016 sh -c '
  echo PROTO="$PROTO"
  echo TCPLOCALHOST="$TCPLOCALHOST"
  echo TCPLOCALIP="$TCPLOCALIP"
  echo TCPLOCALPORT="$TCPLOCALPORT"
  echo TCPREMOTEHOST="$TCPREMOTEHOST"
  echo TCPREMOTEIP="$TCPREMOTEIP"
  echo TCPREMOTEPORT="$TCPREMOTEPORT"
  echo TCPREMOTEINFO="$TCPREMOTEINFO"
'
echo $?

echo '--- tcpclient -v works' 
tcpclient -v -R -H -l Local 0 50016 echo ok
echo $?

echo '--- tcpserver prints error message with used port'
tcpserver -R -H -l Local 127.0.0.1 50016 echo wrong
echo $?

kill $pid
wait

tcpserver -B banner -q -R -H -l Local 127.0.0.1 50016 echo ok &
pid=$!
sleep 1 #XXX

echo '--- tcpcat works; tcpserver -B works'
tcpcat 0 50016
echo $?

echo '--- mconnect works'
mconnect 0 50016 </dev/null
echo $?

kill $pid
wait

echo '--- tcprules prints usage message without enough arguments'
tcprules test.cdb; echo $?

echo '--- tcprules prints error message if it cannot create tmp'
echo 1.2.3.4:deny | tcprules test.cdb /dev/nonexistent/tmp; echo $?

echo '--- tcprules prints error message if it cannot move tmp to cdb'
echo 1.2.3.4:deny | tcprules /dev/nonexistent/cdb test.tmp; echo $?

echo '--- tcprules creates a cdb file'
echo 1.2.3.4:deny | tcprules test.cdb test.tmp; echo $?

echo '--- tcprulescheck sees deny'
tcprulescheck test.cdb 1.2.3.4; echo $?

echo '--- tcprulescheck does not apply deny to another host'
tcprulescheck test.cdb 1.2.3.5; echo $?

echo '--- tcprules replaces a cdb file'
echo 'joe@127.0.0.1:allow,which=/first/
18.23.0.32:allow,which="second"
127.:allow,which=+third+
:allow,which==fourth=' | tcprules test.cdb test.tmp; echo $?

echo '--- tcprulescheck finds rule with address and info'
tcprulescheck test.cdb 127.0.0.1 joe; echo $?

echo '--- tcprulescheck finds rule with address'
tcprulescheck test.cdb 18.23.0.32 joe ; echo $?

echo '--- tcprulescheck finds one-dot wildcard'
tcprulescheck test.cdb 127.0.0.1 bill; echo $?

echo '--- tcprulescheck finds zero-dot wildcard'
tcprulescheck test.cdb 10.119.75.38 bill; echo $?

echo '--- tcprules handles comments, address ranges, multiple variables'
echo '127.0-5.:allow,which=/first/,where=/whatever/
# comment' | tcprules test.cdb test.tmp; echo $?
tcprulescheck test.cdb 127.0.0.1
tcprulescheck test.cdb 127.1.0.1
tcprulescheck test.cdb 127.2.0.1
tcprulescheck test.cdb 127.3.0.1
tcprulescheck test.cdb 127.4.0.1
tcprulescheck test.cdb 127.5.0.1
tcprulescheck test.cdb 127.6.0.1
tcprulescheck test.cdb 127.7.0.1
tcprulescheck test.cdb 127.8.0.1
tcprulescheck test.cdb 127.9.0.1
tcprulescheck test.cdb 127.10.0.1


echo '--- addcr leaves an empty file alone'
echo -n '' | addcr; echo $?

echo '--- addcr leaves a partial final line alone'
echo -n test | addcr; echo $?

echo '--- addcr adds CR after the first line'
echo test | addcr; echo $?

echo '--- addcr adds CR after the second line'
( echo test; echo test2 ) | addcr; echo $?

echo '--- addcr handles nulls'
echo test | tr e '\0' | addcr; echo $?

echo '--- delcr leaves an empty file alone'
echo -n '' | delcr; echo $?

echo '--- delcr leaves a non-CR line alone'
echo test | delcr; echo $?

echo '--- delcr removes CR if a line has it'
echo testx | tr x '\015' | delcr; echo $?

echo '--- delcr converts CR CR LF to CR LF'
echo testxx | tr x '\015' | delcr; echo $?

echo '--- delcr removes CR from a partial final line'
echo -n testx | tr x '\015' | delcr; echo $?

echo '--- delcr handles a non-CR partial final line'
echo -n test | delcr; echo $?

echo '--- delcr handles nulls'
echo test | tr e '\0' | delcr; echo $?

echo '--- fixcr leaves an empty file alone'
echo -n '' | fixcr; echo $?

echo '--- fixcr leaves a partial final line alone'
echo -n test | fixcr; echo $?

echo '--- fixcr adds CR after the first line'
echo test | fixcr; echo $?

echo '--- fixcr adds CR after the second line'
( echo test; echo test2 ) | fixcr; echo $?

echo '--- fixcr does not add CR if a line has it'
echo testx | tr x '\015' | fixcr; echo $?

echo '--- fixcr handles nulls'
echo test | tr e '\0' | fixcr; echo $?

echo '--- recordio works'
( echo test; sleep 1 ) | recordio cat 2>&1 >/dev/null \
| sed 's/^[0-9]*/.../' | sed 's/$/$/'

echo '--- recordio handles multiple-line packets'
( echo 'test
test2'; sleep 1 ) | recordio cat 2>&1 >/dev/null \
| sed 's/^[0-9]*/.../' | sed 's/$/$/'

echo '--- recordio handles partial final lines'
( echo -n test; sleep 1 ) | recordio cat 2>&1 >/dev/null \
| sed 's/^[0-9]*/.../' | sed 's/$/$/'

echo '--- argv0 works'
argv0 sh zero -c 'echo $0'; echo $?

echo '--- argv0 requires arguments'
argv0 sh; echo $?

exit 0