source: trunk/test/testrun_2.sh@ 20

Last change on this file since 20 was 19, checked in by rainer, 19 years ago

Rewrite of test suite, checksum for growing logs, fix for minor bug with dead client detection.

File size: 9.3 KB
Line 
1#! /bin/sh
2
3LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
4RCFILE="$PW_DIR/testrc_2"; export RCFILE
5
6
7do_test_1 () {
8
9 [ -z "$verbose" ] || {
10 echo;
11 echo "${S}Start Server${E}: ./yule -l info -p none &";
12 echo;
13 }
14 ./yule -l info -p none >/dev/null 2>&1 &
15 PROC_Y=$!
16 sleep 5
17
18 [ -z "$verbose" ] || {
19 echo;
20 echo "${S}Start Client${E}: ./samhain.new -l none -p none -e info -t check";
21 echo;
22 }
23
24 ./samhain.new -t check -p none -l none -e info --bind-address=127.0.0.1 >/dev/null 2>&1
25 if test x$? = x0; then
26 [ -z "$verbose" ] || log_msg_ok "samhain.new -t check";
27 else
28 [ -z "$quiet" ] && log_msg_fail "samhain.new -t check";
29 kill $PROC_Y
30 return 1
31 fi
32
33 kill $PROC_Y
34 sleep 5
35
36 egrep "START(>|\").*Yule(>|\")" $LOGFILE >/dev/null 2>&1
37 if [ $? -ne 0 ]; then
38 [ -z "$verbose" ] || log_msg_fail "Server start";
39 return 1
40 fi
41 egrep "NEW CLIENT" $LOGFILE >/dev/null 2>&1
42 if [ $? -ne 0 ]; then
43 [ -z "$verbose" ] || log_msg_fail "Client connect";
44 return 1
45 fi
46 egrep "remote_host.*Checking.*/bin" $LOGFILE >/dev/null 2>&1
47 if [ $? -ne 0 ]; then
48 [ -z "$verbose" ] || log_msg_fail "Client file check";
49 return 1
50 fi
51 egrep "remote_host.*EXIT.*Samhain" $LOGFILE >/dev/null 2>&1
52 if [ $? -ne 0 ]; then
53 [ -z "$verbose" ] || log_msg_fail "Client exit";
54 return 1
55 fi
56 egrep "EXIT.*Yule.*SIGTERM" $LOGFILE >/dev/null 2>&1
57 if [ $? -ne 0 ]; then
58 [ -z "$verbose" ] || log_msg_fail "Server exit";
59 return 1
60 fi
61
62
63 return 0
64}
65
66do_test_2 () {
67
68 ORIGINAL="UseSeparateLogs=no"
69 REPLACEMENT="UseSeparateLogs=yes"
70 ex $RCFILE <<EOF
71:%s/$ORIGINAL/$REPLACEMENT/g
72:wq
73EOF
74# :%s is the "ex" substitution command.
75# :wq is write-and-quit.
76 [ -z "$verbose" ] || {
77 echo;
78 echo "${S}Start Server${E}: ./yule -l info -p none &";
79 echo;
80 }
81
82 rm -f $LOGFILE
83
84 ./yule -l info -p none >/dev/null 2>&1 &
85 PROC_Y=$!
86 sleep 5
87
88 [ -z "$verbose" ] || {
89 echo;
90 echo "${S}Start Client${E}: ./samhain.new -l none -p none -e info -t check";
91 echo;
92 }
93
94 ./samhain.new -t check -p none -l none -e info --bind-address=127.0.0.1 >/dev/null 2>&1
95 if test x$? = x0; then
96 [ -z "$verbose" ] || log_msg_ok "samhain.new -t check";
97 else
98 [ -z "$quiet" ] && log_msg_fail "samhain.new -t check";
99 kill $PROC_Y
100 return 1
101 fi
102
103 kill $PROC_Y
104 sleep 5
105
106 if [ -f ${LOGFILE}.${SH_LOCALHOST} ]; then
107 remhost=${SH_LOCALHOST}
108 else
109 remhost=`echo $SH_LOCALHOST | sed 's,\..*,,'`
110 fi
111 if [ -f ${LOGFILE}.${remhost} ]; then
112 CLIENTLOG="${LOGFILE}.${remhost}"
113 else
114 CLIENTLOG=`ls -1 ${LOGFILE}.* | tail -n 1`
115 fi
116
117 egrep "START(>|\").*Yule(>|\")" $LOGFILE >/dev/null 2>&1
118 if [ $? -ne 0 ]; then
119 [ -z "$verbose" ] || log_msg_fail "Server start";
120 return 1
121 fi
122 egrep "NEW CLIENT" $LOGFILE >/dev/null 2>&1
123 if [ $? -ne 0 ]; then
124 [ -z "$verbose" ] || log_msg_fail "Client connect";
125 return 1
126 fi
127 egrep "remote_host.*Checking.*/bin" ${CLIENTLOG} >/dev/null 2>&1
128 if [ $? -ne 0 ]; then
129 [ -z "$verbose" ] || log_msg_fail "Client file check";
130 return 1
131 fi
132 egrep "remote_host.*EXIT.*Samhain" ${CLIENTLOG} >/dev/null 2>&1
133 if [ $? -ne 0 ]; then
134 [ -z "$verbose" ] || log_msg_fail "Client exit";
135 return 1
136 fi
137 egrep "EXIT.*Yule.*SIGTERM" $LOGFILE >/dev/null 2>&1
138 if [ $? -ne 0 ]; then
139 [ -z "$verbose" ] || log_msg_fail "Server exit";
140 return 1
141 fi
142
143 rm -f ${LOGFILE}.${remhost}
144 return 0
145}
146
147do_test_3 () {
148
149 ORIGINAL_1="ExportSeverity=none"
150 REPLACEMENT_1="ExportSeverity=mark"
151 ORIGINAL_2="UseSeparateLogs=yes"
152 REPLACEMENT_2="UseSeparateLogs=no"
153 ORIGINAL_3="LogSeverity=none"
154 REPLACEMENT_3="LogSeverity=debug"
155 ORIGINAL_4="# SetClientTimeLimit=1800"
156 REPLACEMENT_4="SetClientTimeLimit=20"
157 ex $RCFILE <<EOF
158:%s/${ORIGINAL_1}/${REPLACEMENT_1}/g
159:%s/${ORIGINAL_2}/${REPLACEMENT_2}/g
160:%s/${ORIGINAL_3}/${REPLACEMENT_3}/g
161:%s/${ORIGINAL_4}/${REPLACEMENT_4}/g
162:wq
163EOF
164# :%s is the "ex" substitution command.
165# :wq is write-and-quit.
166 [ -z "$verbose" ] || {
167 echo;
168 echo "${S}Start Server${E}: ./yule -p none &";
169 echo;
170 }
171
172 rm -f $LOGFILE
173
174 ./yule -p none >/dev/null 2>&1 &
175 PROC_Y=$!
176 sleep 5
177
178 [ -z "$verbose" ] || {
179 echo;
180 echo "${S}Start Client${E}: ./samhain.new -l none -p none -t check";
181 echo;
182 }
183
184 ./samhain.new -t check -p none -l none --forever --bind-address=127.0.0.1 >/dev/null 2>&1 &
185 if test x$? = x0; then
186 PROC_S=$!
187 # echo "PID is ${PROC_S}"
188 [ -z "$verbose" ] || log_msg_ok "samhain.new -t check";
189 sleep 5
190 # Redirect the shells (un-)helpful job monitoring messages.
191 # The 'disown' buildin is not portable.
192 { kill -9 ${PROC_S}; sleep 40; } >/dev/null 2>&1
193 else
194 [ -z "$quiet" ] && log_msg_fail "samhain.new -t check";
195 kill $PROC_Y
196 return 1
197 fi
198
199 if [ -t 0 ]; then
200 # enable monitor mode again if interactive
201 set -m
202 fi
203
204
205 kill $PROC_Y
206 sleep 5
207
208 egrep "START(>|\").*Yule(>|\")" $LOGFILE >/dev/null 2>&1
209 if [ $? -ne 0 ]; then
210 [ -z "$verbose" ] || log_msg_fail "Server start";
211 return 1
212 fi
213 egrep "NEW CLIENT" $LOGFILE >/dev/null 2>&1
214 if [ $? -ne 0 ]; then
215 [ -z "$verbose" ] || log_msg_fail "Client connect";
216 return 1
217 fi
218 egrep "remote_host.*File check completed.*" ${LOGFILE} >/dev/null 2>&1
219 if [ $? -ne 0 ]; then
220 [ -z "$verbose" ] || log_msg_fail "Client file check";
221 return 1
222 fi
223 egrep "Time limit exceeded" ${LOGFILE} >/dev/null 2>&1
224 if [ $? -ne 0 ]; then
225 [ -z "$verbose" ] || log_msg_fail "Client dead detection";
226 return 1
227 fi
228 egrep "EXIT.*Yule.*SIGTERM" $LOGFILE >/dev/null 2>&1
229 if [ $? -ne 0 ]; then
230 [ -z "$verbose" ] || log_msg_fail "Server exit";
231 return 1
232 fi
233
234 rm -f ${LOGFILE}.${remhost}
235 return 0
236}
237
238testrun2_internal ()
239{
240 [ -z "$verbose" ] || {
241 echo;
242 echo Working directory: $PW_DIR; echo MAKE is $MAKE;
243 echo;
244 }
245 #
246 #
247 [ -z "$verbose" ] || { echo; echo "${S}Building client and server${E}"; echo; }
248 #
249 if test -r "Makefile"; then
250 $MAKE distclean
251 fi
252 #
253 ${TOP_SRCDIR}/configure --quiet $TRUST --enable-debug --enable-network=client --enable-xml-log --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$LOGFILE --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file --enable-encrypt=2
254 #
255 if test x$? = x0; then
256 [ -z "$verbose" ] || log_msg_ok "configure...";
257 $MAKE > /dev/null 2>>test_log
258 if test x$? = x0; then
259 [ -z "$verbose" ] || log_msg_ok "make...";
260 else
261 [ -z "$quiet" ] && log_msg_fail "make...";
262 return 1
263 fi
264
265 else
266 [ -z "$quiet" ] && log_msg_fail "configure...";
267 return 1
268 fi
269
270 # save binary and build server
271 #
272 cp samhain samhain.build || return 1
273 make clean >/dev/null || return 1
274
275 ${TOP_SRCDIR}/configure --quiet $TRUST --enable-debug --enable-network=server --enable-xml-log --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$LOGFILE --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file --enable-identity=rainer --enable-encrypt=2
276 #
277 if test x$? = x0; then
278 [ -z "$verbose" ] || log_msg_ok "configure...";
279 $MAKE > /dev/null 2>>test_log
280 if test x$? = x0; then
281 [ -z "$verbose" ] || log_msg_ok "make...";
282 else
283 [ -z "$quiet" ] && log_msg_fail "make...";
284 return 1
285 fi
286
287 else
288 [ -z "$quiet" ] && log_msg_fail "configure...";
289 return 1
290 fi
291
292
293 #####################################################################
294 #
295 #
296 rm -f ./.samhain_file
297 rm -f ./.samhain_log
298 rm -f ./.samhain_lock
299
300 cp ${SCRIPTDIR}/testrc_2.in testrc_2
301
302 ./samhain.build -t init -p none
303
304 if test x$? = x0; then
305 [ -z "$verbose" ] || log_msg_ok "init...";
306 else
307 [ -z "$quiet" ] && log_msg_fail "init...";
308 return 1
309 fi
310
311 # Create a password
312
313 SHPW=`./yule -G`
314 if test x"$SHPW" = x; then
315 [ -z "$quiet" ] && log_msg_fail "password not generated -- aborting"
316 return 1
317 fi
318
319 # Set in client
320
321 ./samhain_setpwd samhain.build new $SHPW >/dev/null
322
323 if test x$? = x0; then
324 [ -z "$verbose" ] || log_msg_ok "./samhain_setpwd samhain.build new $SHPW";
325 else
326 [ -z "$quiet" ] && log_msg_fail "./samhain_setpwd samhain.build new $SHPW";
327 return 1
328 fi
329
330 mv samhain.build.new samhain.new || return 1
331
332 rm -f ./.samhain_log.*
333 rm -f ./.samhain_lock
334
335 SHCLT=`./yule -P $SHPW | sed s%HOSTNAME%${SH_LOCALHOST}%`
336
337 if test x$? = x0; then
338 [ -z "$verbose" ] || log_msg_ok "yule -P $SHPW";
339 else
340 [ -z "$quiet" ] && log_msg_fail "yule -P $SHPW";
341 return 1
342 fi
343
344 echo $SHCLT >> testrc_2
345
346 do_test_1
347 if [ $? -eq 0 ]; then
348 [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Client logging";
349 else
350 [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Client logging";
351 fi
352
353 do_test_2
354 if [ $? -eq 0 ]; then
355 [ -z "$quiet" ] && log_ok 2 ${MAXTEST} "Client logging, seperate logfiles";
356 else
357 [ -z "$quiet" ] && log_fail 2 ${MAXTEST} "Client logging, seperate logfiles";
358 fi
359
360 do_test_3
361 if [ $? -eq 0 ]; then
362 [ -z "$quiet" ] && log_ok 3 ${MAXTEST} "Dead client detection";
363 else
364 [ -z "$quiet" ] && log_fail 3 ${MAXTEST} "Dead client detection";
365 fi
366
367 return $?
368}
369
370MAXTEST=3; export MAXTEST
371
372testrun2 ()
373{
374 log_start "RUN CLIENT/SERVER"
375
376 if [ x"$1" = x ]; then
377 [ -z "$quiet" ] && log_msg_fail "Missing hostname"
378 fi
379 #
380 SH_LOCALHOST=$1; export SH_LOCALHOST
381 #
382 testrun2_internal
383 #
384 log_end "RUN CLIENT/SERVER"
385
386 return 0
387}
388
Note: See TracBrowser for help on using the repository browser.