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