]> git.ipfire.org Git - thirdparty/strongswan.git/blob - testing/do-tests
testing: Clearly mark the tests that failed
[thirdparty/strongswan.git] / testing / do-tests
1 #!/bin/bash
2 # Automatically execute the strongSwan test cases
3 #
4 # Copyright (C) 2004 Eric Marchionni, Patrik Rayo
5 # Zuercher Hochschule Winterthur
6 #
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2 of the License, or (at your
10 # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # for more details.
16
17 DIR=$(dirname `readlink -f $0`)
18 . $DIR/testing.conf
19 . $DIR/scripts/function.sh
20 SSHCONF="-F $DIR/ssh_config"
21
22 [ -d $DIR/hosts ] || die "Directory 'hosts' not found"
23 [ -d $DIR/tests ] || die "Directory 'tests' not found"
24 [ -d $BUILDDIR ] ||
25 die "Directory '$BUILDDIR' does not exist, please run make-testing first"
26 running_any $STRONGSWANHOSTS || die "Please start test environment before running $0"
27
28 ln -sfT $DIR $TESTDIR/testing
29
30 ##############################################################################
31 # take care of new path and file variables
32 #
33
34 [ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
35
36 TESTDATE=`date +%Y%m%d-%H%M-%S`
37
38 TODAYDIR=$TESTRESULTSDIR/$TESTDATE
39 mkdir $TODAYDIR
40 TESTRESULTSHTML=$TODAYDIR/all.html
41 INDEX=$TODAYDIR/index.html
42 DEFAULTTESTSDIR=$TESTDIR/testing/tests
43
44 SOURCEIP_ROUTING_TABLE=220
45
46 testnumber="0"
47 failed_cnt="0"
48 passed_cnt="0"
49 subdir_cnt="0"
50
51 ##############################################################################
52 # copy default tests to $BUILDDIR
53 #
54
55 TESTSDIR=$BUILDDIR/tests
56 [ -d $TESTSDIR ] || mkdir $TESTSDIR
57
58 ##############################################################################
59 # assign IP for each host to hostname
60 #
61
62 for host in $STRONGSWANHOSTS
63 do
64 eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
65 eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
66
67 case $host in
68 moon)
69 eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
70 eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
71 ;;
72 sun)
73 eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
74 eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
75 ;;
76 alice)
77 eval ipv4_alice1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
78 eval ipv6_alice1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
79 ;;
80 venus)
81 ;;
82 bob)
83 ;;
84 carol)
85 eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
86 eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
87 ;;
88 dave)
89 eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
90 eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
91 ;;
92 winnetou)
93 ;;
94 esac
95 done
96
97
98 ##############################################################################
99 # open ssh sessions
100 #
101 for host in $STRONGSWANHOSTS
102 do
103 ssh $SSHCONF -N root@`eval echo \\\$ipv4_$host` >/dev/null 2>&1 &
104 eval ssh_pid_$host="`echo $!`"
105 do_on_exit kill `eval echo \\\$ssh_pid_$host`
106 done
107
108 ##############################################################################
109 # determine actual software versions
110 #
111
112 [ -f $SHAREDDIR/.strongswan-version ] && SWANVERSION=`cat $SHAREDDIR/.strongswan-version`
113 KERNELVERSION=`ssh $SSHCONF root@\$ipv4_winnetou uname -r 2>/dev/null`
114
115 # check if tcpdump supports --immediate-mode
116 ssh $SSHCONF root@$ipv4_winnetou tcpdump --immediate-mode -c 1 >/dev/null 2>&1
117 if [ $? -eq 0 ]
118 then
119 TCPDUMP_IM=--immediate-mode
120 fi
121
122 ##############################################################################
123 # create header for the results html file
124 #
125
126 ENVIRONMENT_HEADER=$(cat <<@EOF
127 <table border="0" cellspacing="2" cellpadding="2">
128 <tr valign="top">
129 <td><b>Host</b></td>
130 <td colspan="3">`uname -a`</td>
131 </tr>
132 <tr valign="top">
133 <td><b>Guest kernel</b></td>
134 <td colspan="3">$KERNELVERSION</td>
135 </tr>
136 <tr valign="top">
137 <td><b>strongSwan</b></td>
138 <td colspan="3">$SWANVERSION</td>
139 </tr>
140 <tr valign="top">
141 <td><b>Date</b></td>
142 <td colspan="3">$TESTDATE</td>
143 </tr>
144 <tr>
145 <td width="100">&nbsp;</td>
146 <td width="300">&nbsp;</td>
147 <td width=" 80">&nbsp;</td>
148 <td >&nbsp;</td>
149 </tr>
150 @EOF
151 )
152
153 cat > $INDEX <<@EOF
154 <html>
155 <head>
156 <title>strongSwan KVM Tests</title>
157 </head>
158 <body>
159 <h2>strongSwan KVM Tests</h2>
160 $ENVIRONMENT_HEADER
161 @EOF
162
163 cat > $TESTRESULTSHTML <<@EOF
164 <html>
165 <head>
166 <title>strongSwan KVM Tests - All Tests</title>
167 </head>
168 <body>
169 <div><a href="index.html">strongSwan KVM Tests</a> / All Tests</div>
170 <h2>All Tests</h2>
171 $ENVIRONMENT_HEADER
172 <tr align="left">
173 <th>Number</th>
174 <th>Test</th>
175 <th align="right">Time [s]</th>
176 <th>Result</th>
177 </tr>
178 @EOF
179
180 echo "Guest kernel : $KERNELVERSION"
181 echo "strongSwan : $SWANVERSION"
182 echo "Date : $TESTDATE"
183 echo
184
185 ##############################################################################
186 # trap CTRL-C to properly terminate a long run
187 #
188
189 function abort_tests()
190 {
191 echo -n "...aborting..." > /dev/tty
192 aborted=YES
193 }
194 trap abort_tests INT
195
196 ##############################################################################
197 # enter specific test directory
198 #
199 if [ $# -gt 0 ]
200 then
201 TESTS=$(printf "%s\n" $* | sort -u)
202 else
203 TESTS=$(ls $DEFAULTTESTSDIR)
204 fi
205
206 for SUBDIR in $TESTS
207 do
208 SUBTESTS="`basename $SUBDIR`"
209
210 if [ $SUBTESTS = $SUBDIR ]
211 then
212 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
213 else
214 if [[ $SUBTESTS == *'*'* ]]
215 then
216 SUBTESTS="`basename -a $DEFAULTTESTSDIR/$SUBDIR`"
217 fi
218 SUBDIR="`dirname $SUBDIR`"
219 fi
220
221 if [ ! -d $TODAYDIR/$SUBDIR ]
222 then
223 mkdir $TODAYDIR/$SUBDIR
224 if [ $testnumber == 0 ]
225 then
226 FIRST="<b>Category</b>"
227 else
228 FIRST="&nbsp;"
229 fi
230
231 if [ $subdir_cnt != 0 ]
232 then
233 echo " <td align=\"right\">$subdir_cnt</td>" >> $INDEX
234 echo " <td>&nbsp;</td>" >> $INDEX
235 echo " </tr>" >> $INDEX
236 subdir_cnt="0"
237 fi
238 echo " <tr>" >> $INDEX
239 echo " <td>$FIRST</td>">> $INDEX
240 echo " <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
241
242 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
243 cat > $SUBTESTSINDEX <<@EOF
244 <html>
245 <head>
246 <title>strongSwan $SUBDIR Tests</title>
247 </head>
248 <body>
249 <div><a href="../index.html">strongSwan KVM Tests</a> / $SUBDIR</div>
250 <h2>strongSwan $SUBDIR Tests</h2>
251 <table border="0" cellspacing="2" cellpadding="2">
252 <tr valign="top">
253 <td><b>Guest kernel</b></td>
254 <td colspan="3">$KERNELVERSION</td>
255 </tr>
256 <tr valign="top">
257 <td><b>strongSwan</b></td>
258 <td colspan="3">$SWANVERSION</td>
259 </tr>
260 <tr valign="top">
261 <td><b>Date</b></td>
262 <td colspan="3">$TESTDATE</td>
263 </tr>
264 <tr>
265 <td width="100">&nbsp;</td>
266 <td width="300">&nbsp;</td>
267 <td width=" 50">&nbsp;</td>
268 <td >&nbsp;</td>
269 </tr>
270 <tr align="left">
271 <th>Number</th>
272 <th>Test</th>
273 <th colspan="2">Result</th>
274 </tr>
275 @EOF
276 fi
277
278 for name in $SUBTESTS
279 do
280 let "testnumber += 1"
281 let "subdir_cnt += 1"
282 testname=$SUBDIR/$name
283 log_action " $testnumber $testname:"
284
285 teststart=$(date +%s)
286
287 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
288 then
289 echo "is missing..skipped"
290 continue
291 fi
292
293 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
294 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
295 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
296 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
297 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
298
299 TESTRESULTDIR=$TODAYDIR/$testname
300 mkdir -p $TESTRESULTDIR
301 CONSOLE_LOG=$TESTRESULTDIR/console.log
302 touch $CONSOLE_LOG
303
304 TESTDIR=$TESTSDIR/${testname}
305
306 ##########################################################################
307 # copy test specific configurations to hosts and clear log files
308 #
309
310 DBDIR=/etc/db.d
311
312 $DIR/scripts/load-testconfig $testname
313 unset RADIUSHOSTS
314 unset DBHOSTS
315 unset IPV6
316 unset SWANCTL
317 source $TESTDIR/test.conf
318
319
320 ##########################################################################
321 # run tcpdump in the background
322 #
323
324 if [ "$TCPDUMPHOSTS" != "" ]
325 then
326 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
327
328 for host_iface in $TCPDUMPHOSTS
329 do
330 host=`echo $host_iface | awk -F ":" '{print $1}'`
331 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
332 tcpdump_cmd="tcpdump -l $TCPDUMP_IM -i $iface not port ssh and not port domain >/tmp/tcpdump.log 2>/tmp/tcpdump.err.log &"
333 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
334 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
335 eval TDUP_${host}="true"
336 done
337 fi
338
339 ##########################################################################
340 # create database directory in RAM
341 #
342
343 for host in $DBHOSTS
344 do
345 eval HOSTLOGIN=root@\$ipv4_${host}
346 ssh $SSHCONF $HOSTLOGIN "mkdir -p $DBDIR; mount -t ramfs -o size=5m ramfs $DBDIR" >/dev/null 2>&1
347 ssh $SSHCONF $HOSTLOGIN "chgrp www-data $DBDIR; chmod g+w $DBDIR" >/dev/null 2>&1
348 done
349
350 ##########################################################################
351 # flush conntrack table on all hosts
352 #
353
354 for host in $STRONGSWANHOSTS
355 do
356 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'conntrack -F' >/dev/null 2>&1
357 done
358
359 ##########################################################################
360 # remove leak detective log on all hosts
361 #
362
363 export LEAK_DETECTIVE_LOG=/var/log/leak-detective.log
364 for host in $STRONGSWANHOSTS
365 do
366 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'rm -f $LEAK_DETECTIVE_LOG' >/dev/null 2>&1
367 done
368
369 ##########################################################################
370 # flush IPsec state on all hosts
371 #
372
373 for host in $STRONGSWANHOSTS
374 do
375 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'ip xfrm state flush; ip xfrm policy flush' >/dev/null 2>&1
376 done
377
378 ##########################################################################
379 # execute pre-test commands
380 #
381
382 echo -n "pre.."
383 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
384
385 eval `awk -F "::" '{
386 if ($1 !~ /^#.*/ && $2 != "")
387 {
388 printf("echo \"%s# %s\"; ", $1, $2)
389 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
390 printf("echo;\n")
391 }
392 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
393
394
395 ##########################################################################
396 # stop tcpdump
397 #
398
399 function stop_tcpdump {
400 # wait for packets to get processed, but don't wait longer than 1s
401 eval ssh $SSHCONF root@\$ipv4_${1} "\"i=100; while [ \\\$i -gt 0 ]; do pkill -USR1 tcpdump; tail -1 /tmp/tcpdump.err.log | perl -n -e '/(\\d+).*?(\\d+)/; exit (\\\$1 == \\\$2)' || break; sleep 0.01; i=\\\$((\\\$i-1)); done;\""
402 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
403 eval ssh $SSHCONF root@\$ipv4_${1} "\"killall tcpdump; while true; do killall -q -0 tcpdump || break; sleep 0.01; done;\""
404 eval TDUP_${1}="false"
405 echo "" >> $CONSOLE_LOG
406 }
407
408
409 ##########################################################################
410 # get and evaluate test results
411 #
412
413 echo -n "test.."
414 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
415
416 STATUS="passed"
417
418 eval `awk -F "::" '{
419 host=$1
420 command=$2
421 pattern=$3
422 hit=$4
423 if (host ~ /^#.*/ || command == "")
424 {
425 next
426 }
427 if (command == "tcpdump")
428 {
429 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
430 printf("cmd_out=\044(ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"); ", host, pattern)
431 }
432 else
433 {
434 printf("cmd_out=\044(ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"); ", host, command, pattern)
435 }
436 printf("cmd_exit=\044?; ")
437 printf("cmd_fail=0; ")
438 if (hit ~ /^[0-9]+$/)
439 {
440 printf("if [ \044(echo \"\044cmd_out\" | wc -l) -ne %d ] ", hit)
441 }
442 else
443 {
444 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
445 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
446 }
447 printf("; then STATUS=\"failed\"; cmd_fail=1; fi; \n")
448
449 printf("if [ \044cmd_fail -ne 0 ]; then echo \"~~~~~~~ FAIL ~~~~~~~\"; fi; \n")
450 if (command == "tcpdump")
451 {
452 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
453 }
454 else
455 {
456 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
457 }
458 printf("if [ -n \"\044cmd_out\" ]; then echo \"\044cmd_out\"; fi; \n")
459 printf("if [ \044cmd_fail -ne 0 ]; then echo \"~~~~~~~~~~~~~~~~~~~~\"; fi; \n")
460 printf("echo; ")
461 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
462
463
464 ##########################################################################
465 # log statusall and listall output
466 # get copies of ipsec.conf, ipsec.secrets
467 # create index.html for the given test case
468
469 cat > $TESTRESULTDIR/index.html <<@EOF
470 <html>
471 <head>
472 <title>Test $testname</title>
473 </head>
474 <body>
475 <table border="0" cellpadding="0" cellspacing="0" width="600">
476 <tr><td>
477 <div><a href="../../index.html">strongSwan KVM Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
478 <h2>Test $testname</h2>
479 <h3>Description</h3>
480 @EOF
481
482 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
483
484 cat >> $TESTRESULTDIR/index.html <<@EOF
485 <ul>
486 <li><a href="console.log">console.log</a></li>
487 </ul>
488 <img src="../../images/$DIAGRAM" alt="$VIRTHOSTS">
489 @EOF
490
491 IPTABLES_CMD_V4="echo -e '=== filter table ==='; iptables -v -n -L; echo -e '\n=== nat table ==='; iptables -v -n -t nat -L; echo -e '\n=== mangle table ==='; iptables -v -n -t mangle -L"
492 IPTABLES_CMD_V6="echo -e '=== filter table ==='; ip6tables -v -n -L; echo -e '\n=== nat table ==='; ip6tables -v -n -t nat -L; echo -e '\n=== mangle table ==='; ip6tables -v -n -t mangle -L"
493
494 if [ -n "$IPV6" ]
495 then
496 IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
497 IPROUTE_DSP=$IPROUTE_CMD
498 IPTABLES_CMD="$IPTABLES_CMD_V6"
499 IPTABLES_DSP="ip6tables -L"
500 IPTABLES_SAVE_CMD="ip6tables-save"
501 IPTABLES_SAVE_DSP="ip6tables-save"
502 else
503 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
504 IPROUTE_DSP=$IPROUTE_CMD
505 IPTABLES_CMD="$IPTABLES_CMD_V4"
506 IPTABLES_DSP="iptables -L"
507 IPTABLES_SAVE_CMD="iptables-save"
508 IPTABLES_SAVE_DSP="iptables-save"
509 fi
510
511 if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
512 then
513 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
514 IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
515 IPTABLES_CMD="$IPTABLES_CMD_V4; echo; $IPTABLES_CMD_V6"
516 IPTABLES_DSP="iptables -L ; ip6tables -L"
517 IPTABLES_SAVE_CMD="iptables-save; echo; ip6tables-save"
518 IPTABLES_SAVE_DSP="iptables-save ; ip6tables-save"
519 fi
520
521 for host in $DBHOSTS
522 do
523 eval HOSTLOGIN=root@\$ipv4_${host}
524
525 scp $SSHCONF $HOSTLOGIN:/etc/db.d/ipsec.sql \
526 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
527 done
528
529 for host in $IPSECHOSTS
530 do
531 eval HOSTLOGIN=root@\$ipv4_${host}
532
533 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
534 $TESTRESULTDIR/${host}.strongswan.conf > /dev/null 2>&1
535 if [ -n "$SWANCTL" ]
536 then
537 scp $SSHCONF $HOSTLOGIN:/etc/swanctl/swanctl.conf \
538 $TESTRESULTDIR/${host}.swanctl.conf > /dev/null 2>&1
539
540 for subsys in conns algs certs pools authorities sas pols
541 do
542 ssh $SSHCONF $HOSTLOGIN swanctl --list-$subsys \
543 > $TESTRESULTDIR/${host}.swanctl.$subsys 2>/dev/null
544 done
545
546 ssh $SSHCONF $HOSTLOGIN swanctl --stats \
547 > $TESTRESULTDIR/${host}.swanctl.stats 2>/dev/null
548
549 echo "" >> $TESTRESULTDIR/${host}.swanctl.sas
550 cat $TESTRESULTDIR/${host}.swanctl.pols >> \
551 $TESTRESULTDIR/${host}.swanctl.sas
552 cat $TESTRESULTDIR/${host}.swanctl.algs >> \
553 $TESTRESULTDIR/${host}.swanctl.stats
554 else
555 for file in ipsec.conf ipsec.secrets
556 do
557 scp $SSHCONF $HOSTLOGIN:/etc/$file \
558 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
559 done
560
561 for command in statusall listall
562 do
563 ssh $SSHCONF $HOSTLOGIN ipsec $command \
564 > $TESTRESULTDIR/${host}.$command 2>/dev/null
565 done
566 fi
567
568 if (! [ -f $TESTRESULTDIR/${host}.ipsec.sql ] ) then
569 scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
570 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
571 fi
572
573 ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
574 > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
575 ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
576 > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
577 ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
578 > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
579 ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
580 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
581 ssh $SSHCONF $HOSTLOGIN $IPTABLES_SAVE_CMD \
582 > $TESTRESULTDIR/${host}.iptables-save 2>/dev/null
583 chmod a+r $TESTRESULTDIR/*
584
585 if [ -n "$SWANCTL" ]
586 then
587 cat >> $TESTRESULTDIR/index.html <<@EOF
588 <h3>$host</h3>
589 <table border="0" cellspacing="0" width="600">
590 <tr>
591 <td valign="top">
592 <ul>
593 <li><a href="$host.swanctl.conf">swanctl.conf</a></li>
594 <li><a href="$host.swanctl.conns">swanctl --list-conns</a></li>
595 <li><a href="$host.swanctl.certs">swanctl --list-certs</a></li>
596 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
597 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
598 </ul>
599 </td>
600 <td valign="top">
601 <ul>
602 <li><a href="$host.swanctl.sas">swanctl --list-sas|--list-pols</a></li>
603 <li><a href="$host.swanctl.pools">swanctl --list-pools</a></li>
604 <li><a href="$host.swanctl.authorities">swanctl --list-authorities</a></li>
605 <li><a href="$host.swanctl.stats">swanctl --stats|--list-algs</a></li>
606 <li><a href="$host.auth.log">auth.log</a></li>
607 <li><a href="$host.daemon.log">daemon.log</a></li>
608 </ul>
609 </td>
610 <td valign="top">
611 <ul>
612 <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
613 <li><a href="$host.ip.state">ip -s xfrm state</a></li>
614 <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
615 <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
616 <li><a href="$host.iptables-save">$IPTABLES_SAVE_DSP</a></li>
617 </ul>
618 &nbsp;
619 </td>
620 </tr>
621 </table>
622 @EOF
623
624 else
625 cat >> $TESTRESULTDIR/index.html <<@EOF
626 <h3>$host</h3>
627 <table border="0" cellspacing="0" width="600">
628 <tr>
629 <td valign="top">
630 <ul>
631 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
632 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
633 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
634 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
635 </ul>
636 </td>
637 <td valign="top">
638 <ul>
639 <li><a href="$host.statusall">ipsec statusall</a></li>
640 <li><a href="$host.listall">ipsec listall</a></li>
641 <li><a href="$host.auth.log">auth.log</a></li>
642 <li><a href="$host.daemon.log">daemon.log</a></li>
643 </ul>
644 </td>
645 <td valign="top">
646 <ul>
647 <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
648 <li><a href="$host.ip.state">ip -s xfrm state</a></li>
649 <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
650 <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
651 <li><a href="$host.iptables-save">$IPTABLES_SAVE_DSP</a></li>
652 </ul>
653 </td>
654 </tr>
655 </table>
656 @EOF
657 fi
658 done
659
660 for host in $RADIUSHOSTS
661 do
662 eval HOSTLOGIN=root@\$ipv4_${host}
663
664 for file in clients.conf eap.conf radiusd.conf proxy.conf users
665 do
666 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
667 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
668 done
669
670 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
671 $TESTRESULTDIR/${host}.strongswan.conf > /dev/null 2>&1
672
673 scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
674 $TESTRESULTDIR/${host}.radius.log > /dev/null 2>&1
675
676 ssh $SSHCONF $HOSTLOGIN grep imcv /var/log/daemon.log \
677 >> $TESTRESULTDIR/${host}.daemon.log 2>/dev/null
678
679 chmod a+r $TESTRESULTDIR/*
680 cat >> $TESTRESULTDIR/index.html <<@EOF
681 <h3>$host</h3>
682 <table border="0" cellspacing="0" width="600">
683 <tr>
684 <td valign="top">
685 <ul>
686 <li><a href="$host.clients.conf">clients.conf</a></li>
687 <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
688 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
689 </ul>
690 </td>
691 <td valign="top">
692 <ul>
693 <li><a href="$host.eap.conf">eap.conf</a></li>
694 <li><a href="$host.radius.log">radius.log</a></li>
695 <li><a href="$host.daemon.log">daemon.log</a></li>
696 </ul>
697 </td>
698 <td valign="top">
699 <ul>
700 <li><a href="$host.proxy.conf">proxy.conf</a></li>
701 <li><a href="$host.users">users</a></li>
702 </ul>
703 </td>
704 </tr>
705 </table>
706 @EOF
707
708 done
709
710 cat >> $TESTRESULTDIR/index.html <<@EOF
711 <h3>tcpdump</h3>
712 <ul>
713 @EOF
714
715 for host in $TCPDUMPHOSTS
716 do
717 cat >> $TESTRESULTDIR/index.html <<@EOF
718 <li><a href="$host.tcpdump.log">$host tcpdump.log</a></li>
719 @EOF
720 done
721
722 cat >> $TESTRESULTDIR/index.html <<@EOF
723 </ul>
724 @EOF
725
726 cat >> $TESTRESULTDIR/index.html <<@EOF
727 </td></tr>
728 </table>
729 </body>
730 </html>
731 @EOF
732
733
734 ##########################################################################
735 # execute post-test commands
736 #
737
738 echo -n "post"
739 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
740
741 eval `awk -F "::" '{
742 if ($1 !~ /^#.*/ && $2 != "")
743 {
744 printf("echo \"%s# %s\"; ", $1, $2)
745 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
746 printf("echo;\n")
747 }
748 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
749
750 ##########################################################################
751 # check that IPsec state was cleaned up properly
752 #
753
754 for host in $IPSECHOSTS
755 do
756 eval HOSTLOGIN=root@\$ipv4_${host}
757 IPSECSTATE=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm state'`
758 IPSECPOLICY=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm policy'`
759 if [ -n "$IPSECSTATE" -o -n "$IPSECPOLICY" ]
760 then
761 echo -e "\n$host# ip xfrm state [NO]" >> $CONSOLE_LOG
762 echo "$IPSECSTATE" >> $CONSOLE_LOG
763 echo -e "\n$host# ip xfrm policy [NO]" >> $CONSOLE_LOG
764 echo "$IPSECPOLICY" >> $CONSOLE_LOG
765 STATUS="failed"
766 fi
767 done
768
769
770 ##########################################################################
771 # make sure there were no leaks
772 #
773
774 for host in $STRONGSWANHOSTS
775 do
776 eval HOSTLOGIN=root@\$ipv4_${host}
777 LEAKS=`ssh $SSHCONF $HOSTLOGIN 'cat $LEAK_DETECTIVE_LOG 2>/dev/null | grep -v "No leaks detected.*"'`
778 if [ -n "$LEAKS" ]
779 then
780 echo -e "\n$host# cat $LEAK_DETECTIVE_LOG [NO]" >> $CONSOLE_LOG
781 echo "$LEAKS" >> $CONSOLE_LOG
782 echo "<<< $host $LEAK_DETECTIVE_LOG >>>" >> $CONSOLE_LOG
783 STATUS="failed"
784 fi
785 done
786
787
788 ##########################################################################
789 # get a copy of /var/log/auth.log
790 #
791
792 for host in $IPSECHOSTS
793 do
794 eval HOSTLOGIN=root@\$ipv4_${host}
795 ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv|pt-tls-client' \
796 /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
797 done
798
799
800 ##########################################################################
801 # get a copy of /var/log/daemon.log
802 #
803
804 for host in $IPSECHOSTS
805 do
806 eval HOSTLOGIN=root@\$ipv4_${host}
807 ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv' \
808 /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
809 done
810
811
812 ##########################################################################
813 # stop tcpdump if necessary
814 #
815
816 for host in $TCPDUMPHOSTS
817 do
818 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
819 then
820 stop_tcpdump $host
821 fi
822 eval HOSTLOGIN=root@\$ipv4_${host}
823 scp $SSHCONF $HOSTLOGIN:/tmp/tcpdump.log \
824 $TESTRESULTDIR/${host}.tcpdump.log > /dev/null 2>&1
825 done
826
827 ##########################################################################
828 # remove database directory if needed
829 #
830
831 for host in $DBHOSTS
832 do
833 eval HOSTLOGIN=root@\$ipv4_${host}
834 ssh $SSHCONF $HOSTLOGIN "umount $DBDIR; rm -r $DBDIR" > /dev/null 2>&1
835 done
836
837 ##########################################################################
838 # copy default host config back if necessary
839 #
840
841 $DIR/scripts/restore-defaults $testname
842
843
844 ##########################################################################
845 # set counters
846 #
847
848 if [ $STATUS = "failed" ]
849 then
850 let "failed_cnt += 1"
851 else
852 let "passed_cnt += 1"
853 fi
854
855
856 ##########################################################################
857 # write test status to html file
858 #
859 testend=$(date +%s)
860 let "testend -= teststart"
861 let "timetotal += testend"
862
863 if [ $STATUS = "passed" ]
864 then
865 COLOR="green"
866 log_status 0
867 else
868 COLOR="red"
869 log_status 1
870 fi
871
872 cat >> $TESTRESULTSHTML << @EOF
873 <tr>
874 <td>$testnumber</td>
875 <td><a href="$testname/index.html">$testname</a></td>
876 <td align="right">$testend</td>
877 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
878 </tr>
879 @EOF
880 cat >> $SUBTESTSINDEX << @EOF
881 <tr>
882 <td>$testnumber</td>
883 <td><a href="$name/index.html">$name</a></td>
884 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
885 <td>&nbsp;</td>
886 </tr>
887 @EOF
888
889
890 ##########################################################################
891 # remove any charon.pid files that still may exist
892 #
893
894 for host in $IPSECHOSTS
895 do
896 eval HOSTLOGIN=root@\$ipv4_${host}
897 ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo " removed charon.pid on `hostname`"; fi'
898 done
899
900 if [ -n "$aborted" ]
901 then
902 break 2
903 fi
904
905 done
906
907 done
908
909
910 ##############################################################################
911 # finish the results html file
912 #
913
914 cat >> $TESTRESULTSHTML << @EOF
915 <tr>
916 <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
917 </tr>
918 <tr>
919 <td><b>Passed</b></td><td><b><font color="green">$passed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
920 </tr>
921 <tr>
922 <td><b>Failed</b></td><td><b><font color="red">$failed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
923 </tr>
924 <tr>
925 <td><b>Time [s]</b></td><td><b><font color="blue">$timetotal</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
926 </tr>
927 </table>
928 </body>
929 </html>
930 @EOF
931
932 if [ $subdir_cnt != 0 ]
933 then
934 cat >> $INDEX << @EOF
935 <td align="right">$subdir_cnt</td>
936 <td>&nbsp;</td>
937 </tr>
938 @EOF
939 fi
940
941 let "all_cnt = $passed_cnt + $failed_cnt"
942
943 cat >> $INDEX << @EOF
944 <tr>
945 <td>&nbsp;</td>
946 <td><a href="all.html"><b>all</b></a></td>
947 <td align="right"><b>$all_cnt</b></td>
948 <td>&nbsp;</td>
949 </tr>
950 <tr>
951 <td><b>Failed</b></td>
952 <td>&nbsp;</td>
953 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
954 <td>&nbsp;</td>
955 </tr>
956 </table>
957 </body>
958 </html>
959 @EOF
960
961 echo
962 echo_ok "Passed : $passed_cnt"
963 echo_failed "Failed : $failed_cnt"
964
965 echo
966 echo "The results are available in $TODAYDIR"
967 echo "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
968
969 ENDDATE=`date +%Y%m%d-%H%M-%S`
970 echo
971 echo "Finished : $ENDDATE"