xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/dyndb/tests.sh (revision 15a984a0d95c8f96abe9717ee6241762c55dc106)
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
17status=0
18n=0
19
20DIGOPTS="@10.53.0.1 -p ${PORT}"
21RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s"
22
23newtest() {
24	n=`expr $n + 1`
25	echo_i "${1} (${n})"
26	ret=0
27}
28
29test_add() {
30    host="$1"
31    type="$2"
32    ip="$3"
33
34    cat <<EOF > ns1/update.txt
35server 10.53.0.1 ${PORT}
36ttl 86400
37update add $host $type $ip
38send
39EOF
40
41    newtest "adding $host $type $ip"
42    $NSUPDATE ns1/update.txt > /dev/null 2>&1 || {
43	[ "$should_fail" ] || \
44	     echo_i "update failed for $host $type $ip"
45	return 1
46    }
47
48    out=`$DIG $DIGOPTS +noall +answer -t $type -q $host`
49    echo $out > added.a.out.$n
50    lines=`echo "$out" | grep "$ip" | wc -l`
51    [ $lines -eq 1 ] || {
52	[ "$should_fail" ] || \
53	    echo_i "dig output incorrect for $host $type $cmd: $out"
54	return 1
55    }
56
57    for i in 1 2 3 4 5 6 7 8 9 10
58    do
59	out=`$DIG $DIGOPTS +noall +answer -x $ip`
60	echo $out > added.ptr.out.$n
61	lines=`echo "$out" | grep "$host" | wc -l`
62	[ $lines -eq 1 ] && break;
63	$PERL -e 'select(undef, undef, undef, 0.1);'
64    done
65    [ $lines -eq 1 ] || {
66	[ "$should_fail" ] || \
67	    echo_i "dig reverse output incorrect for $host $type $cmd: $out"
68	return 1
69    }
70
71    return 0
72}
73
74test_del() {
75    host="$1"
76    type="$2"
77
78    ip=`$DIG $DIGOPTS +short $host $type`
79
80    cat <<EOF > ns1/update.txt
81server 10.53.0.1 ${PORT}
82update del $host $type
83send
84EOF
85
86    newtest "deleting $host $type (was $ip)"
87    $NSUPDATE ns1/update.txt > /dev/null 2>&1 || {
88	[ "$should_fail" ] || \
89	     echo_i "update failed deleting $host $type"
90	return 1
91    }
92
93    out=`$DIG $DIGOPTS +noall +answer -t $type -q $host`
94    echo $out > deleted.a.out.$n
95    lines=`echo "$out" | grep "$ip" | wc -l`
96    [ $lines -eq 0 ] || {
97	[ "$should_fail" ] || \
98	    echo_i "dig output incorrect for $host $type $cmd: $out"
99	return 1
100    }
101
102    for i in 1 2 3 4 5 6 7 8 9 10
103    do
104	out=`$DIG $DIGOPTS +noall +answer -x $ip`
105	echo $out > deleted.ptr.out.$n
106	lines=`echo "$out" | grep "$host" | wc -l`
107	[ $lines -eq 0 ] && break
108	$PERL -e 'select(undef, undef, undef, 0.1);'
109    done
110    [ $lines -eq 0 ] || {
111	[ "$should_fail" ] || \
112	    echo_i "dig reverse output incorrect for $host $type $cmd: $out"
113	return 1
114    }
115
116    return 0
117}
118
119test_add test1.ipv4.example.nil. A "10.53.0.10" || ret=1
120status=`expr $status + $ret`
121
122test_add test2.ipv4.example.nil. A "10.53.0.11" || ret=1
123status=`expr $status + $ret`
124
125test_add test3.ipv4.example.nil. A "10.53.0.12" || ret=1
126status=`expr $status + $ret`
127
128test_add test4.ipv6.example.nil. AAAA "2001:db8::1" || ret=1
129status=`expr $status + $ret`
130
131test_del test1.ipv4.example.nil. A || ret=1
132status=`expr $status + $ret`
133
134test_del test2.ipv4.example.nil. A || ret=1
135status=`expr $status + $ret`
136
137test_del test3.ipv4.example.nil. A || ret=1
138status=`expr $status + $ret`
139
140test_del test4.ipv6.example.nil. AAAA || ret=1
141status=`expr $status + $ret`
142
143newtest "checking parameter logging"
144grep "loading params for dyndb 'sample' from .*named.conf:" ns1/named.run > /dev/null || ret=1
145grep "loading params for dyndb 'sample2' from .*named.conf:" ns1/named.run > /dev/null || ret=1
146[ $ret -eq 1 ] && echo_i "failed"
147status=`expr $status + $ret`
148
149echo_i "checking dyndb still works after reload"
150rndc_reload ns1 10.53.0.1
151
152test_add test5.ipv4.example.nil. A "10.53.0.10" || ret=1
153status=`expr $status + $ret`
154
155test_add test6.ipv6.example.nil. AAAA "2001:db8::1" || ret=1
156status=`expr $status + $ret`
157
158test_del test5.ipv4.example.nil. A || ret=1
159status=`expr $status + $ret`
160
161test_del test6.ipv6.example.nil. AAAA || ret=1
162status=`expr $status + $ret`
163
164echo_i "exit status: $status"
165[ $status -eq 0 ] || exit 1
166