]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use helper functions for checking resolution
authorMichał Kępień <michal@isc.org>
Wed, 29 May 2019 09:05:01 +0000 (11:05 +0200)
committerMichał Kępień <michal@isc.org>
Wed, 29 May 2019 09:11:37 +0000 (11:11 +0200)
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.

(cherry picked from commit effd16ab252e65fc4fe050cd125fd0462eca6408)

bin/tests/system/legacy/tests.sh

index 545ef0bd208e83c3fdb638c3685ecec19582fcd1..274493d5849dc5c7fb086413484838484c3a464d 100755 (executable)
@@ -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
 
@@ -36,8 +63,7 @@ status=`expr $status + $ret`
 n=`expr $n + 1`
 echo_i "checking recursive lookup to drop edns server succeeds ($n)"
 ret=0
-$DIG $DIGOPTS +tcp @10.53.0.1 dropedns soa > dig.out.test$n || ret=1
-grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
+resolution_succeeds dropedns. || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`
 
@@ -57,8 +83,7 @@ status=`expr $status + $ret`
 n=`expr $n + 1`
 echo_i "checking recursive lookup to drop edns + no tcp server succeeds ($n)"
 ret=0
-$DIG $DIGOPTS +tcp @10.53.0.1 dropedns-notcp soa > dig.out.test$n || ret=1
-grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
+resolution_succeeds dropedns-notcp. || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`
 
@@ -74,8 +99,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`
 
@@ -93,8 +117,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`
@@ -116,8 +139,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`
 
@@ -139,8 +161,7 @@ status=`expr $status + $ret`
 n=`expr $n + 1`
 echo_i "checking recursive lookup to edns 512 + no tcp server succeeds ($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_succeeds edns512-notcp. || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`
 
@@ -153,9 +174,7 @@ then
     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`
 else