Home | History | Annotate | Line # | Download | only in serve-stale
tests.sh revision 1.1.1.4
      1 #!/bin/sh
      2 #
      3 # Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      4 #
      5 # This Source Code Form is subject to the terms of the Mozilla Public
      6 # License, v. 2.0. If a copy of the MPL was not distributed with this
      7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      8 #
      9 # See the COPYRIGHT file distributed with this work for additional
     10 # information regarding copyright ownership.
     11 
     12 SYSTEMTESTTOP=..
     13 . $SYSTEMTESTTOP/conf.sh
     14 
     15 RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s"
     16 
     17 status=0
     18 n=0
     19 
     20 #echo_i "check ans.pl server ($n)"
     21 #$DIG -p ${PORT} @10.53.0.2 example NS
     22 #$DIG -p ${PORT} @10.53.0.2 example SOA
     23 #$DIG -p ${PORT} @10.53.0.2 ns.example A
     24 #$DIG -p ${PORT} @10.53.0.2 ns.example AAAA
     25 #$DIG -p ${PORT} @10.53.0.2 txt enable
     26 #$DIG -p ${PORT} @10.53.0.2 txt disable
     27 #$DIG -p ${PORT} @10.53.0.2 ns.example AAAA
     28 #$DIG -p ${PORT} @10.53.0.2 txt enable
     29 #$DIG -p ${PORT} @10.53.0.2 ns.example AAAA
     30 #$DIG -p ${PORT} @10.53.0.2 data.example TXT
     31 #$DIG -p ${PORT} @10.53.0.2 nodata.example TXT
     32 #$DIG -p ${PORT} @10.53.0.2 nxdomain.example TXT
     33 
     34 n=`expr $n + 1`
     35 echo_i "prime cache longttl.example ($n)"
     36 ret=0
     37 $DIG -p ${PORT} @10.53.0.1 longttl.example TXT > dig.out.test$n
     38 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
     39 grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
     40 if [ $ret != 0 ]; then echo_i "failed"; fi
     41 status=`expr $status + $ret`
     42 
     43 n=`expr $n + 1`
     44 echo_i "prime cache data.example ($n)"
     45 ret=0
     46 $DIG -p ${PORT} @10.53.0.1 data.example TXT > dig.out.test$n
     47 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
     48 grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
     49 if [ $ret != 0 ]; then echo_i "failed"; fi
     50 status=`expr $status + $ret`
     51 
     52 n=`expr $n + 1`
     53 echo_i "prime cache nodata.example ($n)"
     54 ret=0
     55 $DIG -p ${PORT} @10.53.0.1 nodata.example TXT > dig.out.test$n
     56 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
     57 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
     58 if [ $ret != 0 ]; then echo_i "failed"; fi
     59 status=`expr $status + $ret`
     60 
     61 n=`expr $n + 1`
     62 echo_i "prime cache nxdomain.example ($n)"
     63 ret=0
     64 $DIG -p ${PORT} @10.53.0.1 nxdomain.example TXT > dig.out.test$n
     65 grep "status: NXDOMAIN" dig.out.test$n > /dev/null || ret=1
     66 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
     67 if [ $ret != 0 ]; then echo_i "failed"; fi
     68 status=`expr $status + $ret`
     69 
     70 n=`expr $n + 1`
     71 echo_i "disable responses from authoritative server ($n)"
     72 ret=0
     73 $DIG -p ${PORT} @10.53.0.2 txt disable  > dig.out.test$n
     74 grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
     75 grep "TXT.\"0\"" dig.out.test$n > /dev/null || ret=1
     76 if [ $ret != 0 ]; then echo_i "failed"; fi
     77 status=`expr $status + $ret`
     78 
     79 sleep 1
     80 
     81 n=`expr $n + 1`
     82 echo_i "check 'rndc serve-stale status' ($n)"
     83 ret=0
     84 $RNDCCMD 10.53.0.1 serve-stale status > rndc.out.test$n 2>&1 || ret=1
     85 grep '_default: on (stale-answer-ttl=2 max-stale-ttl=3600)' rndc.out.test$n > /dev/null || ret=1
     86 if [ $ret != 0 ]; then echo_i "failed"; fi
     87 status=`expr $status + $ret`
     88 
     89 n=`expr $n + 1`
     90 echo_i "check stale data.example ($n)"
     91 ret=0
     92 $DIG -p ${PORT} @10.53.0.1 data.example TXT > dig.out.test$n
     93 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
     94 grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
     95 grep "data\.example\..*2.*IN.*TXT.*A text record with a 1 second ttl" dig.out.test$n > /dev/null || ret=1
     96 # Run rndc dumpdb, test whether the stale data has correct comment printed.
     97 # The max-stale-ttl is 3600 seconds, so the comment should say the data is
     98 # stale for somewhere between 3500-3599 seconds.
     99 $RNDCCMD 10.53.0.1 dumpdb > rndc.out.test$n 2>&1 || ret=1
    100 for i in 0 1 2 3 4 5 6 7 8 9; do
    101 	grep '^; Dump complete$' ns1/named_dump1.db > /dev/null 2>&1 && break
    102 	sleep 1
    103 done
    104 awk '/; stale/ { x=$0; getline; print x, $0}' ns1/named_dump1.db |
    105     grep "; stale (will be retained for 35.. more seconds) data\.example.*A text record with a 1 second ttl" > /dev/null 2>&1 || ret=1
    106 # Also make sure the not expired data does not have a stale comment.
    107 awk '/; answer/ { x=$0; getline; print x, $0}' ns1/named_dump1.db |
    108     grep "; answer longttl\.example.*A text record with a 600 second ttl" > /dev/null 2>&1 || ret=1
    109 if [ $ret != 0 ]; then echo_i "failed"; fi
    110 status=`expr $status + $ret`
    111 
    112 n=`expr $n + 1`
    113 echo_i "check stale nodata.example ($n)"
    114 ret=0
    115 $DIG -p ${PORT} @10.53.0.1 nodata.example TXT > dig.out.test$n
    116 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
    117 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    118 grep "example\..*2.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
    119 if [ $ret != 0 ]; then echo_i "failed"; fi
    120 status=`expr $status + $ret`
    121 
    122 n=`expr $n + 1`
    123 echo_i "check stale nxdomain.example ($n)"
    124 ret=0
    125 $DIG -p ${PORT} @10.53.0.1 nxdomain.example TXT > dig.out.test$n
    126 grep "status: NXDOMAIN" dig.out.test$n > /dev/null || ret=1
    127 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    128 grep "example\..*2.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
    129 if [ $ret != 0 ]; then echo_i "failed"; fi
    130 status=`expr $status + $ret`
    131 
    132 n=`expr $n + 1`
    133 echo_i "running 'rndc serve-stale off' ($n)"
    134 ret=0
    135 $RNDCCMD 10.53.0.1 serve-stale off || ret=1
    136 if [ $ret != 0 ]; then echo_i "failed"; fi
    137 status=`expr $status + $ret`
    138 
    139 n=`expr $n + 1`
    140 echo_i "check 'rndc serve-stale status' ($n)"
    141 ret=0
    142 $RNDCCMD 10.53.0.1 serve-stale status > rndc.out.test$n 2>&1 || ret=1
    143 grep '_default: off (rndc) (stale-answer-ttl=2 max-stale-ttl=3600)' rndc.out.test$n > /dev/null || ret=1
    144 if [ $ret != 0 ]; then echo_i "failed"; fi
    145 status=`expr $status + $ret`
    146 
    147 n=`expr $n + 1`
    148 echo_i "check stale data.example (serve-stale off) ($n)"
    149 ret=0
    150 $DIG -p ${PORT} @10.53.0.1 data.example TXT > dig.out.test$n
    151 grep "status: SERVFAIL" dig.out.test$n > /dev/null || ret=1
    152 if [ $ret != 0 ]; then echo_i "failed"; fi
    153 status=`expr $status + $ret`
    154 if [ $ret != 0 ]; then echo_i "failed"; fi
    155 status=`expr $status + $ret`
    156 
    157 n=`expr $n + 1`
    158 echo_i "check stale nodata.example (serve-stale off) ($n)"
    159 ret=0
    160 $DIG -p ${PORT} @10.53.0.1 nodata.example TXT > dig.out.test$n
    161 grep "status: SERVFAIL" dig.out.test$n > /dev/null || ret=1
    162 if [ $ret != 0 ]; then echo_i "failed"; fi
    163 status=`expr $status + $ret`
    164 
    165 n=`expr $n + 1`
    166 echo_i "check stale nxdomain.example (serve-stale off) ($n)"
    167 ret=0
    168 $DIG -p ${PORT} @10.53.0.1 nxdomain.example TXT > dig.out.test$n
    169 grep "status: SERVFAIL" dig.out.test$n > /dev/null || ret=1
    170 if [ $ret != 0 ]; then echo_i "failed"; fi
    171 status=`expr $status + $ret`
    172 
    173 n=`expr $n + 1`
    174 echo_i "running 'rndc serve-stale on' ($n)"
    175 ret=0
    176 $RNDCCMD 10.53.0.1 serve-stale on || ret=1
    177 if [ $ret != 0 ]; then echo_i "failed"; fi
    178 status=`expr $status + $ret`
    179 
    180 n=`expr $n + 1`
    181 echo_i "check 'rndc serve-stale status' ($n)"
    182 ret=0
    183 $RNDCCMD 10.53.0.1 serve-stale status > rndc.out.test$n 2>&1 || ret=1
    184 grep '_default: on (rndc) (stale-answer-ttl=2 max-stale-ttl=3600)' rndc.out.test$n > /dev/null || ret=1
    185 if [ $ret != 0 ]; then echo_i "failed"; fi
    186 status=`expr $status + $ret`
    187 
    188 n=`expr $n + 1`
    189 echo_i "check stale data.example (serve-stale on) ($n)"
    190 ret=0
    191 $DIG -p ${PORT} @10.53.0.1 data.example TXT > dig.out.test$n
    192 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
    193 grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
    194 grep "data\.example\..*2.*IN.*TXT.*A text record with a 1 second ttl" dig.out.test$n > /dev/null || ret=1
    195 if [ $ret != 0 ]; then echo_i "failed"; fi
    196 status=`expr $status + $ret`
    197 
    198 n=`expr $n + 1`
    199 echo_i "check stale nodata.example (serve-stale on) ($n)"
    200 ret=0
    201 $DIG -p ${PORT} @10.53.0.1 nodata.example TXT > dig.out.test$n
    202 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
    203 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    204 grep "example\..*2.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
    205 if [ $ret != 0 ]; then echo_i "failed"; fi
    206 status=`expr $status + $ret`
    207 
    208 n=`expr $n + 1`
    209 echo_i "check stale nxdomain.example (serve-stale on) ($n)"
    210 ret=0
    211 $DIG -p ${PORT} @10.53.0.1 nxdomain.example TXT > dig.out.test$n
    212 grep "status: NXDOMAIN" dig.out.test$n > /dev/null || ret=1
    213 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    214 grep "example\..*2.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
    215 if [ $ret != 0 ]; then echo_i "failed"; fi
    216 status=`expr $status + $ret`
    217 
    218 n=`expr $n + 1`
    219 echo_i "running 'rndc serve-stale no' ($n)"
    220 ret=0
    221 $RNDCCMD 10.53.0.1 serve-stale no || ret=1
    222 if [ $ret != 0 ]; then echo_i "failed"; fi
    223 status=`expr $status + $ret`
    224 
    225 n=`expr $n + 1`
    226 echo_i "check 'rndc serve-stale status' ($n)"
    227 ret=0
    228 $RNDCCMD 10.53.0.1 serve-stale status > rndc.out.test$n 2>&1 || ret=1
    229 grep '_default: off (rndc) (stale-answer-ttl=2 max-stale-ttl=3600)' rndc.out.test$n > /dev/null || ret=1
    230 if [ $ret != 0 ]; then echo_i "failed"; fi
    231 status=`expr $status + $ret`
    232 
    233 n=`expr $n + 1`
    234 echo_i "check stale data.example (serve-stale no) ($n)"
    235 ret=0
    236 $DIG -p ${PORT} @10.53.0.1 data.example TXT > dig.out.test$n
    237 grep "status: SERVFAIL" dig.out.test$n > /dev/null || ret=1
    238 if [ $ret != 0 ]; then echo_i "failed"; fi
    239 status=`expr $status + $ret`
    240 
    241 n=`expr $n + 1`
    242 echo_i "check stale nodata.example (serve-stale no) ($n)"
    243 ret=0
    244 $DIG -p ${PORT} @10.53.0.1 nodata.example TXT > dig.out.test$n
    245 grep "status: SERVFAIL" dig.out.test$n > /dev/null || ret=1
    246 if [ $ret != 0 ]; then echo_i "failed"; fi
    247 status=`expr $status + $ret`
    248 
    249 n=`expr $n + 1`
    250 echo_i "check stale nxdomain.example (serve-stale no) ($n)"
    251 ret=0
    252 $DIG -p ${PORT} @10.53.0.1 nxdomain.example TXT > dig.out.test$n
    253 grep "status: SERVFAIL" dig.out.test$n > /dev/null || ret=1
    254 if [ $ret != 0 ]; then echo_i "failed"; fi
    255 status=`expr $status + $ret`
    256 
    257 n=`expr $n + 1`
    258 echo_i "running 'rndc serve-stale yes' ($n)"
    259 ret=0
    260 $RNDCCMD 10.53.0.1 serve-stale yes || ret=1
    261 if [ $ret != 0 ]; then echo_i "failed"; fi
    262 status=`expr $status + $ret`
    263 
    264 n=`expr $n + 1`
    265 echo_i "check 'rndc serve-stale status' ($n)"
    266 ret=0
    267 $RNDCCMD 10.53.0.1 serve-stale status > rndc.out.test$n 2>&1 || ret=1
    268 grep '_default: on (rndc) (stale-answer-ttl=2 max-stale-ttl=3600)' rndc.out.test$n > /dev/null || ret=1
    269 if [ $ret != 0 ]; then echo_i "failed"; fi
    270 status=`expr $status + $ret`
    271 
    272 n=`expr $n + 1`
    273 echo_i "check stale data.example (serve-stale yes) ($n)"
    274 ret=0
    275 $DIG -p ${PORT} @10.53.0.1 data.example TXT > dig.out.test$n
    276 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
    277 grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
    278 grep "data\.example\..*2.*IN.*TXT.*A text record with a 1 second ttl" dig.out.test$n > /dev/null || ret=1
    279 if [ $ret != 0 ]; then echo_i "failed"; fi
    280 status=`expr $status + $ret`
    281 
    282 n=`expr $n + 1`
    283 echo_i "check stale nodata.example (serve-stale yes) ($n)"
    284 ret=0
    285 $DIG -p ${PORT} @10.53.0.1 nodata.example TXT > dig.out.test$n
    286 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
    287 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    288 grep "example\..*2.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
    289 if [ $ret != 0 ]; then echo_i "failed"; fi
    290 status=`expr $status + $ret`
    291 
    292 n=`expr $n + 1`
    293 echo_i "check stale nxdomain.example (serve-stale yes) ($n)"
    294 ret=0
    295 $DIG -p ${PORT} @10.53.0.1 nxdomain.example TXT > dig.out.test$n
    296 grep "status: NXDOMAIN" dig.out.test$n > /dev/null || ret=1
    297 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    298 grep "example\..*2.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
    299 if [ $ret != 0 ]; then echo_i "failed"; fi
    300 status=`expr $status + $ret`
    301 
    302 n=`expr $n + 1`
    303 echo_i "running 'rndc serve-stale off' ($n)"
    304 ret=0
    305 $RNDCCMD 10.53.0.1 serve-stale off || ret=1
    306 if [ $ret != 0 ]; then echo_i "failed"; fi
    307 status=`expr $status + $ret`
    308 
    309 n=`expr $n + 1`
    310 echo_i "running 'rndc serve-stale reset' ($n)"
    311 ret=0
    312 $RNDCCMD 10.53.0.1 serve-stale reset || ret=1
    313 if [ $ret != 0 ]; then echo_i "failed"; fi
    314 status=`expr $status + $ret`
    315 
    316 n=`expr $n + 1`
    317 echo_i "check 'rndc serve-stale status' ($n)"
    318 ret=0
    319 $RNDCCMD 10.53.0.1 serve-stale status > rndc.out.test$n 2>&1 || ret=1
    320 grep '_default: on (stale-answer-ttl=2 max-stale-ttl=3600)' rndc.out.test$n > /dev/null || ret=1
    321 if [ $ret != 0 ]; then echo_i "failed"; fi
    322 status=`expr $status + $ret`
    323 
    324 n=`expr $n + 1`
    325 echo_i "check stale data.example (serve-stale reset) ($n)"
    326 ret=0
    327 $DIG -p ${PORT} @10.53.0.1 data.example TXT > dig.out.test$n
    328 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
    329 grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
    330 grep "data\.example\..*2.*IN.*TXT.*A text record with a 1 second ttl" dig.out.test$n > /dev/null || ret=1
    331 if [ $ret != 0 ]; then echo_i "failed"; fi
    332 status=`expr $status + $ret`
    333 
    334 n=`expr $n + 1`
    335 echo_i "check stale nodata.example (serve-stale reset) ($n)"
    336 ret=0
    337 $DIG -p ${PORT} @10.53.0.1 nodata.example TXT > dig.out.test$n
    338 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
    339 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    340 grep "example\..*2.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
    341 if [ $ret != 0 ]; then echo_i "failed"; fi
    342 status=`expr $status + $ret`
    343 
    344 n=`expr $n + 1`
    345 echo_i "check stale nxdomain.example (serve-stale reset) ($n)"
    346 ret=0
    347 $DIG -p ${PORT} @10.53.0.1 nxdomain.example TXT > dig.out.test$n
    348 grep "status: NXDOMAIN" dig.out.test$n > /dev/null || ret=1
    349 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    350 grep "example\..*2.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
    351 if [ $ret != 0 ]; then echo_i "failed"; fi
    352 status=`expr $status + $ret`
    353 
    354 n=`expr $n + 1`
    355 echo_i "running 'rndc serve-stale off' ($n)"
    356 ret=0
    357 $RNDCCMD 10.53.0.1 serve-stale off || ret=1
    358 if [ $ret != 0 ]; then echo_i "failed"; fi
    359 status=`expr $status + $ret`
    360 
    361 n=`expr $n + 1`
    362 echo_i "check 'rndc serve-stale status' ($n)"
    363 ret=0
    364 $RNDCCMD 10.53.0.1 serve-stale status > rndc.out.test$n 2>&1 || ret=1
    365 grep '_default: off (rndc) (stale-answer-ttl=2 max-stale-ttl=3600)' rndc.out.test$n > /dev/null || ret=1
    366 if [ $ret != 0 ]; then echo_i "failed"; fi
    367 status=`expr $status + $ret`
    368 
    369 n=`expr $n + 1`
    370 echo_i "updating ns1/named.conf ($n)"
    371 ret=0
    372 copy_setports ns1/named2.conf.in ns1/named.conf
    373 if [ $ret != 0 ]; then echo_i "failed"; fi
    374 status=`expr $status + $ret`
    375 
    376 n=`expr $n + 1`
    377 echo_i "running 'rndc reload' ($n)"
    378 ret=0
    379 rndc_reload ns1 10.53.0.1
    380 if [ $ret != 0 ]; then echo_i "failed"; fi
    381 status=`expr $status + $ret`
    382 
    383 n=`expr $n + 1`
    384 echo_i "check 'rndc serve-stale status' ($n)"
    385 ret=0
    386 $RNDCCMD 10.53.0.1 serve-stale status > rndc.out.test$n 2>&1 || ret=1
    387 grep '_default: off (rndc) (stale-answer-ttl=3 max-stale-ttl=7200)' rndc.out.test$n > /dev/null || ret=1
    388 if [ $ret != 0 ]; then echo_i "failed"; fi
    389 status=`expr $status + $ret`
    390 
    391 n=`expr $n + 1`
    392 echo_i "check 'rndc serve-stale' ($n)"
    393 ret=0
    394 $RNDCCMD 10.53.0.1 serve-stale > rndc.out.test$n 2>&1 && ret=1
    395 grep "unexpected end of input" rndc.out.test$n > /dev/null || ret=1
    396 if [ $ret != 0 ]; then echo_i "failed"; fi
    397 status=`expr $status + $ret`
    398 
    399 n=`expr $n + 1`
    400 echo_i "check 'rndc serve-stale unknown' ($n)"
    401 ret=0
    402 $RNDCCMD 10.53.0.1 serve-stale unknown > rndc.out.test$n 2>&1 && ret=1
    403 grep "syntax error" rndc.out.test$n > /dev/null || ret=1
    404 if [ $ret != 0 ]; then echo_i "failed"; fi
    405 status=`expr $status + $ret`
    406 
    407 n=`expr $n + 1`
    408 echo_i "flush cache, re-enable serve-stale and query again ($n)"
    409 ret=0
    410 $RNDCCMD 10.53.0.1 flushtree example > rndc.out.test$n.1 2>&1 || ret=1
    411 $RNDCCMD 10.53.0.1 serve-stale on > rndc.out.test$n.2 2>&1 || ret=1
    412 $DIG -p ${PORT} @10.53.0.1 data.example TXT > dig.out.test$n
    413 grep "status: SERVFAIL" dig.out.test$n > /dev/null || ret=1
    414 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    415 if [ $ret != 0 ]; then echo_i "failed"; fi
    416 status=`expr $status + $ret`
    417 
    418 n=`expr $n + 1`
    419 echo_i "enable responses from authoritative server ($n)"
    420 ret=0
    421 $DIG -p ${PORT} @10.53.0.2 txt enable  > dig.out.test$n
    422 grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
    423 grep "TXT.\"1\"" dig.out.test$n > /dev/null || ret=1
    424 if [ $ret != 0 ]; then echo_i "failed"; fi
    425 status=`expr $status + $ret`
    426 
    427 n=`expr $n + 1`
    428 echo_i "prime cache data.example (max-stale-ttl default) ($n)"
    429 ret=0
    430 $DIG -p ${PORT} @10.53.0.3 data.example TXT > dig.out.test$n
    431 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
    432 grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
    433 grep "data\.example\..*1.*IN.*TXT.*A text record with a 1 second ttl" dig.out.test$n > /dev/null || ret=1
    434 if [ $ret != 0 ]; then echo_i "failed"; fi
    435 status=`expr $status + $ret`
    436 
    437 n=`expr $n + 1`
    438 echo_i "prime cache nodata.example (max-stale-ttl default) ($n)"
    439 ret=0
    440 $DIG -p ${PORT} @10.53.0.3 nodata.example TXT > dig.out.test$n
    441 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
    442 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    443 grep "example\..*1.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
    444 if [ $ret != 0 ]; then echo_i "failed"; fi
    445 status=`expr $status + $ret`
    446 
    447 n=`expr $n + 1`
    448 echo_i "prime cache nxdomain.example (max-stale-ttl default) ($n)"
    449 ret=0
    450 $DIG -p ${PORT} @10.53.0.3 nxdomain.example TXT > dig.out.test$n
    451 grep "status: NXDOMAIN" dig.out.test$n > /dev/null || ret=1
    452 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    453 grep "example\..*1.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
    454 if [ $ret != 0 ]; then echo_i "failed"; fi
    455 status=`expr $status + $ret`
    456 
    457 n=`expr $n + 1`
    458 echo_i "disable responses from authoritative server ($n)"
    459 ret=0
    460 $DIG -p ${PORT} @10.53.0.2 txt disable  > dig.out.test$n
    461 grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
    462 grep "TXT.\"0\"" dig.out.test$n > /dev/null || ret=1
    463 if [ $ret != 0 ]; then echo_i "failed"; fi
    464 status=`expr $status + $ret`
    465 
    466 sleep 1
    467 
    468 n=`expr $n + 1`
    469 echo_i "check 'rndc serve-stale status' ($n)"
    470 ret=0
    471 $RNDCCMD 10.53.0.3 serve-stale status > rndc.out.test$n 2>&1 || ret=1
    472 grep '_default: off (stale-answer-ttl=1 max-stale-ttl=604800)' rndc.out.test$n > /dev/null || ret=1
    473 if [ $ret != 0 ]; then echo_i "failed"; fi
    474 status=`expr $status + $ret`
    475 
    476 n=`expr $n + 1`
    477 echo_i "check fail of data.example (max-stale-ttl default) ($n)"
    478 ret=0
    479 $DIG -p ${PORT} @10.53.0.3 data.example TXT > dig.out.test$n
    480 grep "status: SERVFAIL" dig.out.test$n > /dev/null || ret=1
    481 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    482 if [ $ret != 0 ]; then echo_i "failed"; fi
    483 status=`expr $status + $ret`
    484 
    485 n=`expr $n + 1`
    486 echo_i "check fail of nodata.example (max-stale-ttl default) ($n)"
    487 ret=0
    488 $DIG -p ${PORT} @10.53.0.3 nodata.example TXT > dig.out.test$n
    489 grep "status: SERVFAIL" dig.out.test$n > /dev/null || ret=1
    490 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    491 if [ $ret != 0 ]; then echo_i "failed"; fi
    492 status=`expr $status + $ret`
    493 
    494 n=`expr $n + 1`
    495 echo_i "check fail of nxdomain.example (max-stale-ttl default) ($n)"
    496 ret=0
    497 $DIG -p ${PORT} @10.53.0.3 nxdomain.example TXT > dig.out.test$n
    498 grep "status: SERVFAIL" dig.out.test$n > /dev/null || ret=1
    499 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    500 if [ $ret != 0 ]; then echo_i "failed"; fi
    501 status=`expr $status + $ret`
    502 
    503 n=`expr $n + 1`
    504 echo_i "check 'rndc serve-stale on' ($n)"
    505 ret=0
    506 $RNDCCMD 10.53.0.3 serve-stale on > rndc.out.test$n 2>&1 || ret=1
    507 if [ $ret != 0 ]; then echo_i "failed"; fi
    508 status=`expr $status + $ret`
    509 
    510 n=`expr $n + 1`
    511 echo_i "check 'rndc serve-stale status' ($n)"
    512 ret=0
    513 $RNDCCMD 10.53.0.3 serve-stale status > rndc.out.test$n 2>&1 || ret=1
    514 grep '_default: on (rndc) (stale-answer-ttl=1 max-stale-ttl=604800)' rndc.out.test$n > /dev/null || ret=1
    515 if [ $ret != 0 ]; then echo_i "failed"; fi
    516 status=`expr $status + $ret`
    517 
    518 n=`expr $n + 1`
    519 echo_i "check data.example (max-stale-ttl default) ($n)"
    520 ret=0
    521 $DIG -p ${PORT} @10.53.0.3 data.example TXT > dig.out.test$n
    522 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
    523 grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
    524 grep "data\.example\..*1.*IN.*TXT.*A text record with a 1 second ttl" dig.out.test$n > /dev/null || ret=1
    525 if [ $ret != 0 ]; then echo_i "failed"; fi
    526 status=`expr $status + $ret`
    527 
    528 n=`expr $n + 1`
    529 echo_i "check nodata.example (max-stale-ttl default) ($n)"
    530 ret=0
    531 $DIG -p ${PORT} @10.53.0.3 nodata.example TXT > dig.out.test$n
    532 grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
    533 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    534 grep "example\..*1.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
    535 if [ $ret != 0 ]; then echo_i "failed"; fi
    536 status=`expr $status + $ret`
    537 
    538 n=`expr $n + 1`
    539 echo_i "check nxdomain.example (max-stale-ttl default) ($n)"
    540 ret=0
    541 $DIG -p ${PORT} @10.53.0.3 nxdomain.example TXT > dig.out.test$n
    542 grep "status: NXDOMAIN" dig.out.test$n > /dev/null || ret=1
    543 grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
    544 grep "example\..*1.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
    545 if [ $ret != 0 ]; then echo_i "failed"; fi
    546 status=`expr $status + $ret`
    547 
    548 echo_i "exit status: $status"
    549 [ $status -eq 0 ] || exit 1
    550