xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/zonechecks/tests.sh (revision 3f351f34c6d827cf017cdcff3543f6ec0c88b420)
1#!/bin/sh
2
3# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
4#
5# SPDX-License-Identifier: MPL-2.0
6#
7# This Source Code Form is subject to the terms of the Mozilla Public
8# License, v. 2.0.  If a copy of the MPL was not distributed with this
9# file, you can obtain one at https://mozilla.org/MPL/2.0/.
10#
11# See the COPYRIGHT file distributed with this work for additional
12# information regarding copyright ownership.
13
14SYSTEMTESTTOP=..
15. $SYSTEMTESTTOP/conf.sh
16
17DIGOPTS="-p ${PORT}"
18RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s"
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	$RNDCCMD 10.53.0.1 zonestatus primary.example > rndc.out.pri 2>&1
168	grep "zone not loaded" rndc.out.pri > /dev/null || break
169	sleep 1
170done
171checkfor() {
172	grep "$1" $2 > /dev/null || {
173		ret=1;
174		echo_i "missing string '$1' from '$2'"
175	}
176}
177checkfor "name: primary.example" rndc.out.pri
178checkfor "type: primary" rndc.out.pri
179checkfor "files: primary.db, primary.db.signed" rndc.out.pri
180checkfor "serial: " rndc.out.pri
181checkfor "nodes: " rndc.out.pri
182checkfor "last loaded: " rndc.out.pri
183checkfor "secure: yes" rndc.out.pri
184checkfor "inline signing: no" rndc.out.pri
185checkfor "key maintenance: automatic" rndc.out.pri
186checkfor "next key event: " rndc.out.pri
187checkfor "next resign node: " rndc.out.pri
188checkfor "next resign time: " rndc.out.pri
189checkfor "dynamic: yes" rndc.out.pri
190checkfor "frozen: no" rndc.out.pri
191for i in 0 1 2 3 4 5 6 7 8 9
192do
193	$RNDCCMD 10.53.0.2 zonestatus primary.example > rndc.out.sec 2>&1
194	grep "zone not loaded" rndc.out.sec > /dev/null || break
195	sleep 1
196done
197checkfor "name: primary.example" rndc.out.sec
198checkfor "type: secondary" rndc.out.sec
199checkfor "files: sec.db" rndc.out.sec
200checkfor "serial: " rndc.out.sec
201checkfor "nodes: " rndc.out.sec
202checkfor "next refresh: " rndc.out.sec
203checkfor "expires: " rndc.out.sec
204checkfor "secure: yes" rndc.out.sec
205for i in 0 1 2 3 4 5 6 7 8 9
206do
207	$RNDCCMD 10.53.0.1 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$RNDCCMD 10.53.0.1 reload reload.example | sed 's/^/ns1 /' | cat_i
214for i in 0 1 2 3 4 5 6 7 8 9
215do
216	$DIG $DIGOPTS reload.example SOA @10.53.0.1 > dig.out
217	grep " 2 0 0 0 0" dig.out >/dev/null && break
218	sleep 1
219done
220$RNDCCMD 10.53.0.1 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
225rndc_reload ns1 10.53.0.1 reload.example
226for i in 0 1 2 3 4 5 6 7 8 9
227do
228	$DIG $DIGOPTS reload.example SOA @10.53.0.1 > dig.out
229	grep " 3 0 0 0 0" dig.out >/dev/null && break
230	sleep 1
231done
232$RNDCCMD 10.53.0.1 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$RNDCCMD 10.53.0.1 zonestatus duplicate.example > rndc.out.duplicate 2>&1
241checkfor "zone 'duplicate.example' was found in multiple views" rndc.out.duplicate
242$RNDCCMD 10.53.0.1 zonestatus duplicate.example in primary > rndc.out.duplicate 2>&1
243checkfor "name: duplicate.example" rndc.out.duplicate
244$RNDCCMD 10.53.0.1 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 "checking 'rdnc zonestatus' with big serial value"
250ret=0
251$RNDCCMD 10.53.0.1 zonestatus bigserial.example > rndc.out.bigserial 2>&1
252checkfor "serial: 3003113544" rndc.out.bigserial
253if [ $ret != 0 ]; then echo_i "failed"; fi
254status=`expr $status + $ret`
255
256echo_i "exit status: $status"
257[ $status -eq 0 ] || exit 1
258