tests.sh 8.16 KB
Newer Older
1
#!/bin/sh
Mark Andrews's avatar
Mark Andrews committed
2
#
3
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Mark Andrews's avatar
Mark Andrews committed
4
#
5 6 7
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 9 10
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
Mark Andrews's avatar
Mark Andrews committed
11

12
. ../conf.sh
13 14

status=0
15
n=0
16

Evan Hunt's avatar
Evan Hunt committed
17
DIGOPTS="@10.53.0.1 -p ${PORT} +nocookie"
18
RNDCCMD="$RNDC -c ../common/rndc.conf -p ${CONTROLPORT} -s"
19

20 21
newtest() {
	n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
22
	echo_i "${1} (${n})"
23 24 25
	ret=0
}

26 27 28 29 30
test_update() {
    host="$1"
    type="$2"
    cmd="$3"
    digout="$4"
31
    should_fail="$5"
32 33

    cat <<EOF > ns1/update.txt
Evan Hunt's avatar
Evan Hunt committed
34
server 10.53.0.1 ${PORT}
35 36 37
update add $host $cmd
send
EOF
38

Evan Hunt's avatar
Evan Hunt committed
39
    newtest "testing update for $host $type $cmd${comment:+ }$comment"
40 41
    $NSUPDATE -k ns1/ddns.key ns1/update.txt > /dev/null 2>&1 || {
	[ "$should_fail" ] || \
Evan Hunt's avatar
Evan Hunt committed
42
             echo_i "update failed for $host $type $cmd"
43 44 45
	return 1
    }

46
    out=`$DIG $DIGOPTS -t $type -q $host | egrep "^$host"`
47 48
    lines=`echo "$out" | grep "$digout" | wc -l`
    [ $lines -eq 1 ] || {
49
	[ "$should_fail" ] || \
Evan Hunt's avatar
Evan Hunt committed
50
            echo_i "dig output incorrect for $host $type $cmd: $out"
51 52 53 54 55
	return 1
    }
    return 0
}

56 57 58 59 60 61 62 63
test_update testdc1.example.nil. A "86400 A 10.53.0.10" "10.53.0.10" || ret=1
status=`expr $status + $ret`

test_update testdc2.example.nil. A "86400 A 10.53.0.11" "10.53.0.11" || ret=1
status=`expr $status + $ret`

test_update testdc3.example.nil. A "86400 A 10.53.0.10" "10.53.0.10" || ret=1
status=`expr $status + $ret`
64

65 66
test_update deny.example.nil. TXT "86400 TXT helloworld" "helloworld" should_fail && ret=1
status=`expr $status + $ret`
67

Evan Hunt's avatar
Evan Hunt committed
68
newtest "testing nxrrset"
Evan Hunt's avatar
Evan Hunt committed
69 70 71 72 73
$DIG $DIGOPTS testdc1.example.nil AAAA > dig.out.$n
grep "status: NOERROR" dig.out.$n > /dev/null || ret=1
grep "ANSWER: 0" dig.out.$n > /dev/null || ret=1
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
74
newtest "testing prerequisites are checked correctly"
75
cat > ns1/update.txt << EOF
Evan Hunt's avatar
Evan Hunt committed
76
server 10.53.0.1 ${PORT}
77 78 79 80 81 82 83
prereq nxdomain testdc3.example.nil
update add testdc3.example.nil 86500 in a 10.53.0.12
send
EOF
$NSUPDATE -k ns1/ddns.key ns1/update.txt > /dev/null 2>&1 && ret=1
out=`$DIG $DIGOPTS +short a testdc3.example.nil`
[ "$out" = "10.53.0.12" ] && ret=1
Evan Hunt's avatar
Evan Hunt committed
84
[ "$ret" -eq 0 ] || echo_i "failed"
85 86
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
87
newtest "testing passing client info into DLZ driver"
88 89
out=`$DIG $DIGOPTS +short -t txt -q source-addr.example.nil | grep -v '^;'`
addr=`eval echo "$out" | cut -f1 -d'#'`
90
[ "$addr" = "10.53.0.1" ] || ret=1
Evan Hunt's avatar
Evan Hunt committed
91
[ "$ret" -eq 0 ] || echo_i "failed"
92 93
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
94
newtest "testing DLZ driver is cleaned up on reload"
95
rndc_reload ns1 10.53.0.1
96 97 98 99
for i in 0 1 2 3 4 5 6 7 8 9; do
    ret=0
    grep 'dlz_example: shutting down zone example.nil' ns1/named.run > /dev/null 2>&1 || ret=1
    [ "$ret" -eq 0 ] && break
Mark Andrews's avatar
Mark Andrews committed
100
    sleep 1
101
done
Evan Hunt's avatar
Evan Hunt committed
102
[ "$ret" -eq 0 ] || echo_i "failed"
103 104
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
105
newtest "testing multiple DLZ drivers"
Evan Hunt's avatar
Evan Hunt committed
106 107 108
test_update testdc1.alternate.nil. A "86400 A 10.53.0.10" "10.53.0.10" || ret=1
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
109
newtest "testing AXFR from DLZ drivers"
110 111
$DIG $DIGOPTS +noall +answer axfr example.nil > dig.out.example.ns1.test$n
lines=`cat dig.out.example.ns1.test$n | wc -l`
112
[ ${lines:-0} -eq 4 ] || ret=1
113 114
$DIG $DIGOPTS +noall +answer axfr alternate.nil > dig.out.alternate.ns1.test$n
lines=`cat dig.out.alternate.ns1.test$n | wc -l`
115
[ ${lines:-0} -eq 5 ] || ret=1
Evan Hunt's avatar
Evan Hunt committed
116
[ "$ret" -eq 0 ] || echo_i "failed"
Evan Hunt's avatar
Evan Hunt committed
117 118
status=`expr $status + $ret`

119 120 121 122 123 124 125 126
newtest "testing AXFR denied from DLZ drivers"
$DIG $DIGOPTS -b 10.53.0.5 +noall +answer axfr example.nil > dig.out.example.ns1.test$n
grep "; Transfer failed" dig.out.example.ns1.test$n > /dev/null || ret=1
$DIG $DIGOPTS -b 10.53.0.5 +noall +answer axfr alternate.nil > dig.out.alternate.ns1.test$n
grep "; Transfer failed" dig.out.alternate.ns1.test$n > /dev/null || ret=1
[ "$ret" -eq 0 ] || echo_i "failed"
status=`expr $status + $ret`

127 128 129 130 131 132 133 134 135 136
newtest "testing AXFR denied based on view ACL"
# 10.53.0.1 should be disallowed
$DIG $DIGOPTS -b 10.53.0.1 +noall +answer axfr example.org > dig.out.example.ns1.test$n.1
grep "; Transfer failed" dig.out.example.ns1.test$n.1 > /dev/null || ret=1
# 10.53.0.2 should be allowed
$DIG $DIGOPTS -b 10.53.0.2 +noall +answer axfr example.org > dig.out.example.ns1.test$n.2
grep "; Transfer failed" dig.out.example.ns1.test$n.2 > /dev/null && ret=1
[ "$ret" -eq 0 ] || echo_i "failed"
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
137
newtest "testing unsearched/unregistered DLZ zone is not found"
138 139
$DIG $DIGOPTS +noall +answer ns other.nil > dig.out.ns1.test$n
grep "3600.IN.NS.other.nil." dig.out.ns1.test$n > /dev/null && ret=1
Evan Hunt's avatar
Evan Hunt committed
140
[ "$ret" -eq 0 ] || echo_i "failed"
Evan Hunt's avatar
Evan Hunt committed
141 142
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
143
newtest "testing unsearched/registered DLZ zone is found"
144 145
$DIG $DIGOPTS +noall +answer ns zone.nil > dig.out.ns1.test$n
grep "3600.IN.NS.zone.nil." dig.out.ns1.test$n > /dev/null || ret=1
Evan Hunt's avatar
Evan Hunt committed
146
[ "$ret" -eq 0 ] || echo_i "failed"
Evan Hunt's avatar
Evan Hunt committed
147 148
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
149
newtest "testing unsearched/registered DLZ zone is found"
150 151
$DIG $DIGOPTS +noall +answer ns zone.nil > dig.out.ns1.test$n
grep "3600.IN.NS.zone.nil." dig.out.ns1.test$n > /dev/null || ret=1
Evan Hunt's avatar
Evan Hunt committed
152
[ "$ret" -eq 0 ] || echo_i "failed"
153 154
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
155
newtest "testing correct behavior with findzone returning ISC_R_NOMORE"
156 157
$DIG $DIGOPTS +noall a test.example.com > /dev/null 2>&1 || ret=1
# we should only find one logged lookup per searched DLZ database
158
lines=`grep "dlz_findzonedb.*test\.example\.com.*example.nil" ns1/named.run | wc -l`
159
[ $lines -eq 1 ] || ret=1
160
lines=`grep "dlz_findzonedb.*test\.example\.com.*alternate.nil" ns1/named.run | wc -l`
161
[ $lines -eq 1 ] || ret=1
Evan Hunt's avatar
Evan Hunt committed
162
[ "$ret" -eq 0 ] || echo_i "failed"
163 164
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
165
newtest "testing findzone can return different results per client"
166 167 168 169 170 171 172 173 174 175 176 177
$DIG $DIGOPTS -b 10.53.0.1 +noall a test.example.net > /dev/null 2>&1 || ret=1
# we should only find one logged lookup per searched DLZ database
lines=`grep "dlz_findzonedb.*example\.net.*example.nil" ns1/named.run | wc -l`
[ $lines -eq 1 ] || ret=1
lines=`grep "dlz_findzonedb.*example\.net.*alternate.nil" ns1/named.run | wc -l`
[ $lines -eq 1 ] || ret=1
$DIG $DIGOPTS -b 10.53.0.2 +noall a test.example.net > /dev/null 2>&1 || ret=1
# we should find several logged lookups this time
lines=`grep "dlz_findzonedb.*example\.net.*example.nil" ns1/named.run | wc -l`
[ $lines -gt 2 ] || ret=1
lines=`grep "dlz_findzonedb.*example\.net.*alternate.nil" ns1/named.run | wc -l`
[ $lines -gt 2 ] || ret=1
Evan Hunt's avatar
Evan Hunt committed
178
[ "$ret" -eq 0 ] || echo_i "failed"
179 180
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
181
newtest "testing zone returning oversized data"
182 183
$DIG $DIGOPTS txt too-long.example.nil > dig.out.ns1.test$n 2>&1 || ret=1
grep "status: SERVFAIL" dig.out.ns1.test$n > /dev/null || ret=1
Evan Hunt's avatar
Evan Hunt committed
184
[ "$ret" -eq 0 ] || echo_i "failed"
Evan Hunt's avatar
Evan Hunt committed
185 186
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
187
newtest "testing zone returning oversized data at zone origin"
188 189
$DIG $DIGOPTS txt bigcname.domain > dig.out.ns1.test$n 2>&1 || ret=1
grep "status: SERVFAIL" dig.out.ns1.test$n > /dev/null || ret=1
Evan Hunt's avatar
Evan Hunt committed
190
[ "$ret" -eq 0 ] || echo_i "failed"
191 192
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
193
newtest "checking redirected lookup for nonexistent name"
194 195 196 197
$DIG $DIGOPTS @10.53.0.1 unexists a > dig.out.ns1.test$n || ret=1
grep "status: NOERROR" dig.out.ns1.test$n > /dev/null || ret=1
grep "^unexists.*A.*100.100.100.2" dig.out.ns1.test$n > /dev/null || ret=1
grep "flags:[^;]* aa[ ;]" dig.out.ns1.test$n > /dev/null || ret=1
Evan Hunt's avatar
Evan Hunt committed
198
if [ $ret != 0 ]; then echo_i "failed"; fi
199 200
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
201
newtest "checking no redirected lookup for nonexistent type"
Evan Hunt's avatar
Evan Hunt committed
202 203 204
$DIG $DIGOPTS @10.53.0.1 exists aaaa > dig.out.ns1.test$n || ret=1
grep "status: NOERROR" dig.out.ns1.test$n > /dev/null || ret=1
grep "ANSWER: 0" dig.out.ns1.test$n > /dev/null || ret=1
Evan Hunt's avatar
Evan Hunt committed
205
if [ $ret != 0 ]; then echo_i "failed"; fi
Evan Hunt's avatar
Evan Hunt committed
206 207
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
208
newtest "checking redirected lookup for a long nonexistent name"
209 210 211 212 213 214
$DIG $DIGOPTS @10.53.0.1 long.name.is.not.there a > dig.out.ns1.test$n || ret=1
grep "status: NOERROR" dig.out.ns1.test$n > /dev/null || ret=1
grep "^long.name.*A.*100.100.100.3" dig.out.ns1.test$n > /dev/null || ret=1
grep "flags:[^;]* aa[ ;]" dig.out.ns1.test$n > /dev/null || ret=1
lookups=`grep "lookup #.*\.not\.there" ns1/named.run | wc -l`
[ "$lookups" -eq 1 ] || ret=1
Evan Hunt's avatar
Evan Hunt committed
215
if [ $ret != 0 ]; then echo_i "failed"; fi
216 217
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
218
echo_i "exit status: $status"
219
[ $status -eq 0 ] || exit 1