1#!/bin/sh 2# 3# Copyright (C) 2004, 2007, 2011, 2012, 2014 Internet Systems Consortium, Inc. ("ISC") 4# Copyright (C) 2001 Internet Software Consortium. 5# 6# Permission to use, copy, modify, and/or distribute this software for any 7# purpose with or without fee is hereby granted, provided that the above 8# copyright notice and this permission notice appear in all copies. 9# 10# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 11# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 12# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 13# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 14# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 15# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16# PERFORMANCE OF THIS SOFTWARE. 17 18# Id: tests.sh,v 1.11 2012/02/22 14:22:54 marka Exp 19 20 21# WARNING: The test labelled "testing request-ixfr option in view vs zone" 22# is fragile because it depends upon counting instances of records 23# in the log file - need a better approach <sdm> - until then, 24# if you add any tests above that point, you will break the test. 25 26SYSTEMTESTTOP=.. 27. $SYSTEMTESTTOP/conf.sh 28 29status=0 30 31DIGOPTS="+tcp +noadd +nosea +nostat +noquest +nocomm +nocmd" 32DIGCMD="$DIG $DIGOPTS @10.53.0.1 -p 5300" 33SENDCMD="$PERL ../send.pl 10.53.0.2 5301" 34RNDCCMD="$RNDC -s 10.53.0.1 -p 9953 -c ../common/rndc.conf" 35 36echo "I:testing initial AXFR" 37 38$SENDCMD <<EOF 39/SOA/ 40nil. 300 SOA ns.nil. root.nil. 1 300 300 604800 300 41/AXFR/ 42nil. 300 SOA ns.nil. root.nil. 1 300 300 604800 300 43/AXFR/ 44nil. 300 NS ns.nil. 45nil. 300 TXT "initial AXFR" 46a.nil. 60 A 10.0.0.61 47b.nil. 60 A 10.0.0.62 48/AXFR/ 49nil. 300 SOA ns.nil. root.nil. 1 300 300 604800 300 50EOF 51 52sleep 1 53 54# Initially, ns1 is not authoritative for anything (see setup.sh). 55# Now that ans is up and running with the right data, we make it 56# a slave for nil. 57 58cat <<EOF >>ns1/named.conf 59zone "nil" { 60 type slave; 61 file "myftp.db"; 62 masters { 10.53.0.2; }; 63}; 64EOF 65 66$RNDCCMD reload 67 68for i in 0 1 2 3 4 5 6 7 8 9 69do 70 $DIGCMD nil. SOA > dig.out 71 grep "SOA" dig.out > /dev/null && break 72 sleep 1 73done 74 75$DIGCMD nil. TXT | grep 'initial AXFR' >/dev/null || { 76 echo "I:failed" 77 status=1 78} 79 80echo "I:testing successful IXFR" 81 82# We change the IP address of a.nil., and the TXT record at the apex. 83# Then we do a SOA-only update. 84 85$SENDCMD <<EOF 86/SOA/ 87nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 88/IXFR/ 89nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 90nil. 300 SOA ns.nil. root.nil. 1 300 300 604800 300 91a.nil. 60 A 10.0.0.61 92nil. 300 TXT "initial AXFR" 93nil. 300 SOA ns.nil. root.nil. 2 300 300 604800 300 94nil. 300 TXT "successful IXFR" 95a.nil. 60 A 10.0.1.61 96nil. 300 SOA ns.nil. root.nil. 2 300 300 604800 300 97nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 98nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 99EOF 100 101sleep 1 102 103$RNDCCMD refresh nil 104 105sleep 2 106 107$DIGCMD nil. TXT | grep 'successful IXFR' >/dev/null || { 108 echo "I:failed" 109 status=1 110} 111 112echo "I:testing AXFR fallback after IXFR failure" 113 114# Provide a broken IXFR response and a working fallback AXFR response 115 116$SENDCMD <<EOF 117/SOA/ 118nil. 300 SOA ns.nil. root.nil. 4 300 300 604800 300 119/IXFR/ 120nil. 300 SOA ns.nil. root.nil. 4 300 300 604800 300 121nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 122nil. 300 TXT "delete-nonexistent-txt-record" 123nil. 300 SOA ns.nil. root.nil. 4 300 300 604800 300 124nil. 300 TXT "this-txt-record-would-be-added" 125nil. 300 SOA ns.nil. root.nil. 4 300 300 604800 300 126/AXFR/ 127nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 128/AXFR/ 129nil. 300 NS ns.nil. 130nil. 300 TXT "fallback AXFR" 131/AXFR/ 132nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 133EOF 134 135sleep 1 136 137$RNDCCMD refresh nil 138 139sleep 2 140 141$DIGCMD nil. TXT | grep 'fallback AXFR' >/dev/null || { 142 echo "I:failed" 143 status=1 144} 145 146echo "I:testing ixfr-from-differences option" 147# ns3 is master; ns4 is slave 148$CHECKZONE test. ns3/mytest.db > /dev/null 2>&1 149if [ $? -ne 0 ] 150then 151 echo "I:named-checkzone returned failure on ns3/mytest.db" 152fi 153# modify the master 154#echo "I: digging against master: " 155#$DIG $DIGOPTS @10.53.0.3 -p 5300 a host1.test. 156#echo "I: digging against slave: " 157#$DIG $DIGOPTS @10.53.0.4 -p 5300 a host1.test. 158 159cp ns3/mytest1.db ns3/mytest.db 160$RNDC -s 10.53.0.3 -p 9953 -c ../common/rndc.conf reload 161 162for i in 0 1 2 3 4 5 6 7 8 9 163do 164 $DIG +tcp -p 5300 @10.53.0.4 SOA test > dig.out 165 grep -i "hostmaster\.test\..2" dig.out > /dev/null && break 166 sleep 1 167done 168 169# slave should have gotten notify and updated 170 171for i in 0 1 2 3 4 5 6 7 8 9 172do 173 INCR=`grep "test/IN/primary" ns4/named.run|grep "got incremental"|wc -l` 174 [ $INCR -eq 1 ] && break 175 sleep 1 176done 177if [ $INCR -ne 1 ] 178then 179 echo "I:failed to get incremental response" 180 status=1 181fi 182 183echo "I:testing request-ixfr option in view vs zone" 184# There's a view with 2 zones. In the view, "request-ixfr yes" 185# but in the zone "sub.test", request-ixfr no" 186# we want to make sure that a change to sub.test results in AXFR, while 187# changes to test. result in IXFR 188 189echo "I: this result should be AXFR" 190cp ns3/subtest1.db ns3/subtest.db # change to sub.test zone, should be AXFR 191$RNDC -s 10.53.0.3 -p 9953 -c ../common/rndc.conf reload 192 193for i in 0 1 2 3 4 5 6 7 8 9 194do 195 $DIG +tcp -p 5300 @10.53.0.4 SOA sub.test > dig.out 196 grep -i "hostmaster\.test\..3" dig.out > /dev/null && break 197 sleep 1 198done 199 200echo "I: this result should be AXFR" 201for i in 0 1 2 3 4 5 6 7 8 9 202do 203 NONINCR=`grep 'sub\.test/IN/primary' ns4/named.run|grep "got nonincremental" | wc -l` 204 [ $NONINCR -eq 2 ] && break 205 sleep 1 206done 207if [ $NONINCR -ne 2 ] 208then 209 echo "I:failed to get nonincremental response in 2nd AXFR test" 210 status=1 211else 212 echo "I: success: AXFR it was" 213fi 214 215echo "I: this result should be IXFR" 216cp ns3/mytest2.db ns3/mytest.db # change to test zone, should be IXFR 217$RNDC -s 10.53.0.3 -p 9953 -c ../common/rndc.conf reload 218 219for i in 0 1 2 3 4 5 6 7 8 9 220do 221 $DIG +tcp -p 5300 @10.53.0.4 SOA test > dig.out 222 grep -i "hostmaster\.test\..4" dig.out > /dev/null && break 223 sleep 1 224done 225 226for i in 0 1 2 3 4 5 6 7 8 9 227do 228 INCR=`grep "test/IN/primary" ns4/named.run|grep "got incremental"|wc -l` 229 [ $INCR -eq 2 ] && break 230 sleep 1 231done 232if [ $INCR -ne 2 ] 233then 234 echo "I:failed to get incremental response in 2nd IXFR test" 235 status=1 236else 237 echo "I: success: IXFR it was" 238fi 239 240echo "I:testing DiG's handling of a multi message AXFR style IXFR response" 241( 242(sleep 10 && kill $$) 2>/dev/null & 243sub=$! 244$DIG ixfr=0 large -p 5300 @10.53.0.3 > dig.out 245kill $sub 246) 247lines=`grep hostmaster.large dig.out | wc -l` 248test ${lines:-0} -eq 2 || { echo "I:failed"; status=1; } 249messages=`sed -n 's/^;;.*messages \([0-9]*\),.*/\1/p' dig.out` 250test ${messages:-0} -gt 1 || { echo "I:failed"; status=1; } 251 252echo "I:test 'dig +notcp ixfr=<value>' vs 'dig ixfr=<value> +notcp' vs 'dig ixfr=<value>'" 253ret=0 254# Should be "switch to TCP" response 255$DIG +notcp ixfr=1 test -p 5300 @10.53.0.4 > dig.out1 || ret=1 256$DIG ixfr=1 +notcp test -p 5300 @10.53.0.4 > dig.out2 || ret=1 257$PERL ../digcomp.pl dig.out1 dig.out2 || ret=1 258awk '$4 == "SOA" { soacnt++} END {if (soacnt == 1) exit(0); else exit(1);}' dig.out1 || ret=1 259awk '$4 == "SOA" { if ($7 == 4) exit(0); else exit(1);}' dig.out1 || ret=1 260# Should be incremental transfer. 261$DIG ixfr=1 test -p 5300 @10.53.0.4 > dig.out3 || ret=1 262awk '$4 == "SOA" { soacnt++} END { if (soacnt == 6) exit(0); else exit(1);}' dig.out3 || ret=1 263if [ ${ret} != 0 ]; then 264 echo "I:failed"; 265 status=1; 266fi 267 268echo "I:exit status: $status" 269exit $status 270