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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
|
#!/bin/bash
# Automatically execute the strongSwan test cases
#
# Copyright (C) 2004 Eric Marchionni, Patrik Rayo
# Zuercher Hochschule Winterthur
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# RCSID $Id: do-tests,v 1.20 2006/02/08 21:27:59 as Exp $
DIR=`dirname $0`
source $DIR/scripts/function.sh
[ -f $DIR/testing.conf ] || die "Configuration file 'testing.conf' not found"
[ -d $DIR/hosts ] || die "Directory 'hosts' not found"
[ -d $DIR/tests ] || die "Directory 'tests' not found"
source $DIR/testing.conf
##############################################################################
# test if UMLs have been built at all
#
[ -d $BUILDDIR ] || die "Directory '$BUILDDIR' does not exist. Please run 'make-testing'first."
##############################################################################
# take care of new path and file variables
#
[ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
TESTDATE=`date +%Y%m%d-%H%M`
TODAYDIR=$TESTRESULTSDIR/$TESTDATE
mkdir $TODAYDIR
TESTRESULTSHTML=$TODAYDIR/index.html
ALLHTML=$TODAYDIR/all.html
DEFAULTTESTSDIR=$UMLTESTDIR/testing/tests
testnumber="0"
failed_cnt="0"
passed_cnt="0"
##############################################################################
# copy default tests to $BUILDDIR
#
TESTSDIR=$BUILDDIR/tests
[ -d $TESTSDIR ] || mkdir $TESTSDIR
##############################################################################
# assign IP for each host to hostname
#
for host in $STRONGSWANHOSTS
do
eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
case $host in
moon)
eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
;;
sun)
eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
;;
alice)
;;
venus)
;;
bob)
;;
carol)
eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
;;
dave)
eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
;;
winnetou)
;;
esac
done
##############################################################################
# create header for the results html file
#
KERNEL_VERSION=`basename $KERNEL .tar.bz2`
IPSEC_VERSION=`basename $STRONGSWAN .tar.bz2`
cat > $TESTRESULTSHTML <<@EOF
<html>
<head>
<title>strongSwan UML Testing</title>
</head>
<body>
<h2>strongSwan UML Testing</h2>
<table border="0" cellspacing="2">
<tr><td><b>Host:</b></td><td>`uname -a`</td></tr>
<tr><td><b>UML kernel: </b></td><td>$KERNEL_VERSION</td></tr>
<tr><td><b>IPsec:</b></td><td>$IPSEC_VERSION</td></tr>
<tr><td><b>Date:</b></td><td>$TESTDATE</td></tr>
</table>
<p>
<table border="0" width="500">
<thead align="left"><th>Number</th><th>Test</th><th>Result</th></thead>
@EOF
cat > $ALLHTML <<@EOF
<html>
<head>
<title>strongSwan UML Testing</title>
</head>
<body>
<h2>strongSwan UML Testing</h2>
<table border="0" cellspacing="2">
<tr><td><b>Host:</b></td><td>`uname -a`</td></tr>
<tr><td><b>UML kernel: </b></td><td>$KERNEL_VERSION</td></tr>
<tr><td><b>IPsec:</b></td><td>$IPSEC_VERSION</td></tr>
<tr><td><b>Date:</b></td><td>$TESTDATE</td></tr>
<tr><td colspan="2"> </td></tr>
@EOF
cecho "UML kernel: $KERNEL_VERSION"
cecho "IPsec: $IPSEC_VERSION"
cecho "Date: $TESTDATE"
cecho ""
##############################################################################
# enter specific test directory
#
if [ $# -gt 0 ]
then
TESTS=$*
elif [ $SELECTEDTESTSONLY = "yes" ]
then
# set internal field seperator
TESTS=$SELECTEDTESTS
else
# set internal field seperator
TESTS="`ls $DEFAULTTESTSDIR`"
fi
for SUBDIR in $TESTS
do
SUBTESTS="`basename $SUBDIR`"
if [ $SUBTESTS = $SUBDIR ]
then
SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
else
SUBDIR="`dirname $SUBDIR`"
fi
if [ ! -d $TODAYDIR/$SUBDIR ]
then
mkdir $TODAYDIR/$SUBDIR
echo "<tr><td> </td><td><a href=\"$SUBDIR\">$SUBDIR</a></td>" >> $ALLHTML
fi
for name in $SUBTESTS
do
let "testnumber += 1"
testname=$SUBDIR/$name
cecho-n " $testnumber $testname.."
if [ ! -d $DEFAULTTESTSDIR/${testname} ]
then
cecho "is missing..skipped"
continue
fi
[ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
[ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
[ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
[ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
[ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
TESTRESULTDIR=$TODAYDIR/$testname
mkdir -p $TESTRESULTDIR
CONSOLE_LOG=$TESTRESULTDIR/console.log
touch $CONSOLE_LOG
TESTDIR=$TESTSDIR/${testname}
rm -rf $TESTDIR
mkdir -p $TESTDIR
cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
##############################################################################
# replace IP wildcards with actual IPv4 and IPv6 addresses
#
for host in $STRONGSWANHOSTS
do
case $host in
moon)
searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
;;
sun)
searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
;;
alice)
searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
;;
venus)
searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
;;
bob)
searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
;;
carol)
searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
;;
dave)
searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
;;
winnetou)
searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
;;
esac
done
##########################################################################
# copy test specific configurations to uml hosts and clear auth.log files
#
$DIR/scripts/load-testconfig $testname
source $TESTDIR/test.conf
##########################################################################
# run tcpdump in the background
#
if [ "$TCPDUMPHOSTS" != "" ]
then
echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
for host_iface in $TCPDUMPHOSTS
do
host=`echo $host_iface | awk -F ":" '{print $1}'`
iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain and not arp > /tmp/tcpdump.log 2>&1 &"
echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
ssh root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
eval TDUP_${host}="true"
done
fi
##########################################################################
# execute pre-test commands
#
cecho-n "pre.."
echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
eval `awk -F "::" '{
if ($2 != "")
{
printf("echo \"%s# %s\"; ", $1, $2)
printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
printf("echo;\n")
}
}' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
##########################################################################
# stop tcpdump
#
function stop_tcpdump {
echo "${1}# killall tcpdump" >> $CONSOLE_LOG
eval ssh root@\$ipv4_${1} killall tcpdump
eval TDUP_${1}="false"
echo ""
}
##########################################################################
# get and evaluate test results
#
cecho-n "test.."
echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
STATUS="passed"
eval `awk -F "::" '{
host=$1
command=$2
pattern=$3
hit=$4
if (command != "")
{
if (command == "tcpdump")
{
printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
printf("ssh root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
}
else
{
printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
printf("ssh root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
}
printf("cmd_exit=\044?; ")
printf("echo; ")
printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
printf("; then STATUS=\"failed\"; fi; \n")
}
}' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
##########################################################################
# set counters
#
if [ $STATUS = "failed" ]
then
let "failed_cnt += 1"
else
let "passed_cnt += 1"
fi
##########################################################################
# log statusall and listall output
# get copies of ipsec.conf, ipsec.secrets
# create index.html for the given test case
cat > $TESTRESULTDIR/index.html <<@EOF
<html>
<head>
<title>Test $testname</title>
</head>
<body>
<table border="0" width="600">
<tr><td>
<h2>Test $testname</h2>
<h3>Description</h3>
@EOF
cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
cat >> $TESTRESULTDIR/index.html <<@EOF
<ul>
<li><a href="console.log">console.log</a></li>
</ul>
<img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
@EOF
for host in $IPSECHOSTS
do
eval HOSTLOGIN=root@\$ipv4_${host}
for command in statusall listall
do
ssh $HOSTLOGIN ipsec $command \
> $TESTRESULTDIR/${host}.$command 2>/dev/null
done
for file in ipsec.conf ipsec.secrets
do
scp $HOSTLOGIN:/etc/$file \
$TESTRESULTDIR/${host}.$file > /dev/null 2>&1
done
ssh $HOSTLOGIN ip route list \
> $TESTRESULTDIR/${host}.iproute 2>/dev/null
ssh $HOSTLOGIN iptables -v -n -L \
> $TESTRESULTDIR/${host}.iptables 2>/dev/null
cat >> $TESTRESULTDIR/index.html <<@EOF
<h3>$host</h3>
<table border="0" cellspacing="0" width="400">
<tr>
<td>
<ul>
<li><a href="$host.ipsec.conf">ipsec.conf</a></li>
<li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
<li><a href="$host.statusall">ipsec statusall</a></li>
<li><a href="$host.listall">ipsec listall</a></li>
</ul>
</td>
<td>
<ul>
<li><a href="$host.auth.log">auth.log</a></li>
<li><a href="$host.daemon.log">daemon.log</a></li>
<li><a href="$host.iproute">ip route list</a></li>
<li><a href="$host.iptables">iptables -L</a></li>
</ul>
</td>
</tr>
</table>
@EOF
done
cat >> $TESTRESULTDIR/index.html <<@EOF
</td></tr>
<tr><td align="right">
<b><a href="../index.html">Back</a></b>
</td></tr>
</table>
</body>
</html>
@EOF
##########################################################################
# execute post-test commands
#
cecho-n "post.."
echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
eval `awk -F "::" '{
if ($2 != "")
{
printf("echo \"%s# %s\"; ", $1, $2)
printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
printf("echo;\n")
}
}' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
##########################################################################
# get a copy of /var/log/auth.log
#
for host in $IPSECHOSTS
do
eval HOSTLOGIN=root@\$ipv4_${host}
ssh $HOSTLOGIN grep pluto /var/log/auth.log \
> $TESTRESULTDIR/${host}.auth.log
echo >> $TESTRESULTDIR/${host}.auth.log
ssh $HOSTLOGIN grep charon /var/log/auth.log \
>> $TESTRESULTDIR/${host}.auth.log
done
##########################################################################
# get a copy of /var/log/daemon.log
#
for host in $IPSECHOSTS
do
eval HOSTLOGIN=root@\$ipv4_${host}
ssh $HOSTLOGIN grep pluto /var/log/daemon.log \
> $TESTRESULTDIR/${host}.daemon.log
echo >> $TESTRESULTDIR/${host}.daemon.log
ssh $HOSTLOGIN grep charon /var/log/daemon.log \
>> $TESTRESULTDIR/${host}.daemon.log
done
##########################################################################
# stop tcpdump if necessary
#
for host in $TCPDUMPHOSTS
do
if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
then
echo "${host}# killall tcpdump" >> $CONSOLE_LOG
eval ssh root@\$ipv4_$host killall tcpdump
eval TDUP_${host}="false"
fi
done
##########################################################################
# copy default host config back if necessary
#
$DIR/scripts/restore-defaults $testname
##########################################################################
# write test status to html file
#
cecho "$STATUS"
if [ $STATUS = "passed" ]
then
COLOR="green"
else
COLOR="red"
fi
cat >> $TESTRESULTSHTML << @EOF
<tr>
<td>$testnumber</td>
<td><a href="$testname/">$testname</a></td>
<td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
</tr>
@EOF
done
done
##############################################################################
# finish the results html file
#
cat >> $TESTRESULTSHTML << @EOF
</table>
<p>
<b>Passed: $passed_cnt</b><br>
<b>Failed: $failed_cnt</b><br>
<p>
</body>
</html>
@EOF
cat >> $ALLHTML << @EOF
</table>
</body>
</html>
@EOF
cecho ""
cecho "Passed: $passed_cnt"
cecho "Failed: $failed_cnt"
cecho ""
##############################################################################
# copy the test results to the apache server
#
HTDOCS="/var/www/localhost/htdocs"
cecho-n "Copying test results to winnetou.."
ssh root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
scp -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
ssh root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
cecho "done"
cecho ""
cecho "The results are available in $TODAYDIR"
cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
|