tests.sh 3.94 KB
Newer Older
Evan Hunt's avatar
Evan Hunt committed
1 2
#!/bin/sh
#
3
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Evan Hunt's avatar
Evan Hunt 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.
Evan Hunt's avatar
Evan Hunt committed
11 12 13 14 15 16 17

SYSTEMTESTTOP=..
. $SYSTEMTESTTOP/conf.sh

status=0
n=0

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

newtest() {
	n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
23
	echo_i "${1} (${n})"
Evan Hunt's avatar
Evan Hunt committed
24 25 26 27 28 29 30 31 32
	ret=0
}

test_add() {
    host="$1"
    type="$2"
    ip="$3"

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

Evan Hunt's avatar
Evan Hunt committed
39
    newtest "adding $host $type $ip"
Evan Hunt's avatar
Evan Hunt committed
40 41
    $NSUPDATE ns1/update.txt > /dev/null 2>&1 || {
	[ "$should_fail" ] || \
42
	     echo_i "update failed for $host $type $ip"
Evan Hunt's avatar
Evan Hunt committed
43 44 45 46 47 48 49 50
	return 1
    }

    out=`$DIG $DIGOPTS +noall +answer -t $type -q $host`
    echo $out > added.a.out.$n
    lines=`echo "$out" | grep "$ip" | wc -l`
    [ $lines -eq 1 ] || {
	[ "$should_fail" ] || \
51
	    echo_i "dig output incorrect for $host $type $cmd: $out"
Evan Hunt's avatar
Evan Hunt committed
52 53 54
	return 1
    }

55 56 57 58 59 60 61 62
    for i in 1 2 3 4 5 6 7 8 9 10
    do
	out=`$DIG $DIGOPTS +noall +answer -x $ip`
	echo $out > added.ptr.out.$n
	lines=`echo "$out" | grep "$host" | wc -l`
	[ $lines -eq 1 ] && break;
	$PERL -e 'select(undef, undef, undef, 0.1);'
    done
Evan Hunt's avatar
Evan Hunt committed
63 64
    [ $lines -eq 1 ] || {
	[ "$should_fail" ] || \
65
	    echo_i "dig reverse output incorrect for $host $type $cmd: $out"
Evan Hunt's avatar
Evan Hunt committed
66 67 68 69 70 71 72 73 74 75 76 77 78
	return 1
    }

    return 0
}

test_del() {
    host="$1"
    type="$2"

    ip=`$DIG $DIGOPTS +short $host $type`

    cat <<EOF > ns1/update.txt
Evan Hunt's avatar
Evan Hunt committed
79
server 10.53.0.1 ${PORT}
Evan Hunt's avatar
Evan Hunt committed
80 81 82 83
update del $host $type
send
EOF

Evan Hunt's avatar
Evan Hunt committed
84
    newtest "deleting $host $type (was $ip)"
Evan Hunt's avatar
Evan Hunt committed
85 86
    $NSUPDATE ns1/update.txt > /dev/null 2>&1 || {
	[ "$should_fail" ] || \
87
	     echo_i "update failed deleting $host $type"
Evan Hunt's avatar
Evan Hunt committed
88 89 90 91 92 93 94 95
	return 1
    }

    out=`$DIG $DIGOPTS +noall +answer -t $type -q $host`
    echo $out > deleted.a.out.$n
    lines=`echo "$out" | grep "$ip" | wc -l`
    [ $lines -eq 0 ] || {
	[ "$should_fail" ] || \
96
	    echo_i "dig output incorrect for $host $type $cmd: $out"
Evan Hunt's avatar
Evan Hunt committed
97 98 99
	return 1
    }

100 101 102 103 104 105 106 107
    for i in 1 2 3 4 5 6 7 8 9 10
    do
	out=`$DIG $DIGOPTS +noall +answer -x $ip`
	echo $out > deleted.ptr.out.$n
	lines=`echo "$out" | grep "$host" | wc -l`
	[ $lines -eq 0 ] && break
	$PERL -e 'select(undef, undef, undef, 0.1);'
    done
Evan Hunt's avatar
Evan Hunt committed
108 109
    [ $lines -eq 0 ] || {
	[ "$should_fail" ] || \
110
	    echo_i "dig reverse output incorrect for $host $type $cmd: $out"
Evan Hunt's avatar
Evan Hunt committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
	return 1
    }

    return 0
}

test_add test1.ipv4.example.nil. A "10.53.0.10" || ret=1
status=`expr $status + $ret`

test_add test2.ipv4.example.nil. A "10.53.0.11" || ret=1
status=`expr $status + $ret`

test_add test3.ipv4.example.nil. A "10.53.0.12" || ret=1
status=`expr $status + $ret`

test_add test4.ipv6.example.nil. AAAA "2001:db8::1" || ret=1
status=`expr $status + $ret`

test_del test1.ipv4.example.nil. A || ret=1
status=`expr $status + $ret`

test_del test2.ipv4.example.nil. A || ret=1
status=`expr $status + $ret`

test_del test3.ipv4.example.nil. A || ret=1
status=`expr $status + $ret`

test_del test4.ipv6.example.nil. AAAA || ret=1
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
141
newtest "checking parameter logging"
Evan Hunt's avatar
Evan Hunt committed
142 143 144
grep "loading params for dyndb 'sample' from .*named.conf:" ns1/named.run > /dev/null || ret=1
grep "loading params for dyndb 'sample2' from .*named.conf:" ns1/named.run > /dev/null || ret=1
[ $ret -eq 1 ] && echo_i "failed"
145 146
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
147
echo_i "checking dyndb still works after reload"
148
rndc_reload ns1 10.53.0.1
Evan Hunt's avatar
Evan Hunt committed
149 150 151 152 153 154 155 156 157 158 159 160 161

test_add test5.ipv4.example.nil. A "10.53.0.10" || ret=1
status=`expr $status + $ret`

test_add test6.ipv6.example.nil. AAAA "2001:db8::1" || ret=1
status=`expr $status + $ret`

test_del test5.ipv4.example.nil. A || ret=1
status=`expr $status + $ret`

test_del test6.ipv6.example.nil. AAAA || ret=1
status=`expr $status + $ret`

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