source: trunk/test/testrun_2c.sh@ 583

Last change on this file since 583 was 469, checked in by katerina, 10 years ago

Fix for ticket #367 (testing scripts). Also update version and changelog.

File size: 12.2 KB
Line 
1#! /bin/sh
2
3#
4# Copyright Rainer Wichmann (2006)
5#
6# License Information:
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20#
21LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
22RCFILE="$PW_DIR/testrc_2"; export RCFILE
23HTML="$PW_DIR/yule.html"; export HTML
24
25SERVER_BUILDOPTS="--quiet $TRUST --enable-xml-log --enable-debug --enable-network=server --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2 --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-logserver=${SH_LOCALHOST} --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-database=mysql"; export SERVER_BUILDOPTS
26
27CLIENT_BUILDOPTS="--quiet $TRUST --prefix=$PW_DIR --with-tmp-dir=$PW_DIR --localstatedir=$PW_DIR --enable-network=client --disable-mail --disable-external-scripts --enable-login-watch --enable-xml-log --enable-db-reload --with-logserver=localhost --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2 --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock"; export CLIENT_BUILDOPTS
28
29MAXTEST=4; export MAXTEST
30
31do_test_1_c () {
32
33 [ -z "$verbose" ] || {
34 echo;
35 echo "${S}Start Server${E}: ./yule -l info -p none &";
36 echo;
37 }
38
39 rm -f test_log_valgrind
40
41 ${VALGRIND} ./yule.2 -q -l info -p none >/dev/null 2>>test_log_valgrind &
42 PROC_Y2=$!
43 five_sec_sleep
44
45 [ -z "$verbose" ] || {
46 echo;
47 echo "${S}Start Server #2${E}: ./yule.2 -l info -p none &";
48 echo;
49 }
50
51 ${VALGRIND} ./yule -l info -p none -e info --bind-address=127.0.0.1 \
52 --server-port=49778 >/dev/null 2>>test_log_valgrind &
53 PROC_Y=$!
54 five_sec_sleep
55
56 [ -z "$verbose" ] || {
57 echo;
58 echo "${S}Start Client${E}: ./samhain.new -l none -p none -e info -t check";
59 echo;
60 }
61
62 ${VALGRIND} ./samhain.new -t check -p none -l none -e info --bind-address=127.0.0.1 >/dev/null 2>>test_log_valgrind
63 if test x$? = x0; then
64 [ -z "$verbose" ] || log_msg_ok "samhain.new -t check";
65 else
66 [ -z "$quiet" ] && log_msg_fail "samhain.new -t check";
67 kill $PROC_Y
68 kill $PROC_Y2
69 return 1
70 fi
71
72 kill $PROC_Y
73 kill $PROC_Y2
74 five_sec_sleep
75
76 # cp ${LOGFILE} triple_test
77 # cp ${LOGFILE}2 triple_test_2
78
79 egrep "START(>|\").*Yule(>|\")" ${LOGFILE}2 >/dev/null 2>&1
80 if [ $? -ne 0 ]; then
81 [ -z "$verbose" ] || log_msg_fail "Server #2 start";
82 return 1
83 fi
84 egrep "remote_host.*Checking.*/bin" ${LOGFILE}2 >/dev/null 2>&1
85 if [ $? -ne 0 ]; then
86 [ -z "$verbose" ] || log_msg_fail "Client file check (relayed)";
87 return 1
88 fi
89 egrep "remote_host.*EXIT.*Samhain" ${LOGFILE}2 >/dev/null 2>&1
90 if [ $? -ne 0 ]; then
91 [ -z "$verbose" ] || log_msg_fail "Client exit (relayed)";
92 return 1
93 fi
94 egrep "EXIT.*Yule.*SIGTERM" ${LOGFILE}2 >/dev/null 2>&1
95 if [ $? -ne 0 ]; then
96 [ -z "$verbose" ] || log_msg_fail "Server #2 exit";
97 return 1
98 fi
99
100
101 egrep "START(>|\").*Yule(>|\")" $LOGFILE >/dev/null 2>&1
102 if [ $? -ne 0 ]; then
103 [ -z "$verbose" ] || log_msg_fail "Server start";
104 return 1
105 fi
106 egrep "NEW CLIENT" $LOGFILE >/dev/null 2>&1
107 if [ $? -ne 0 ]; then
108 [ -z "$verbose" ] || log_msg_fail "Client connect";
109 return 1
110 fi
111 egrep "remote_host.*Checking.*/bin" $LOGFILE >/dev/null 2>&1
112 if [ $? -ne 0 ]; then
113 [ -z "$verbose" ] || log_msg_fail "Client file check";
114 return 1
115 fi
116 egrep "remote_host.*EXIT.*Samhain" $LOGFILE >/dev/null 2>&1
117 if [ $? -ne 0 ]; then
118 [ -z "$verbose" ] || log_msg_fail "Client exit";
119 return 1
120 fi
121 egrep "EXIT.*Yule.*SIGTERM" $LOGFILE >/dev/null 2>&1
122 if [ $? -ne 0 ]; then
123 [ -z "$verbose" ] || log_msg_fail "Server exit";
124 return 1
125 fi
126
127 [ -z "$VALGRIND" ] || {
128 tmp=`cat test_log_valgrind 2>/dev/null | wc -l`;
129 if [ $tmp -ne 0 ]; then
130 [ -z "$verbose" ] || log_msg_fail "valgrind reports errors";
131 cat test_log_valgrind
132 return 1;
133 fi;
134 }
135
136 return 0
137}
138
139testrun_threesockets () {
140
141 GPG="$1"
142
143 [ -z "$verbose" ] || {
144 echo;
145 echo Working directory: $PW_DIR; echo MAKE is $MAKE; echo GPG is $GPG;
146 echo;
147 }
148
149 [ -z "$verbose" ] || { echo; echo "${S}Building client and server${E}"; echo; }
150
151 if test -r "Makefile"; then
152 $MAKE distclean
153 fi
154
155 ${TOP_SRCDIR}/configure --with-gpg=${GPG} --with-fp=EF6CEF54701A0AFDB86AF4C31AAD26C80F571F6C --with-checksum=no ${SERVER_BUILDOPTS} >/dev/null 2>&1
156
157 if test x$? = x0; then
158 [ -z "$verbose" ] || log_msg_ok "configure...";
159 $MAKE > /dev/null 2>>test_log
160 if test x$? = x0; then
161 [ -z "$verbose" ] || log_msg_ok "make...";
162 else
163 [ -z "$quiet" ] && log_msg_fail "make...";
164 return 1
165 fi
166 else
167 [ -z "$quiet" ] && log_msg_fail "configure...";
168 return 1
169 fi
170
171 rm -f ./.samhain_file
172 rm -f ./.samhain_log
173 rm -f ./.samhain_lock
174 rm -f ./rc.${SH_LOCALHOST}
175 rm -f ./file.${SH_LOCALHOST}
176
177 cp ${SCRIPTDIR}/testrc_2.in testrc_2
178
179 ORIGINAL="DatabaseSeverity=none"
180 REPLACEMENT="DatabaseSeverity=warn"
181 ex -s $RCFILE <<EOF
182%s/$ORIGINAL/$REPLACEMENT/g
183wq
184EOF
185
186 ORIGINAL="MailSeverity=none"
187 REPLACEMENT="MailSeverity=crit"
188 ex -s $RCFILE <<EOF
189%s/$ORIGINAL/$REPLACEMENT/g
190wq
191EOF
192 return 0
193 }
194
195check_mysql_log () {
196 DATE="$1"
197
198 rm -f test_log_db
199 #
200 echo "SELECT * FROM log WHERE entry_status = 'NEW' and log_time > '"${DATE}"';" | mysql --password=samhain -u samhain samhain >test_log_db
201 #
202 egrep "START.*Yule" test_log_db >/dev/null 2>&1
203 if [ $? -ne 0 ]; then
204 [ -z "$verbose" ] || log_msg_fail "Server start";
205 return 1
206 fi
207 egrep "NEW CLIENT" test_log_db >/dev/null 2>&1
208 if [ $? -ne 0 ]; then
209 [ -z "$verbose" ] || log_msg_fail "Client connect";
210 return 1
211 fi
212 egrep "Checking.*/bin" test_log_db >/dev/null 2>&1
213 if [ $? -ne 0 ]; then
214 [ -z "$verbose" ] || log_msg_fail "Client file check";
215 return 1
216 fi
217 egrep "EXIT.*Samhain" test_log_db >/dev/null 2>&1
218 if [ $? -ne 0 ]; then
219 [ -z "$verbose" ] || log_msg_fail "Client exit";
220 return 1
221 fi
222 egrep "EXIT.*Yule.*SIGTERM" test_log_db >/dev/null 2>&1
223 if [ $? -ne 0 ]; then
224 [ -z "$verbose" ] || log_msg_fail "Server exit";
225 return 1
226 fi
227 return 0
228}
229
230testrun2c ()
231{
232 log_start "RUN FULL CLIENT/SERVER W/MYSQL"
233 #
234 if [ -z "$doall" ]; then
235 log_skip 1 $MAXTEST 'Client/server w/mysql (or use --really-all)'
236 log_skip 2 $MAXTEST 'Client/server w/mysql (or use --really-all)'
237 log_skip 3 $MAXTEST 'Client/server w/mysql (or use --really-all)'
238 log_skip 4 $MAXTEST 'Client/server w/mysql (or use --really-all)'
239 return 0
240 fi
241 if [ x"$1" = x ]; then
242 [ -z "$quiet" ] && log_msg_fail "Missing hostname"
243 fi
244 MYSQL=`find_path mysql`
245 if [ -z "$MYSQL" ]; then
246 log_skip 1 $MAXTEST "mysql not found";
247 log_skip 2 $MAXTEST "mysql not found";
248 log_skip 3 $MAXTEST "mysql not found";
249 log_skip 4 $MAXTEST "mysql not found";
250 return 1
251 else
252 TEST=`echo "DESCRIBE log;" | mysql --password=samhain -u samhain samhain 2>/dev/null`
253 if [ $? -ne 0 -o -z "$TEST" ]; then
254 log_skip 1 $MAXTEST "mysql not default setup"
255 log_skip 2 $MAXTEST "mysql not default setup"
256 log_skip 3 $MAXTEST "mysql not default setup"
257 log_skip 4 $MAXTEST "mysql not default setup"
258 return 1
259 fi
260 fi
261 #
262 SH_LOCALHOST=$1; export SH_LOCALHOST
263 #
264 DATE=`date '+%Y-%m-%d %T'`
265 #
266 testrun2a_internal
267 #
268 # BUILD Server 2
269 #
270 cp ./yule ./yule.orig
271
272 ${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}2 --with-log-file=${LOGFILE}2 --with-pid-file=$PW_DIR/.samhain_lock2 --with-html-file=${HTML}2 --with-state-dir=$PW_DIR --with-port=49778 --with-database=mysql
273 #
274 if test x$? = x0; then
275 [ -z "$verbose" ] || log_msg_ok "configure...";
276 $MAKE > /dev/null 2>>test_log
277 if test x$? = x0; then
278 [ -z "$verbose" ] || log_msg_ok "make...";
279 else
280 [ -z "$quiet" ] && log_msg_fail "make...";
281 return 1
282 fi
283
284 else
285 [ -z "$quiet" ] && log_msg_fail "configure...";
286 return 1
287 fi
288
289 cp yule yule.2 || return 1
290 #
291 cp ./yule.orig ./yule
292 #
293 SHPW=`cat ./testpw`
294
295 if test x"$SHPW" = x; then
296 [ -z "$quiet" ] && log_msg_fail "password not generated -- aborting"
297 return 1
298 fi
299
300 rm -f ./testpw
301
302 ./samhain_setpwd yule new $SHPW >/dev/null
303
304 if test x$? = x0; then
305 [ -z "$verbose" ] || log_msg_ok "./samhain_setpwd yule new $SHPW";
306 else
307 [ -z "$quiet" ] && log_msg_fail "./samhain_setpwd yule new $SHPW";
308 return 1
309 fi
310
311
312 $MAKE clean >/dev/null || return 1
313 mv yule.new yule || return 1
314 #
315 ORIGINAL="DatabaseSeverity=none"
316 REPLACEMENT="DatabaseSeverity=info"
317 ex -s $RCFILE <<EOF
318%s/$ORIGINAL/$REPLACEMENT/g
319wq
320EOF
321 #
322 do_test_1_a
323 #
324 if [ $? -ne 0 ]; then
325 [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Client/server w/mysql";
326 else
327 #
328 check_mysql_log "${DATE}"
329 if [ $? -ne 0 ]; then
330 [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Client/server w/mysql";
331 else
332 [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Client/server w/mysql";
333 fi
334 fi
335 #
336 cp testrc_2 testrc_22
337 ORIGINAL="DatabaseSeverity=none"
338 REPLACEMENT="DatabaseSeverity=info"
339 ex -s $RCFILE <<EOF
340%s/$REPLACEMENT/$ORIGINAL/g
341wq
342EOF
343 #
344 do_test_1_c
345 #
346 if [ $? -ne 0 ]; then
347 [ -z "$quiet" ] && log_fail 2 ${MAXTEST} "Client/server (relay) w/mysql";
348 else
349 #
350 check_mysql_log "${DATE}"
351 if [ $? -ne 0 ]; then
352 [ -z "$quiet" ] && log_fail 2 ${MAXTEST} "Client/server (relay) w/mysql";
353 else
354 [ -z "$quiet" ] && log_ok 2 ${MAXTEST} "Client/server (relay) w/mysql";
355 fi
356 fi
357 #
358 #
359 if [ -f ./yule ]; then
360 ./yule -p info -l info --set-database-severity=info -D >/dev/null 2>>test_log
361 five_sec_sleep
362 netstat -pant 2>/dev/null | grep 49777 | grep yule >/dev/null 2>&1
363 if [ $? -ne 0 ]; then
364 [ -z "$quiet" ] && log_fail 3 ${MAXTEST} "Client/server w/mysql";
365 else
366 NSOCK=`netstat -pand 2>/dev/null | grep STREAM | grep yule | wc -l`
367 if [ $NSOCK -ne 2 ]; then
368 [ -z "$quiet" ] && log_fail 3 ${MAXTEST} "Three sockets open";
369 netstat -pand 2>/dev/null | grep yule
370 else
371 [ -z "$quiet" ] && log_ok 3 ${MAXTEST} "Three sockets open";
372 fi
373 fi
374 PID=`cat .samhain_lock`
375 kill $PID
376 else
377 log_fail 3 ${MAXTEST} "Three sockets open";
378 fi
379 #
380 cp ${SCRIPTDIR}/testrc_2.in testrc_2
381 #
382 GPG=`find_path gpg`
383 if [ -z "$GPG" ]; then
384 log_skip 4 $MAXTEST 'gpg not found in $PATH'
385 else
386 eval "$GPG" --list-keys 0F571F6C >/dev/null 2>/dev/null
387 if [ $? -ne 0 ]; then
388 log_skip 4 $MAXTEST 'public PGP key 0x0F571F6C not present'
389 else
390 testrun_threesockets "$GPG"
391 #
392 cp ${SCRIPTDIR}/testrc_2.in testrc_2
393 #
394 if [ -f ./yule ]; then
395 ./yule -D --set-database-severity=warn >/dev/null 2>>test_log
396 five_sec_sleep
397 netstat -pant 2>/dev/null | grep 49777 | grep yule >/dev/null 2>&1
398 if [ $? -ne 0 ]; then
399 [ -z "$quiet" ] && log_fail 4 ${MAXTEST} "Three sockets open (gpg) - 1";
400 else
401 NSOCK=`netstat -pand 2>/dev/null | grep STREAM | grep yule | wc -l`
402 if [ $NSOCK -ne 2 ]; then
403 [ -z "$quiet" ] && log_fail 4 ${MAXTEST} "Three sockets open (gpg) - 2";
404 netstat -pand 2>/dev/null | grep yule
405 else
406 [ -z "$quiet" ] && log_ok 4 ${MAXTEST} "Three sockets open (gpg)";
407 fi
408 fi
409 PID=`cat .samhain_lock`
410 kill $PID
411 else
412 log_fail 4 ${MAXTEST} "Three sockets open (gpg) - 3";
413 fi
414 fi
415 fi
416 #
417 if [ -n "$cleanup" ]; then
418 rm -f ./rc.${SH_LOCALHOST}
419 rm -f ./file.${SH_LOCALHOST}
420 ALTHOST=`find_hostname`
421 rm -f "./file.${ALTHOST}"
422 rm -f "./rc.${ALTHOST}"
423 fi
424 #
425 log_end "RUN FULL CLIENT/SERVER W/MYSQL"
426}
427
Note: See TracBrowser for help on using the repository browser.