mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
Use helper functions for checking resolution
Extract repeated dig and grep calls into two helper shell functions, resolution_succeeds() and resolution_fails(), in order to reduce code duplication in the "legacy" system test, emphasize the similarity between all the resolution checks in that test, and make the conditions for success and failure uniform for all resolution checks in that test.
This commit is contained in:
@@ -14,6 +14,33 @@ SYSTEMTESTTOP=..
|
||||
|
||||
DIGOPTS="-p ${PORT} +tries=3 +time=5"
|
||||
|
||||
# Check whether the SOA record for the name provided in $1 can be resolved by
|
||||
# ns1. Return 0 if resolution succeeds as expected; return 1 otherwise.
|
||||
resolution_succeeds() {
|
||||
_ret=0
|
||||
$DIG $DIGOPTS +tcp @10.53.0.1 ${1} SOA > dig.out.test$n || _ret=1
|
||||
grep "status: NOERROR" dig.out.test$n > /dev/null || _ret=1
|
||||
return $_ret
|
||||
}
|
||||
|
||||
# Check whether the SOA record for the name provided in $1 can be resolved by
|
||||
# ns1. Return 0 if resolution fails as expected; return 1 otherwise. Note that
|
||||
# both a SERVFAIL response and timing out mean resolution failed, so the exit
|
||||
# code of dig does not influence the result (the exit code for a SERVFAIL
|
||||
# response is 0 while the exit code for not getting a response at all is not 0).
|
||||
resolution_fails() {
|
||||
_servfail=0
|
||||
_timeout=0
|
||||
$DIG $DIGOPTS +tcp @10.53.0.1 ${1} SOA > dig.out.test$n
|
||||
grep "status: SERVFAIL" dig.out.test$n > /dev/null && _servfail=1
|
||||
grep "connection timed out" dig.out.test$n > /dev/null && _timeout=1
|
||||
if [ $_servfail -eq 1 ] || [ $_timeout -eq 1 ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
status=0
|
||||
n=0
|
||||
|
||||
@@ -30,8 +57,7 @@ status=`expr $status + $ret`
|
||||
n=`expr $n + 1`
|
||||
echo_i "checking recursive lookup to formerr edns server succeeds ($n)"
|
||||
ret=0
|
||||
$DIG $DIGOPTS +tcp @10.53.0.1 ednsformerr soa > dig.out.test$n || ret=1
|
||||
grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
|
||||
resolution_succeeds ednsformerr. || ret=1
|
||||
if [ $ret != 0 ]; then echo_i "failed"; fi
|
||||
status=`expr $status + $ret`
|
||||
|
||||
@@ -48,8 +74,7 @@ status=`expr $status + $ret`
|
||||
n=`expr $n + 1`
|
||||
echo_i "checking recursive lookup to notimp edns server fails ($n)"
|
||||
ret=0
|
||||
$DIG $DIGOPTS +tcp @10.53.0.1 ednsnotimp soa > dig.out.test$n
|
||||
grep "status: NOERROR" dig.out.test$n > /dev/null && ret=1
|
||||
resolution_fails ednsnotimp. || ret=1
|
||||
if [ $ret != 0 ]; then echo_i "failed"; fi
|
||||
status=`expr $status + $ret`
|
||||
|
||||
@@ -66,8 +91,7 @@ status=`expr $status + $ret`
|
||||
n=`expr $n + 1`
|
||||
echo_i "checking recursive lookup to refused edns server fails ($n)"
|
||||
ret=0
|
||||
$DIG $DIGOPTS +tcp @10.53.0.1 ednsrefused soa > dig.out.test$n
|
||||
grep "status: NOERROR" dig.out.test$n > /dev/null && ret=1
|
||||
resolution_fails ednsrefused. || ret=1
|
||||
if [ $ret != 0 ]; then echo_i "failed"; fi
|
||||
status=`expr $status + $ret`
|
||||
|
||||
@@ -90,8 +114,7 @@ status=`expr $status + $ret`
|
||||
n=`expr $n + 1`
|
||||
echo_i "checking recursive lookup to drop edns server fails ($n)"
|
||||
ret=0
|
||||
$DIG $DIGOPTS +tcp @10.53.0.1 dropedns soa > dig.out.test$n
|
||||
grep "status: NOERROR" dig.out.test$n > /dev/null && ret=1
|
||||
resolution_fails dropedns. || ret=1
|
||||
if [ $ret != 0 ]; then echo_i "failed"; fi
|
||||
status=`expr $status + $ret`
|
||||
|
||||
@@ -111,8 +134,7 @@ status=`expr $status + $ret`
|
||||
n=`expr $n + 1`
|
||||
echo_i "checking recursive lookup to drop edns + no tcp server fails ($n)"
|
||||
ret=0
|
||||
$DIG $DIGOPTS +tcp @10.53.0.1 dropedns-notcp soa > dig.out.test$n
|
||||
grep "status: NOERROR" dig.out.test$n > /dev/null && ret=1
|
||||
resolution_fails dropedns-notcp. || ret=1
|
||||
if [ $ret != 0 ]; then echo_i "failed"; fi
|
||||
status=`expr $status + $ret`
|
||||
|
||||
@@ -128,8 +150,7 @@ status=`expr $status + $ret`
|
||||
n=`expr $n + 1`
|
||||
echo_i "checking recursive lookup to plain dns server succeeds ($n)"
|
||||
ret=0
|
||||
$DIG $DIGOPTS +tcp @10.53.0.1 plain soa > dig.out.test$n || ret=1
|
||||
grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
|
||||
resolution_succeeds plain. || ret=1
|
||||
if [ $ret != 0 ]; then echo_i "failed"; fi
|
||||
status=`expr $status + $ret`
|
||||
|
||||
@@ -147,8 +168,7 @@ status=`expr $status + $ret`
|
||||
n=`expr $n + 1`
|
||||
echo_i "checking recursive lookup to plain dns + no tcp server succeeds ($n)"
|
||||
ret=0
|
||||
$DIG $DIGOPTS +tcp @10.53.0.1 plain-notcp soa > dig.out.test$n || ret=1
|
||||
grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
|
||||
resolution_succeeds plain-notcp. || ret=1
|
||||
if [ $ret != 0 ]; then echo_i "failed"; fi
|
||||
status=`expr $status + $ret`
|
||||
n=`expr $n + 1`
|
||||
@@ -170,8 +190,7 @@ status=`expr $status + $ret`
|
||||
n=`expr $n + 1`
|
||||
echo_i "checking recursive lookup to edns 512 server succeeds ($n)"
|
||||
ret=0
|
||||
$DIG $DIGOPTS +tcp @10.53.0.1 edns512 soa > dig.out.test$n || ret=1
|
||||
grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
|
||||
resolution_succeeds edns512. || ret=1
|
||||
if [ $ret != 0 ]; then echo_i "failed"; fi
|
||||
status=`expr $status + $ret`
|
||||
|
||||
@@ -193,8 +212,7 @@ status=`expr $status + $ret`
|
||||
n=`expr $n + 1`
|
||||
echo_i "checking recursive lookup to edns 512 + no tcp server fails ($n)"
|
||||
ret=0
|
||||
$DIG $DIGOPTS +tcp @10.53.0.1 edns512-notcp soa > dig.out.test$n || ret=1
|
||||
grep "status: NOERROR" dig.out.test$n > /dev/null && ret=1
|
||||
resolution_fails edns512-notcp. || ret=1
|
||||
if [ $ret != 0 ]; then echo_i "failed"; fi
|
||||
status=`expr $status + $ret`
|
||||
|
||||
@@ -205,9 +223,7 @@ $PERL $SYSTEMTESTTOP/start.pl --noclean --restart --port ${PORT} legacy ns1
|
||||
n=`expr $n + 1`
|
||||
echo_i "checking recursive lookup to edns 512 + no tcp + trust anchor fails ($n)"
|
||||
ret=0
|
||||
$DIG $DIGOPTS +tcp @10.53.0.1 edns512-notcp soa > dig.out.test$n
|
||||
grep "status: SERVFAIL" dig.out.test$n > /dev/null ||
|
||||
grep "connection timed out;" dig.out.test$n > /dev/null || ret=1
|
||||
resolution_fails edns512-notcp. || ret=1
|
||||
if [ $ret != 0 ]; then echo_i "failed"; fi
|
||||
status=`expr $status + $ret`
|
||||
|
||||
|
Reference in New Issue
Block a user