Blame bin/tests/system/dlzexternal/tests.sh

Packit Service ae04f2
#!/bin/sh
Packit Service ae04f2
#
Packit Service ae04f2
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Packit Service ae04f2
#
Packit Service ae04f2
# This Source Code Form is subject to the terms of the Mozilla Public
Packit Service ae04f2
# License, v. 2.0. If a copy of the MPL was not distributed with this
Packit Service ae04f2
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Packit Service ae04f2
#
Packit Service ae04f2
# See the COPYRIGHT file distributed with this work for additional
Packit Service ae04f2
# information regarding copyright ownership.
Packit Service ae04f2
Packit Service ae04f2
SYSTEMTESTTOP=..
Packit Service ae04f2
. $SYSTEMTESTTOP/conf.sh
Packit Service ae04f2
Packit Service ae04f2
status=0
Packit Service ae04f2
n=0
Packit Service ae04f2
Packit Service ae04f2
DIGOPTS="@10.53.0.1 -p ${PORT} +nocookie"
Packit Service ae04f2
RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s"
Packit Service ae04f2
Packit Service ae04f2
newtest() {
Packit Service ae04f2
	n=`expr $n + 1`
Packit Service ae04f2
	echo_i "${1} (${n})"
Packit Service ae04f2
	ret=0
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
test_update() {
Packit Service ae04f2
    host="$1"
Packit Service ae04f2
    type="$2"
Packit Service ae04f2
    cmd="$3"
Packit Service ae04f2
    digout="$4"
Packit Service ae04f2
    should_fail="$5"
Packit Service ae04f2
Packit Service ae04f2
    cat <<EOF > ns1/update.txt
Packit Service ae04f2
server 10.53.0.1 ${PORT}
Packit Service ae04f2
update add $host $cmd
Packit Service ae04f2
send
Packit Service ae04f2
EOF
Packit Service ae04f2
Packit Service ae04f2
    newtest "testing update for $host $type $cmd${comment:+ }$comment"
Packit Service ae04f2
    $NSUPDATE -k ns1/ddns.key ns1/update.txt > /dev/null 2>&1 || {
Packit Service ae04f2
	[ "$should_fail" ] || \
Packit Service ae04f2
             echo_i "update failed for $host $type $cmd"
Packit Service ae04f2
	return 1
Packit Service ae04f2
    }
Packit Service ae04f2
Packit Service ae04f2
    out=`$DIG $DIGOPTS -t $type -q $host | egrep "^$host"`
Packit Service ae04f2
    lines=`echo "$out" | grep "$digout" | wc -l`
Packit Service ae04f2
    [ $lines -eq 1 ] || {
Packit Service ae04f2
	[ "$should_fail" ] || \
Packit Service ae04f2
            echo_i "dig output incorrect for $host $type $cmd: $out"
Packit Service ae04f2
	return 1
Packit Service ae04f2
    }
Packit Service ae04f2
    return 0
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
test_update testdc1.example.nil. A "86400 A 10.53.0.10" "10.53.0.10" || ret=1
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
test_update testdc2.example.nil. A "86400 A 10.53.0.11" "10.53.0.11" || ret=1
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
test_update testdc3.example.nil. A "86400 A 10.53.0.10" "10.53.0.10" || ret=1
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
test_update deny.example.nil. TXT "86400 TXT helloworld" "helloworld" should_fail && ret=1
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing nxrrset"
Packit Service ae04f2
$DIG $DIGOPTS testdc1.example.nil AAAA > dig.out.$n
Packit Service ae04f2
grep "status: NOERROR" dig.out.$n > /dev/null || ret=1
Packit Service ae04f2
grep "ANSWER: 0" dig.out.$n > /dev/null || ret=1
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing prerequisites are checked correctly"
Packit Service ae04f2
cat > ns1/update.txt << EOF
Packit Service ae04f2
server 10.53.0.1 ${PORT}
Packit Service ae04f2
prereq nxdomain testdc3.example.nil
Packit Service ae04f2
update add testdc3.example.nil 86500 in a 10.53.0.12
Packit Service ae04f2
send
Packit Service ae04f2
EOF
Packit Service ae04f2
$NSUPDATE -k ns1/ddns.key ns1/update.txt > /dev/null 2>&1 && ret=1
Packit Service ae04f2
out=`$DIG $DIGOPTS +short a testdc3.example.nil`
Packit Service ae04f2
[ "$out" = "10.53.0.12" ] && ret=1
Packit Service ae04f2
[ "$ret" -eq 0 ] || echo_i "failed"
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing passing client info into DLZ driver"
Packit Service ae04f2
out=`$DIG $DIGOPTS +short -t txt -q source-addr.example.nil | grep -v '^;'`
Packit Service ae04f2
addr=`eval echo "$out" | cut -f1 -d'#'`
Packit Service ae04f2
[ "$addr" = "10.53.0.1" ] || ret=1
Packit Service ae04f2
[ "$ret" -eq 0 ] || echo_i "failed"
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing DLZ driver is cleaned up on reload"
Packit Service ae04f2
$RNDCCMD 10.53.0.1 reload 2>&1 | sed 's/^/ns1 /' | cat_i
Packit Service ae04f2
for i in 0 1 2 3 4 5 6 7 8 9; do
Packit Service ae04f2
    ret=0
Packit Service ae04f2
    grep 'dlz_example: shutting down zone example.nil' ns1/named.run > /dev/null 2>&1 || ret=1
Packit Service ae04f2
    [ "$ret" -eq 0 ] && break
Packit Service ae04f2
    sleep 1
Packit Service ae04f2
done
Packit Service ae04f2
[ "$ret" -eq 0 ] || echo_i "failed"
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing multiple DLZ drivers"
Packit Service ae04f2
test_update testdc1.alternate.nil. A "86400 A 10.53.0.10" "10.53.0.10" || ret=1
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing AXFR from DLZ drivers"
Packit Service ae04f2
$DIG $DIGOPTS +noall +answer axfr example.nil > dig.out.example.ns1.test$n
Packit Service ae04f2
lines=`cat dig.out.example.ns1.test$n | wc -l`
Packit Service ae04f2
[ ${lines:-0} -eq 4 ] || ret=1
Packit Service ae04f2
$DIG $DIGOPTS +noall +answer axfr alternate.nil > dig.out.alternate.ns1.test$n
Packit Service ae04f2
lines=`cat dig.out.alternate.ns1.test$n | wc -l`
Packit Service ae04f2
[ ${lines:-0} -eq 5 ] || ret=1
Packit Service ae04f2
[ "$ret" -eq 0 ] || echo_i "failed"
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing AXFR denied from DLZ drivers"
Packit Service ae04f2
$DIG $DIGOPTS -b 10.53.0.5 +noall +answer axfr example.nil > dig.out.example.ns1.test$n
Packit Service ae04f2
grep "; Transfer failed" dig.out.example.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
$DIG $DIGOPTS -b 10.53.0.5 +noall +answer axfr alternate.nil > dig.out.alternate.ns1.test$n
Packit Service ae04f2
grep "; Transfer failed" dig.out.alternate.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
[ "$ret" -eq 0 ] || echo_i "failed"
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing unsearched/unregistered DLZ zone is not found"
Packit Service ae04f2
$DIG $DIGOPTS +noall +answer ns other.nil > dig.out.ns1.test$n
Packit Service ae04f2
grep "3600.IN.NS.other.nil." dig.out.ns1.test$n > /dev/null && ret=1
Packit Service ae04f2
[ "$ret" -eq 0 ] || echo_i "failed"
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing unsearched/registered DLZ zone is found"
Packit Service ae04f2
$DIG $DIGOPTS +noall +answer ns zone.nil > dig.out.ns1.test$n
Packit Service ae04f2
grep "3600.IN.NS.zone.nil." dig.out.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
[ "$ret" -eq 0 ] || echo_i "failed"
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing unsearched/registered DLZ zone is found"
Packit Service ae04f2
$DIG $DIGOPTS +noall +answer ns zone.nil > dig.out.ns1.test$n
Packit Service ae04f2
grep "3600.IN.NS.zone.nil." dig.out.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
[ "$ret" -eq 0 ] || echo_i "failed"
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing correct behavior with findzone returning ISC_R_NOMORE"
Packit Service ae04f2
$DIG $DIGOPTS +noall a test.example.com > /dev/null 2>&1 || ret=1
Packit Service ae04f2
# we should only find one logged lookup per searched DLZ database
Packit Service ae04f2
lines=`grep "dlz_findzonedb.*test\.example\.com.*example.nil" ns1/named.run | wc -l`
Packit Service ae04f2
[ $lines -eq 1 ] || ret=1
Packit Service ae04f2
lines=`grep "dlz_findzonedb.*test\.example\.com.*alternate.nil" ns1/named.run | wc -l`
Packit Service ae04f2
[ $lines -eq 1 ] || ret=1
Packit Service ae04f2
[ "$ret" -eq 0 ] || echo_i "failed"
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing findzone can return different results per client"
Packit Service ae04f2
$DIG $DIGOPTS -b 10.53.0.1 +noall a test.example.net > /dev/null 2>&1 || ret=1
Packit Service ae04f2
# we should only find one logged lookup per searched DLZ database
Packit Service ae04f2
lines=`grep "dlz_findzonedb.*example\.net.*example.nil" ns1/named.run | wc -l`
Packit Service ae04f2
[ $lines -eq 1 ] || ret=1
Packit Service ae04f2
lines=`grep "dlz_findzonedb.*example\.net.*alternate.nil" ns1/named.run | wc -l`
Packit Service ae04f2
[ $lines -eq 1 ] || ret=1
Packit Service ae04f2
$DIG $DIGOPTS -b 10.53.0.2 +noall a test.example.net > /dev/null 2>&1 || ret=1
Packit Service ae04f2
# we should find several logged lookups this time
Packit Service ae04f2
lines=`grep "dlz_findzonedb.*example\.net.*example.nil" ns1/named.run | wc -l`
Packit Service ae04f2
[ $lines -gt 2 ] || ret=1
Packit Service ae04f2
lines=`grep "dlz_findzonedb.*example\.net.*alternate.nil" ns1/named.run | wc -l`
Packit Service ae04f2
[ $lines -gt 2 ] || ret=1
Packit Service ae04f2
[ "$ret" -eq 0 ] || echo_i "failed"
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing zone returning oversized data"
Packit Service ae04f2
$DIG $DIGOPTS txt too-long.example.nil > dig.out.ns1.test$n 2>&1 || ret=1
Packit Service ae04f2
grep "status: SERVFAIL" dig.out.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
[ "$ret" -eq 0 ] || echo_i "failed"
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "testing zone returning oversized data at zone origin"
Packit Service ae04f2
$DIG $DIGOPTS txt bigcname.domain > dig.out.ns1.test$n 2>&1 || ret=1
Packit Service ae04f2
grep "status: SERVFAIL" dig.out.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
[ "$ret" -eq 0 ] || echo_i "failed"
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "checking redirected lookup for nonexistent name"
Packit Service ae04f2
$DIG $DIGOPTS @10.53.0.1 unexists a > dig.out.ns1.test$n || ret=1
Packit Service ae04f2
grep "status: NOERROR" dig.out.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
grep "^unexists.*A.*100.100.100.2" dig.out.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
grep "flags:[^;]* aa[ ;]" dig.out.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
if [ $ret != 0 ]; then echo_i "failed"; fi
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "checking no redirected lookup for nonexistent type"
Packit Service ae04f2
$DIG $DIGOPTS @10.53.0.1 exists aaaa > dig.out.ns1.test$n || ret=1
Packit Service ae04f2
grep "status: NOERROR" dig.out.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
grep "ANSWER: 0" dig.out.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
if [ $ret != 0 ]; then echo_i "failed"; fi
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
newtest "checking redirected lookup for a long nonexistent name"
Packit Service ae04f2
$DIG $DIGOPTS @10.53.0.1 long.name.is.not.there a > dig.out.ns1.test$n || ret=1
Packit Service ae04f2
grep "status: NOERROR" dig.out.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
grep "^long.name.*A.*100.100.100.3" dig.out.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
grep "flags:[^;]* aa[ ;]" dig.out.ns1.test$n > /dev/null || ret=1
Packit Service ae04f2
lookups=`grep "lookup #.*\.not\.there" ns1/named.run | wc -l`
Packit Service ae04f2
[ "$lookups" -eq 1 ] || ret=1
Packit Service ae04f2
if [ $ret != 0 ]; then echo_i "failed"; fi
Packit Service ae04f2
status=`expr $status + $ret`
Packit Service ae04f2
Packit Service ae04f2
echo_i "exit status: $status"
Packit Service ae04f2
[ $status -eq 0 ] || exit 1