xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/zonechecks/tests.sh (revision d90047b5d07facf36e6c01dcc0bded8997ce9cc2)
1#!/bin/sh
2#
3# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
4#
5# This Source Code Form is subject to the terms of the Mozilla Public
6# License, v. 2.0. If a copy of the MPL was not distributed with this
7# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8#
9# See the COPYRIGHT file distributed with this work for additional
10# information regarding copyright ownership.
11
12SYSTEMTESTTOP=..
13. $SYSTEMTESTTOP/conf.sh
14
15DIGOPTS="-p ${PORT}"
16RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s"
17
18status=0
19
20#
21echo_i "checking that we detect a NS which refers to a CNAME"
22if $CHECKZONE . cname.db > cname.out 2>&1
23then
24	echo_i "failed (status)"; status=`expr $status + 1`
25else
26	if grep "is a CNAME" cname.out > /dev/null
27	then
28		:
29	else
30		echo_i "failed (message)"; status=`expr $status + 1`
31	fi
32fi
33
34#
35echo_i "checking that we detect a NS which is below a DNAME"
36if $CHECKZONE . dname.db > dname.out 2>&1
37then
38	echo_i "failed (status)"; status=`expr $status + 1`
39else
40	if grep "is below a DNAME" dname.out > /dev/null
41	then
42		:
43	else
44		echo_i "failed (message)"; status=`expr $status + 1`
45	fi
46fi
47
48#
49echo_i "checking that we detect a NS which has no address records (A/AAAA)"
50if $CHECKZONE . noaddress.db > noaddress.out
51then
52	echo_i "failed (status)"; status=`expr $status + 1`
53else
54	if grep "has no address records" noaddress.out > /dev/null
55	then
56		:
57	else
58		echo_i "failed (message)"; status=`expr $status + 1`
59	fi
60fi
61
62#
63echo_i "checking that we detect a NS which has no records"
64if $CHECKZONE . nxdomain.db > nxdomain.out
65then
66	echo_i "failed (status)"; status=`expr $status + 1`
67else
68	if grep "has no address records" noaddress.out > /dev/null
69	then
70		:
71	else
72		echo_i "failed (message)"; status=`expr $status + 1`
73	fi
74fi
75
76#
77echo_i "checking that we detect a NS which looks like a A record (fail)"
78if $CHECKZONE -n fail . a.db > a.out 2>&1
79then
80	echo_i "failed (status)"; status=`expr $status + 1`
81else
82	if grep "appears to be an address" a.out > /dev/null
83	then
84		:
85	else
86		echo_i "failed (message)"; status=`expr $status + 1`
87	fi
88fi
89
90#
91echo_i "checking that we detect a NS which looks like a A record (warn=default)"
92if $CHECKZONE . a.db > a.out 2>&1
93then
94	if grep "appears to be an address" a.out > /dev/null
95	then
96		:
97	else
98		echo_i "failed (message)"; status=`expr $status + 1`
99	fi
100else
101	echo_i "failed (status)"; status=`expr $status + 1`
102fi
103
104#
105echo_i "checking that we detect a NS which looks like a A record (ignore)"
106if $CHECKZONE -n ignore . a.db > a.out 2>&1
107then
108	if grep "appears to be an address" a.out > /dev/null
109	then
110		echo_i "failed (message)"; status=`expr $status + 1`
111	else
112		:
113	fi
114else
115	echo_i "failed (status)"; status=`expr $status + 1`
116fi
117
118#
119echo_i "checking that we detect a NS which looks like a AAAA record (fail)"
120if $CHECKZONE -n fail . aaaa.db > aaaa.out 2>&1
121then
122	echo_i "failed (status)"; status=`expr $status + 1`
123else
124	if grep "appears to be an address" aaaa.out > /dev/null
125	then
126		:
127	else
128		echo_i "failed (message)"; status=`expr $status + 1`
129	fi
130fi
131
132#
133echo_i "checking that we detect a NS which looks like a AAAA record (warn=default)"
134if $CHECKZONE . aaaa.db > aaaa.out 2>&1
135then
136	if grep "appears to be an address" aaaa.out > /dev/null
137	then
138		:
139	else
140		echo_i "failed (message)"; status=`expr $status + 1`
141	fi
142else
143	echo_i "failed (status)"; status=`expr $status + 1`
144fi
145
146#
147echo_i "checking that we detect a NS which looks like a AAAA record (ignore)"
148if $CHECKZONE -n ignore . aaaa.db > aaaa.out 2>&1
149then
150	if grep "appears to be an address" aaaa.out > /dev/null
151	then
152		echo_i "failed (message)"; status=`expr $status + 1`
153	else
154		:
155	fi
156else
157	echo_i "failed (status)"; status=`expr $status + 1`
158fi
159
160#
161echo_i "checking 'rdnc zonestatus' output"
162ret=0
163for i in 0 1 2 3 4 5 6 7 8 9
164do
165	$RNDCCMD 10.53.0.1 zonestatus master.example > rndc.out.master 2>&1
166	grep "zone not loaded" rndc.out.master > /dev/null || break
167	sleep 1
168done
169checkfor() {
170	grep "$1" $2 > /dev/null || {
171		ret=1;
172		echo_i "missing string '$1' from '$2'"
173	}
174}
175checkfor "name: master.example" rndc.out.master
176checkfor "type: master" rndc.out.master
177checkfor "files: master.db, master.db.signed" rndc.out.master
178checkfor "serial: " rndc.out.master
179checkfor "nodes: " rndc.out.master
180checkfor "last loaded: " rndc.out.master
181checkfor "secure: yes" rndc.out.master
182checkfor "inline signing: no" rndc.out.master
183checkfor "key maintenance: automatic" rndc.out.master
184checkfor "next key event: " rndc.out.master
185checkfor "next resign node: " rndc.out.master
186checkfor "next resign time: " rndc.out.master
187checkfor "dynamic: yes" rndc.out.master
188checkfor "frozen: no" rndc.out.master
189for i in 0 1 2 3 4 5 6 7 8 9
190do
191	$RNDCCMD 10.53.0.2 zonestatus master.example > rndc.out.slave 2>&1
192	grep "zone not loaded" rndc.out.slave > /dev/null || break
193	sleep 1
194done
195checkfor "name: master.example" rndc.out.slave
196checkfor "type: slave" rndc.out.slave
197checkfor "files: slave.db" rndc.out.slave
198checkfor "serial: " rndc.out.slave
199checkfor "nodes: " rndc.out.slave
200checkfor "next refresh: " rndc.out.slave
201checkfor "expires: " rndc.out.slave
202checkfor "secure: yes" rndc.out.slave
203for i in 0 1 2 3 4 5 6 7 8 9
204do
205	$RNDCCMD 10.53.0.1 zonestatus reload.example > rndc.out.prereload 2>&1
206	grep "zone not loaded" rndc.out.prereload > /dev/null || break
207	sleep 1
208done
209checkfor "files: reload.db, soa.db$" rndc.out.prereload
210echo "@ 0 SOA . . 2 0 0 0 0" > ns1/soa.db
211$RNDCCMD 10.53.0.1 reload reload.example | sed 's/^/ns1 /' | cat_i
212for i in 0 1 2 3 4 5 6 7 8 9
213do
214	$DIG $DIGOPTS reload.example SOA @10.53.0.1 > dig.out
215	grep " 2 0 0 0 0" dig.out >/dev/null && break
216	sleep 1
217done
218$RNDCCMD 10.53.0.1 zonestatus reload.example > rndc.out.postreload 2>&1
219checkfor "files: reload.db, soa.db$" rndc.out.postreload
220sleep 1
221echo "@ 0 SOA . . 3 0 0 0 0" > ns1/reload.db
222echo "@ 0 NS ." >> ns1/reload.db
223rndc_reload ns1 10.53.0.1 reload.example
224for i in 0 1 2 3 4 5 6 7 8 9
225do
226	$DIG $DIGOPTS reload.example SOA @10.53.0.1 > dig.out
227	grep " 3 0 0 0 0" dig.out >/dev/null && break
228	sleep 1
229done
230$RNDCCMD 10.53.0.1 zonestatus reload.example > rndc.out.removeinclude 2>&1
231checkfor "files: reload.db$" rndc.out.removeinclude
232
233if [ $ret != 0 ]; then echo_i "failed"; fi
234status=`expr $status + $ret`
235
236echo_i "checking 'rdnc zonestatus' with duplicated zone name"
237ret=0
238$RNDCCMD 10.53.0.1 zonestatus duplicate.example > rndc.out.duplicate 2>&1
239checkfor "zone 'duplicate.example' was found in multiple views" rndc.out.duplicate
240$RNDCCMD 10.53.0.1 zonestatus duplicate.example in primary > rndc.out.duplicate 2>&1
241checkfor "name: duplicate.example" rndc.out.duplicate
242$RNDCCMD 10.53.0.1 zonestatus nosuchzone.example > rndc.out.duplicate 2>&1
243checkfor "no matching zone 'nosuchzone.example' in any view" rndc.out.duplicate
244if [ $ret != 0 ]; then echo_i "failed"; fi
245status=`expr $status + $ret`
246
247echo_i "checking 'rdnc zonestatus' with big serial value"
248ret=0
249$RNDCCMD 10.53.0.1 zonestatus bigserial.example > rndc.out.bigserial 2>&1
250checkfor "serial: 3003113544" rndc.out.bigserial
251if [ $ret != 0 ]; then echo_i "failed"; fi
252status=`expr $status + $ret`
253
254echo_i "exit status: $status"
255[ $status -eq 0 ] || exit 1
256