xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/checkzone/tests.sh (revision 734a9f3d6cd20770d53d02e90be56c0051c48e5f)
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
14set -e
15
16. ../conf.sh
17
18status=0
19n=1
20
21for db in zones/good*.db; do
22  echo_i "checking $db ($n)"
23  ret=0
24  case $db in
25    zones/good-gc-msdcs.db | zones/good-spf-exception.db)
26      $CHECKZONE -k fail -i local example $db >test.out.$n 2>&1 || ret=1
27      ;;
28    zones/good-dns-sd-reverse.db)
29      $CHECKZONE -k fail -i local 0.0.0.0.in-addr.arpa $db >test.out.$n 2>&1 || ret=1
30      ;;
31    *)
32      $CHECKZONE -i local example $db >test.out.$n 2>&1 || ret=1
33      ;;
34  esac
35  n=$((n + 1))
36  if [ $ret != 0 ]; then echo_i "failed"; fi
37  status=$((status + ret))
38done
39
40for db in zones/bad*.db; do
41  echo_i "checking $db ($n)"
42  ret=0 v=0
43  case $db in
44    zones/bad-dns-sd-reverse.db | zones/bad-svcb-servername.db)
45      $CHECKZONE -k fail -i local 0.0.0.0.in-addr.arpa $db >test.out.$n 2>&1 || v=$?
46      ;;
47    *)
48      $CHECKZONE -i local example $db >test.out.$n 2>&1 || v=$?
49      ;;
50  esac
51  test $v = 1 || ret=1
52  n=$((n + 1))
53  if [ $ret != 0 ]; then echo_i "failed"; fi
54  status=$((status + ret))
55done
56
57echo_i "checking with journal file ($n)"
58ret=0
59$CHECKZONE -D -o test.orig.db test zones/test1.db >/dev/null 2>&1 || ret=1
60$CHECKZONE -D -o test.changed.db test zones/test2.db >/dev/null 2>&1 || ret=1
61$MAKEJOURNAL test test.orig.db test.changed.db test.orig.db.jnl 2>&1 || ret=1
62jlines=$($JOURNALPRINT test.orig.db.jnl | wc -l)
63[ $jlines = 3 ] || ret=1
64$CHECKZONE -D -j -o test.out1.db test test.orig.db >/dev/null 2>&1 || ret=1
65cmp -s test.changed.db test.out1.db || ret=1
66mv -f test.orig.db.jnl test.journal
67$CHECKZONE -D -J test.journal -o test.out2.db test test.orig.db >/dev/null 2>&1 || ret=1
68cmp -s test.changed.db test.out2.db || ret=1
69n=$((n + 1))
70if [ $ret != 0 ]; then echo_i "failed"; fi
71status=$((status + ret))
72
73echo_i "checking with spf warnings ($n)"
74ret=0
75$CHECKZONE example zones/spf.db >test.out1.$n 2>&1 || ret=1
76$CHECKZONE -T ignore example zones/spf.db >test.out2.$n 2>&1 || ret=1
77grep "'x.example' found type SPF" test.out1.$n >/dev/null && ret=1
78grep "'y.example' found type SPF" test.out1.$n >/dev/null || ret=1
79grep "'example' found type SPF" test.out1.$n >/dev/null && ret=1
80grep "'x.example' found type SPF" test.out2.$n >/dev/null && ret=1
81grep "'y.example' found type SPF" test.out2.$n >/dev/null && ret=1
82grep "'example' found type SPF" test.out2.$n >/dev/null && ret=1
83n=$((n + 1))
84if [ $ret != 0 ]; then echo_i "failed"; fi
85status=$((status + ret))
86
87echo_i "checking with max ttl (text) ($n)"
88ret=0
89$CHECKZONE -i local -l 300 example zones/good1.db >test.out1.$n 2>&1 && ret=1
90$CHECKZONE -i local -l 600 example zones/good1.db >test.out2.$n 2>&1 || ret=1
91n=$((n + 1))
92if [ $ret != 0 ]; then echo_i "failed"; fi
93status=$((status + ret))
94
95echo_i "checking with max ttl (raw) ($n)"
96ret=0
97$CHECKZONE -f raw -l 300 example good1.db.raw >test.out1.$n 2>&1 && ret=1
98$CHECKZONE -f raw -l 600 example good1.db.raw >test.out2.$n 2>&1 || ret=1
99n=$((n + 1))
100if [ $ret != 0 ]; then echo_i "failed"; fi
101status=$((status + ret))
102
103echo_i "checking for no 'inherited owner' warning on '\$INCLUDE file' with no new \$ORIGIN ($n)"
104ret=0
105$CHECKZONE example zones/nowarn.inherited.owner.db >test.out1.$n 2>&1 || ret=1
106grep "inherited.owner" test.out1.$n >/dev/null && ret=1
107n=$((n + 1))
108if [ $ret != 0 ]; then echo_i "failed"; fi
109status=$((status + ret))
110
111echo_i "checking for 'inherited owner' warning on '\$ORIGIN + \$INCLUDE file' ($n)"
112ret=0
113$CHECKZONE example zones/warn.inherit.origin.db >test.out1.$n 2>&1 || ret=1
114grep "inherited.owner" test.out1.$n >/dev/null || ret=1
115n=$((n + 1))
116if [ $ret != 0 ]; then echo_i "failed"; fi
117status=$((status + ret))
118
119echo_i "checking for 'inherited owner' warning on '\$INCLUDE file origin' ($n)"
120ret=0
121$CHECKZONE example zones/warn.inherited.owner.db >test.out1.$n 2>&1 || ret=1
122grep "inherited.owner" test.out1.$n >/dev/null || ret=1
123n=$((n + 1))
124if [ $ret != 0 ]; then echo_i "failed"; fi
125status=$((status + ret))
126
127echo_i "checking that raw zone with bad class is handled ($n)"
128ret=0
129$CHECKZONE -f raw example zones/bad-badclass.raw >test.out.$n 2>&1 && ret=1
130grep "failed: bad class" test.out.$n >/dev/null || ret=1
131n=$((n + 1))
132if [ $ret != 0 ]; then echo_i "failed"; fi
133status=$((status + ret))
134
135echo_i "checking that expirations that loop using serial arithmetic are handled ($n)"
136ret=0
137q=-q
138test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
139test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
140test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
141test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
142test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
143test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
144test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
145test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
146test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
147test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
148test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
149test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
150test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
151test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
152test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
153test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
154test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
155test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
156test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
157test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
158test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
159test $ret -eq 1 || $CHECKZONE $q dyn.example.net zones/crashzone.db || ret=1
160n=$((n + 1))
161if [ $ret != 0 ]; then echo_i "failed"; fi
162status=$((status + ret))
163
164echo_i "checking that nameserver below DNAME is reported even with occulted address record present ($n)"
165ret=0
166$CHECKZONE example.com zones/ns-address-below-dname.db >test.out.$n 2>&1 && ret=1
167grep "is below a DNAME" test.out.$n >/dev/null || ret=1
168n=$((n + 1))
169if [ $ret != 0 ]; then echo_i "failed"; fi
170status=$((status + ret))
171
172echo_i "checking that delegating nameserver below DNAME is reported even with occulted address record present ($n)"
173ret=0
174$CHECKZONE example.com zones/delegating-ns-address-below-dname.db >test.out.$n 2>&1 || ret=1
175grep "is below a DNAME" test.out.$n >/dev/null || ret=1
176n=$((n + 1))
177if [ $ret != 0 ]; then echo_i "failed"; fi
178status=$((status + ret))
179
180n=$((n + 1))
181echo_i "checking that named-compilezone works when reading input from stdin ($n)"
182ret=0
183# Step 1: take raw input from stdin and convert it to text/relative format.
184# Last argument "-" is optional, but it says more explicitly that we're reading from stdin.
185cat zones/zone1.db | ./named-compilezone -f text -F text -s relative \
186  -o zones/zone1_stdin.txt zone1.com - >/dev/null || ret=1
187status=$((status + ret))
188
189ret=0
190# Step 2: take raw input from file and convert it to text format.
191./named-compilezone -f text -F text -s relative -o zones/zone1_file.txt \
192  zone1.com zones/zone1.db >/dev/null || ret=1
193status=$((status + ret))
194
195ret=0
196# Step 3: Ensure that output conversion from stdin is the same as the output conversion from a file.
197diff zones/zone1_file.txt zones/zone1_stdin.txt >/dev/null 2>&1 || ret=1
198if [ $ret != 0 ]; then echo_i "failed"; fi
199status=$((status + ret))
200
201n=$((n + 1))
202ret=0
203echo_i "checking integer overflow is prevented in \$GENERATE ($n)"
204$CHECKZONE -D example.com zones/generate-overflow.db >test.out.$n 2>&1 || ret=1
205lines=$(grep -c CNAME test.out.$n)
206echo $lines
207[ "$lines" -eq 1 ] || ret=1
208if [ $ret != 0 ]; then echo_i "failed"; fi
209status=$((status + ret))
210
211echo_i "exit status: $status"
212[ $status -eq 0 ] || exit 1
213