1#!/bin/sh 2# 3# Copyright (C) 2004, 2007, 2011-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.10 2011/09/01 05:28:14 marka Exp 19 20SYSTEMTESTTOP=.. 21. $SYSTEMTESTTOP/conf.sh 22 23status=0 24 25RNDCOPTS="-c ../common/rndc.conf -s 10.53.0.2 -p 9953" 26DIGOPTS="+nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm \ 27 +nostat @10.53.0.2 -p 5300" 28 29# fill the cache with nodes from flushtest.example zone 30load_cache () { 31 # empty all existing cache data 32 $RNDC $RNDCOPTS flush 33 34 # load the positive cache entries 35 $DIG $DIGOPTS -f - << EOF > /dev/null 2>&1 36txt top1.flushtest.example 37txt second1.top1.flushtest.example 38txt third1.second1.top1.flushtest.example 39txt third2.second1.top1.flushtest.example 40txt second2.top1.flushtest.example 41txt second3.top1.flushtest.example 42txt second1.top2.flushtest.example 43txt second2.top2.flushtest.example 44txt second3.top2.flushtest.example 45txt top3.flushtest.example 46txt second1.top3.flushtest.example 47txt third1.second1.top3.flushtest.example 48txt third2.second1.top3.flushtest.example 49txt third1.second2.top3.flushtest.example 50txt third2.second2.top3.flushtest.example 51txt second3.top3.flushtest.example 52EOF 53 54 # load the negative cache entries 55 # nxrrset: 56 $DIG $DIGOPTS a third1.second1.top1.flushtest.example > /dev/null 57 # nxdomain: 58 $DIG $DIGOPTS txt top4.flushtest.example > /dev/null 59 # empty nonterminal: 60 $DIG $DIGOPTS txt second2.top3.flushtest.example > /dev/null 61 62 # sleep 2 seconds ensure the TTLs will be lower on cached data 63 sleep 2 64} 65 66dump_cache () { 67 rm -f ns2/named_dump.db 68 $RNDC $RNDCOPTS dumpdb -cache _default 69 sleep 1 70} 71 72clear_cache () { 73 $RNDC $RNDCOPTS flush 74} 75 76in_cache () { 77 ttl=`$DIG $DIGOPTS "$@" | awk '{print $2}'` 78 [ -z "$ttl" ] && { 79 ttl=`$DIG $DIGOPTS +noanswer +auth "$@" | awk '{print $2}'` 80 [ "$ttl" -ge 3599 ] && return 1 81 return 0 82 } 83 [ "$ttl" -ge 3599 ] && return 1 84 return 0 85} 86 87echo "I:check correctness of routine cache cleaning" 88$DIG $DIGOPTS +tcp +keepopen -b 10.53.0.7 -f dig.batch > dig.out.ns2 || status=1 89grep ";" dig.out.ns2 90 91$PERL ../digcomp.pl --lc dig.out.ns2 knowngood.dig.out || status=1 92 93echo "I:only one tcp socket was used" 94tcpclients=`grep "client 10.53.0.7#[0-9]*:" ns2/named.run | awk '{print $4}' | sort | uniq -c | wc -l` 95 96test $tcpclients -eq 1 || { status=1; echo "I:failed"; } 97 98echo "I:reset and check that records are correctly cached initially" 99ret=0 100load_cache 101dump_cache 102nrecords=`grep flushtest.example ns2/named_dump.db | grep -v '^;' | egrep '(TXT|ANY)'| wc -l` 103[ $nrecords -eq 17 ] || { ret=1; echo "I: found $nrecords records expected 17"; } 104if [ $ret != 0 ]; then echo "I:failed"; fi 105status=`expr $status + $ret` 106 107echo "I:check flushing of the full cache" 108ret=0 109clear_cache 110dump_cache 111nrecords=`grep flushtest.example ns2/named_dump.db | grep -v '^;' | wc -l` 112[ $nrecords -eq 0 ] || ret=1 113if [ $ret != 0 ]; then echo "I:failed"; fi 114status=`expr $status + $ret` 115 116echo "I:check flushing of individual nodes (interior node)" 117ret=0 118clear_cache 119load_cache 120# interior node 121in_cache txt top1.flushtest.example || ret=1 122$RNDC $RNDCOPTS flushname top1.flushtest.example 123in_cache txt top1.flushtest.example && ret=1 124if [ $ret != 0 ]; then echo "I:failed"; fi 125status=`expr $status + $ret` 126 127echo "I:check flushing of individual nodes (leaf node, under the interior node)" 128ret=0 129# leaf node, under the interior node (should still exist) 130in_cache txt third2.second1.top1.flushtest.example || ret=1 131$RNDC $RNDCOPTS flushname third2.second1.top1.flushtest.example 132in_cache txt third2.second1.top1.flushtest.example && ret=1 133if [ $ret != 0 ]; then echo "I:failed"; fi 134status=`expr $status + $ret` 135 136echo "I:check flushing of individual nodes (another leaf node, with both positive and negative cache entries)" 137ret=0 138# another leaf node, with both positive and negative cache entries 139in_cache a third1.second1.top1.flushtest.example || ret=1 140in_cache txt third1.second1.top1.flushtest.example || ret=1 141$RNDC $RNDCOPTS flushname third1.second1.top1.flushtest.example 142in_cache a third1.second1.top1.flushtest.example && ret=1 143in_cache txt third1.second1.top1.flushtest.example && ret=1 144if [ $ret != 0 ]; then echo "I:failed"; fi 145status=`expr $status + $ret` 146 147echo "I:check flushing a nonexistent name" 148ret=0 149$RNDC $RNDCOPTS flushname fake.flushtest.example || ret=1 150if [ $ret != 0 ]; then echo "I:failed"; fi 151status=`expr $status + $ret` 152 153echo "I:check flushing of namespaces" 154ret=0 155clear_cache 156load_cache 157# flushing leaf node should leave the interior node: 158in_cache txt third1.second1.top1.flushtest.example || ret=1 159in_cache txt top1.flushtest.example || ret=1 160$RNDC $RNDCOPTS flushtree third1.second1.top1.flushtest.example 161in_cache txt third1.second1.top1.flushtest.example && ret=1 162in_cache txt top1.flushtest.example || ret=1 163in_cache txt second1.top1.flushtest.example || ret=1 164in_cache txt third2.second1.top1.flushtest.example || ret=1 165$RNDC $RNDCOPTS flushtree second1.top1.flushtest.example 166in_cache txt top1.flushtest.example || ret=1 167in_cache txt second1.top1.flushtest.example && ret=1 168in_cache txt third2.second1.top1.flushtest.example && ret=1 169 170# flushing from an empty node should still remove all its children 171in_cache txt second1.top2.flushtest.example || ret=1 172$RNDC $RNDCOPTS flushtree top2.flushtest.example 173in_cache txt second1.top2.flushtest.example && ret=1 174in_cache txt second2.top2.flushtest.example && ret=1 175in_cache txt second3.top2.flushtest.example && ret=1 176if [ $ret != 0 ]; then echo "I:failed"; fi 177status=`expr $status + $ret` 178 179echo "I:check flushing a nonexistent namespace" 180ret=0 181$RNDC $RNDCOPTS flushtree fake.flushtest.example || ret=1 182if [ $ret != 0 ]; then echo "I:failed"; fi 183status=`expr $status + $ret` 184 185echo "I:check the number of cached records remaining" 186ret=0 187dump_cache 188nrecords=`grep flushtest.example ns2/named_dump.db | grep -v '^;' | egrep '(TXT|ANY)' | wc -l` 189[ $nrecords -eq 17 ] || { ret=1; echo "I: found $nrecords records expected 17"; } 190if [ $ret != 0 ]; then echo "I:failed"; fi 191status=`expr $status + $ret` 192 193echo "I:check flushtree clears adb correctly" 194ret=0 195load_cache 196dump_cache 197awk '/plain success\/timeout/ {getline; getline; if ($2 == "ns.flushtest.example") exit(0); exit(1); }' ns2/named_dump.db || ret=1 198$RNDC $RNDCOPTS flushtree flushtest.example || ret=1 199dump_cache 200awk '/plain success\/timeout/ {getline; getline; if ($2 == "ns.flushtest.example") exit(1); exit(0); }' ns2/named_dump.db || ret=1 201if [ $ret != 0 ]; then echo "I:failed"; fi 202status=`expr $status + $ret` 203 204echo "I:check expire option returned from slave zone" 205ret=0 206$DIG @10.53.0.2 -p 5300 +expire soa expire-test > dig.out.expire 207grep EXPIRE: dig.out.expire > /dev/null || ret=1 208if [ $ret != 0 ]; then echo "I:failed"; fi 209status=`expr $status + $ret` 210 211echo "I:exit status: $status" 212exit $status 213