1#!/bin/sh
2#
3# Copyright (C) 2004, 2007, 2009, 2012-2014  Internet Systems Consortium, Inc. ("ISC")
4#
5# Permission to use, copy, modify, and/or distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15# PERFORMANCE OF THIS SOFTWARE.
16
17SYSTEMTESTTOP=..
18. $SYSTEMTESTTOP/conf.sh
19
20status=0
21
22#
23echo "I: checking that we detect a NS which refers to a CNAME"
24if $CHECKZONE . cname.db > cname.out 2>&1
25then
26	echo "I:failed (status)"; status=`expr $status + 1`
27else
28	if grep "is a CNAME" cname.out > /dev/null
29	then
30		:
31	else
32		echo "I:failed (message)"; status=`expr $status + 1`
33	fi
34fi
35
36#
37echo "I: checking that we detect a NS which is below a DNAME"
38if $CHECKZONE . dname.db > dname.out 2>&1
39then
40	echo "I:failed (status)"; status=`expr $status + 1`
41else
42	if grep "is below a DNAME" dname.out > /dev/null
43	then
44		:
45	else
46		echo "I:failed (message)"; status=`expr $status + 1`
47	fi
48fi
49
50#
51echo "I: checking that we detect a NS which has no address records (A/AAAA)"
52if $CHECKZONE . noaddress.db > noaddress.out
53then
54	echo "I:failed (status)"; status=`expr $status + 1`
55else
56	if grep "has no address records" noaddress.out > /dev/null
57	then
58		:
59	else
60		echo "I:failed (message)"; status=`expr $status + 1`
61	fi
62fi
63
64#
65echo "I: checking that we detect a NS which has no records"
66if $CHECKZONE . nxdomain.db > nxdomain.out
67then
68	echo "I:failed (status)"; status=`expr $status + 1`
69else
70	if grep "has no address records" noaddress.out > /dev/null
71	then
72		:
73	else
74		echo "I:failed (message)"; status=`expr $status + 1`
75	fi
76fi
77
78#
79echo "I: checking that we detect a NS which looks like a A record (fail)"
80if $CHECKZONE -n fail . a.db > a.out 2>&1
81then
82	echo "I:failed (status)"; status=`expr $status + 1`
83else
84	if grep "appears to be an address" a.out > /dev/null
85	then
86		:
87	else
88		echo "I:failed (message)"; status=`expr $status + 1`
89	fi
90fi
91
92#
93echo "I: checking that we detect a NS which looks like a A record (warn=default)"
94if $CHECKZONE . a.db > a.out 2>&1
95then
96	if grep "appears to be an address" a.out > /dev/null
97	then
98		:
99	else
100		echo "I:failed (message)"; status=`expr $status + 1`
101	fi
102else
103	echo "I:failed (status)"; status=`expr $status + 1`
104fi
105
106#
107echo "I: checking that we detect a NS which looks like a A record (ignore)"
108if $CHECKZONE -n ignore . a.db > a.out 2>&1
109then
110	if grep "appears to be an address" a.out > /dev/null
111	then
112		echo "I:failed (message)"; status=`expr $status + 1`
113	else
114		:
115	fi
116else
117	echo "I:failed (status)"; status=`expr $status + 1`
118fi
119
120#
121echo "I: checking that we detect a NS which looks like a AAAA record (fail)"
122if $CHECKZONE -n fail . aaaa.db > aaaa.out 2>&1
123then
124	echo "I:failed (status)"; status=`expr $status + 1`
125else
126	if grep "appears to be an address" aaaa.out > /dev/null
127	then
128		:
129	else
130		echo "I:failed (message)"; status=`expr $status + 1`
131	fi
132fi
133
134#
135echo "I: checking that we detect a NS which looks like a AAAA record (warn=default)"
136if $CHECKZONE . aaaa.db > aaaa.out 2>&1
137then
138	if grep "appears to be an address" aaaa.out > /dev/null
139	then
140		:
141	else
142		echo "I:failed (message)"; status=`expr $status + 1`
143	fi
144else
145	echo "I:failed (status)"; status=`expr $status + 1`
146fi
147
148#
149echo "I: checking that we detect a NS which looks like a AAAA record (ignore)"
150if $CHECKZONE -n ignore . aaaa.db > aaaa.out 2>&1
151then
152	if grep "appears to be an address" aaaa.out > /dev/null
153	then
154		echo "I:failed (message)"; status=`expr $status + 1`
155	else
156		:
157	fi
158else
159	echo "I:failed (status)"; status=`expr $status + 1`
160fi
161
162#
163echo "I: checking 'rdnc zonestatus' output"
164ret=0
165for i in 0 1 2 3 4 5 6 7 8 9
166do
167	$RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 zonestatus master.example > rndc.out.master 2>&1
168	grep "zone not loaded" rndc.out.master > /dev/null || break
169	sleep 1
170done
171checkfor() {
172	grep "$1" $2 > /dev/null || {
173		ret=1;
174		echo "I: missing '$1' from '$2'"
175	}
176}
177checkfor "name: master.example" rndc.out.master
178checkfor "type: master" rndc.out.master
179checkfor "files: master.db, master.db.signed" rndc.out.master
180checkfor "serial: " rndc.out.master
181checkfor "nodes: " rndc.out.master
182checkfor "last loaded: " rndc.out.master
183checkfor "secure: yes" rndc.out.master
184checkfor "inline signing: no" rndc.out.master
185checkfor "key maintenance: automatic" rndc.out.master
186checkfor "next key event: " rndc.out.master
187checkfor "next resign node: " rndc.out.master
188checkfor "next resign time: " rndc.out.master
189checkfor "dynamic: yes" rndc.out.master
190checkfor "frozen: no" rndc.out.master
191for i in 0 1 2 3 4 5 6 7 8 9
192do
193	$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 zonestatus master.example > rndc.out.slave 2>&1
194	grep "zone not loaded" rndc.out.slave > /dev/null || break
195	sleep 1
196done
197checkfor "name: master.example" rndc.out.slave
198checkfor "type: slave" rndc.out.slave
199checkfor "files: slave.db" rndc.out.slave
200checkfor "serial: " rndc.out.slave
201checkfor "nodes: " rndc.out.slave
202checkfor "next refresh: " rndc.out.slave
203checkfor "expires: " rndc.out.slave
204checkfor "secure: yes" rndc.out.slave
205for i in 0 1 2 3 4 5 6 7 8 9
206do
207	$RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 zonestatus reload.example > rndc.out.prereload 2>&1
208	grep "zone not loaded" rndc.out.prereload > /dev/null || break
209	sleep 1
210done
211checkfor "files: reload.db, soa.db$" rndc.out.prereload
212echo "@ 0 SOA . . 2 0 0 0 0" > ns1/soa.db
213$RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 reload reload.example
214for i in 0 1 2 3 4 5 6 7 8 9
215do
216	$DIG reload.example SOA @10.53.0.1 -p 5300 > dig.out
217	grep " 2 0 0 0 0" dig.out >/dev/null && break
218	sleep 1
219done
220$RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 zonestatus reload.example > rndc.out.postreload 2>&1
221checkfor "files: reload.db, soa.db$" rndc.out.postreload
222sleep 1
223echo "@ 0 SOA . . 3 0 0 0 0" > ns1/reload.db
224echo "@ 0 NS ." >> ns1/reload.db
225$RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 reload reload.example
226for i in 0 1 2 3 4 5 6 7 8 9
227do
228	$DIG reload.example SOA @10.53.0.1 -p 5300 > dig.out
229	grep " 3 0 0 0 0" dig.out >/dev/null && break
230	sleep 1
231done
232$RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 zonestatus reload.example > rndc.out.removeinclude 2>&1
233checkfor "files: reload.db$" rndc.out.removeinclude
234
235if [ $ret != 0 ]; then echo "I:failed"; fi
236status=`expr $status + $ret`
237
238echo "I: checking 'rdnc zonestatus' with duplicated zone name"
239ret=0
240$RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 zonestatus duplicate.example > rndc.out.duplicate 2>&1
241checkfor "zone 'duplicate.example' was found in multiple views" rndc.out.duplicate
242$RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 zonestatus duplicate.example in primary > rndc.out.duplicate 2>&1
243checkfor "name: duplicate.example" rndc.out.duplicate
244$RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 zonestatus nosuchzone.example > rndc.out.duplicate 2>&1
245checkfor "no matching zone 'nosuchzone.example' in any view" rndc.out.duplicate
246if [ $ret != 0 ]; then echo "I:failed"; fi
247status=`expr $status + $ret`
248
249echo "I:exit status: $status"
250exit $status
251