1#!/bin/sh
2#
3# Copyright (C) 2004, 2007, 2011, 2012  Internet Systems Consortium, Inc. ("ISC")
4# Copyright (C) 2000, 2001  Internet Software Consortium.
5#
6# Permission to use, copy, modify, and/or distribute this software for any
7# purpose with or without fee is hereby granted, provided that the above
8# copyright notice and this permission notice appear in all copies.
9#
10# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16# PERFORMANCE OF THIS SOFTWARE.
17
18# Id: tests.sh,v 1.13 2011/10/13 22:18:05 marka Exp  
19
20# ns1 = stealth master
21# ns2 = slave with update forwarding disabled; not currently used
22# ns3 = slave with update forwarding enabled
23
24SYSTEMTESTTOP=..
25. $SYSTEMTESTTOP/conf.sh
26
27status=0
28
29
30echo "I:waiting for servers to be ready for testing"
31for i in 1 2 3 4 5 6 7 8 9 10
32do
33	ret=0
34	$DIG +tcp example. @10.53.0.1 soa -p 5300 > dig.out.ns1 || ret=1
35	grep "status: NOERROR" dig.out.ns1 > /dev/null ||  ret=1
36	$DIG +tcp example. @10.53.0.2 soa -p 5300 > dig.out.ns2 || ret=1
37	grep "status: NOERROR" dig.out.ns2 > /dev/null ||  ret=1
38	$DIG +tcp example. @10.53.0.3 soa -p 5300 > dig.out.ns3 || ret=1
39	grep "status: NOERROR" dig.out.ns3 > /dev/null ||  ret=1
40	test $ret = 0 && break
41	sleep 1
42done
43echo "I:fetching master copy of zone before update"
44$DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.\
45	@10.53.0.1 axfr -p 5300 > dig.out.ns1 || status=1
46
47echo "I:fetching slave 1 copy of zone before update"
48$DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.\
49	@10.53.0.2 axfr -p 5300 > dig.out.ns2 || status=1
50
51echo "I:fetching slave 2 copy of zone before update"
52$DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.\
53	@10.53.0.3 axfr -p 5300 > dig.out.ns3 || status=1
54
55echo "I:comparing pre-update copies to known good data"
56$PERL ../digcomp.pl knowngood.before dig.out.ns1 || status=1
57$PERL ../digcomp.pl knowngood.before dig.out.ns2 || status=1
58$PERL ../digcomp.pl knowngood.before dig.out.ns3 || status=1
59
60echo "I:updating zone (signed)"
61$NSUPDATE -y update.example:c3Ryb25nIGVub3VnaCBmb3IgYSBtYW4gYnV0IG1hZGUgZm9yIGEgd29tYW4K -- - <<EOF || status=1
62server 10.53.0.3 5300
63update add updated.example. 600 A 10.10.10.1
64update add updated.example. 600 TXT Foo
65send
66EOF
67
68echo "I:sleeping 15 seconds for server to incorporate changes"
69sleep 15
70
71echo "I:fetching master copy of zone after update"
72$DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.\
73	@10.53.0.1 axfr -p 5300 > dig.out.ns1 || status=1
74
75echo "I:fetching slave 1 copy of zone after update"
76$DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.\
77	@10.53.0.2 axfr -p 5300 > dig.out.ns2 || status=1
78
79echo "I:fetching slave 2 copy of zone after update"
80$DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.\
81	@10.53.0.3 axfr -p 5300 > dig.out.ns3 || status=1
82
83echo "I:comparing post-update copies to known good data"
84$PERL ../digcomp.pl knowngood.after1 dig.out.ns1 || status=1
85$PERL ../digcomp.pl knowngood.after1 dig.out.ns2 || status=1
86$PERL ../digcomp.pl knowngood.after1 dig.out.ns3 || status=1
87
88echo "I:updating zone (unsigned)"
89$NSUPDATE -- - <<EOF || status=1
90server 10.53.0.3 5300
91update add unsigned.example. 600 A 10.10.10.1
92update add unsigned.example. 600 TXT Foo
93send
94EOF
95
96echo "I:sleeping 15 seconds for server to incorporate changes"
97sleep 15
98
99echo "I:fetching master copy of zone after update"
100$DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.\
101	@10.53.0.1 axfr -p 5300 > dig.out.ns1 || status=1
102
103echo "I:fetching slave 1 copy of zone after update"
104$DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.\
105	@10.53.0.2 axfr -p 5300 > dig.out.ns2 || status=1
106
107echo "I:fetching slave 2 copy of zone after update"
108$DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.\
109	@10.53.0.3 axfr -p 5300 > dig.out.ns3 || status=1
110
111echo "I:comparing post-update copies to known good data"
112$PERL ../digcomp.pl knowngood.after2 dig.out.ns1 || status=1
113$PERL ../digcomp.pl knowngood.after2 dig.out.ns2 || status=1
114$PERL ../digcomp.pl knowngood.after2 dig.out.ns3 || status=1
115
116echo "I:checking update forwarding to dead master"
117count=0
118ret=0
119while [ $count -lt 5 -a $ret -eq 0 ]
120do
121(
122$NSUPDATE -- - <<EOF 
123server 10.53.0.3 5300
124zone nomaster
125update add unsigned.nomaster. 600 A 10.10.10.1
126update add unsigned.nomaster. 600 TXT Foo
127send
128EOF
129) > /dev/null 2>&1 &
130	$DIG +notcp +noadd +noauth nomaster.\
131		@10.53.0.3 soa -p 5300 > dig.out.ns3 || ret=1
132	grep "status: NOERROR" dig.out.ns3 > /dev/null || ret=1
133	count=`expr $count + 1`
134done
135if [ $ret != 0 ] ; then echo "I:failed"; status=`expr $status + $ret`; fi
136
137echo "I:exit status: $status"
138exit $status
139