tests.sh 7.64 KB
Newer Older
1
#!/bin/sh
Mark Andrews's avatar
Mark Andrews committed
2
#
3
# Copyright (C) 2010-2015  Internet Systems Consortium, Inc. ("ISC")
Mark Andrews's avatar
Mark Andrews committed
4 5 6 7 8 9 10 11 12 13 14 15 16
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

17 18 19 20
SYSTEMTESTTOP=..
. $SYSTEMTESTTOP/conf.sh

status=0
21
n=0
22

23
DIGOPTS="@10.53.0.1 -p 5300 +nocookie"
24

25 26 27 28 29 30
newtest() {
	n=`expr $n + 1`
	echo "${1} (${n})"
	ret=0
}

31 32 33 34 35
test_update() {
    host="$1"
    type="$2"
    cmd="$3"
    digout="$4"
36
    should_fail="$5"
37 38 39 40 41 42

    cat <<EOF > ns1/update.txt
server 10.53.0.1 5300
update add $host $cmd
send
EOF
43

44
    newtest "I:testing update for $host $type $cmd${comment:+ }$comment"
45 46 47
    $NSUPDATE -k ns1/ddns.key ns1/update.txt > /dev/null 2>&1 || {
	[ "$should_fail" ] || \
             echo "I:update failed for $host $type $cmd"
48 49 50
	return 1
    }

51
    out=`$DIG $DIGOPTS -t $type -q $host | egrep "^$host"`
52 53
    lines=`echo "$out" | grep "$digout" | wc -l`
    [ $lines -eq 1 ] || {
54 55
	[ "$should_fail" ] || \
            echo "I:dig output incorrect for $host $type $cmd: $out"
56 57 58 59 60
	return 1
    }
    return 0
}

61 62 63 64 65 66 67 68
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`
69

70 71
test_update deny.example.nil. TXT "86400 TXT helloworld" "helloworld" should_fail && ret=1
status=`expr $status + $ret`
72

Evan Hunt's avatar
Evan Hunt committed
73 74 75 76 77 78
newtest "I:testing nxrrset"
$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`

79
newtest "I:testing prerequisites are checked correctly"
80 81 82 83 84 85 86 87 88 89 90 91
cat > ns1/update.txt << EOF
server 10.53.0.1 5300
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
[ "$ret" -eq 0 ] || echo "I:failed"
status=`expr $status + $ret`

92
newtest "I:testing passing client info into DLZ driver"
93 94
out=`$DIG $DIGOPTS +short -t txt -q source-addr.example.nil | grep -v '^;'`
addr=`eval echo "$out" | cut -f1 -d'#'`
95 96 97 98
[ "$addr" = "10.53.0.1" ] || ret=1
[ "$ret" -eq 0 ] || echo "I:failed"
status=`expr $status + $ret`

99
newtest "I:testing DLZ driver is cleaned up on reload"
100 101 102 103 104
$RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 reload 2>&1 | sed 's/^/I:ns1 /'
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
105
    sleep 1
106 107 108 109
done
[ "$ret" -eq 0 ] || echo "I:failed"
status=`expr $status + $ret`

110
newtest "I:testing multiple DLZ drivers"
Evan Hunt's avatar
Evan Hunt committed
111 112 113
test_update testdc1.alternate.nil. A "86400 A 10.53.0.10" "10.53.0.10" || ret=1
status=`expr $status + $ret`

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

124 125 126
newtest "I:testing unsearched/unregistered DLZ zone is not found"
$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
127 128 129
[ "$ret" -eq 0 ] || echo "I:failed"
status=`expr $status + $ret`

130 131 132
newtest "I:testing unsearched/registered DLZ zone is found"
$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
133 134 135
[ "$ret" -eq 0 ] || echo "I:failed"
status=`expr $status + $ret`

136 137 138
newtest "I:testing unsearched/registered DLZ zone is found"
$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
139 140 141
[ "$ret" -eq 0 ] || echo "I:failed"
status=`expr $status + $ret`

142
newtest "I:testing correct behavior with findzone returning ISC_R_NOMORE"
143 144
$DIG $DIGOPTS +noall a test.example.com > /dev/null 2>&1 || ret=1
# we should only find one logged lookup per searched DLZ database
145
lines=`grep "dlz_findzonedb.*test\.example\.com.*example.nil" ns1/named.run | wc -l`
146
[ $lines -eq 1 ] || ret=1
147
lines=`grep "dlz_findzonedb.*test\.example\.com.*alternate.nil" ns1/named.run | wc -l`
148 149 150 151
[ $lines -eq 1 ] || ret=1
[ "$ret" -eq 0 ] || echo "I:failed"
status=`expr $status + $ret`

152
newtest "I:testing findzone can return different results per client"
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
$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
[ "$ret" -eq 0 ] || echo "I:failed"
status=`expr $status + $ret`

168 169 170
newtest "I:testing zone returning oversized data"
$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
171 172 173
[ "$ret" -eq 0 ] || echo "I:failed"
status=`expr $status + $ret`

174 175 176
newtest "I:testing zone returning oversized data at zone origin"
$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
177 178 179
[ "$ret" -eq 0 ] || echo "I:failed"
status=`expr $status + $ret`

180 181 182 183 184 185 186 187
newtest "I:checking redirected lookup for nonexistent name"
$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
if [ $ret != 0 ]; then echo "I:failed"; fi
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
188 189 190 191 192 193 194
newtest "I:checking no redirected lookup for nonexistent type"
$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
if [ $ret != 0 ]; then echo "I:failed"; fi
status=`expr $status + $ret`

195 196 197 198 199 200 201 202 203 204
newtest "I:checking redirected lookup for a long nonexistent name"
$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
if [ $ret != 0 ]; then echo "I:failed"; fi
status=`expr $status + $ret`

205 206
echo "I:exit status: $status"
[ $status -eq 0 ] || exit 1