230545
From 221fb11e658e7dea1be6dbfd25e149f2d131e4fb Mon Sep 17 00:00:00 2001
230545
From: Mark Andrews <marka@isc.org>
230545
Date: Wed, 29 Jul 2020 23:36:03 +1000
230545
Subject: [PATCH] Add a test for update-policy 'subdomain'
230545
230545
The new test checks that 'update-policy subdomain' is properly enforced.
230545
230545
(cherry picked from commit 393e8f643c02215fa4e6d4edf67be7d77085da0e)
230545
230545
Add a test for update-policy 'zonesub'
230545
230545
The new test checks that 'update-policy zonesub' is properly enforced.
230545
230545
(cherry picked from commit 58e560beb50873c699f3431cf57e215dc645d7aa)
230545
---
230545
 bin/tests/system/nsupdate/ns1/named.conf.in | 12 +++++
230545
 bin/tests/system/nsupdate/tests.sh          | 60 +++++++++++++++++++--
230545
 2 files changed, 68 insertions(+), 4 deletions(-)
230545
230545
diff --git a/bin/tests/system/nsupdate/ns1/named.conf.in b/bin/tests/system/nsupdate/ns1/named.conf.in
230545
index 26b6b7c9ab..540a984842 100644
230545
--- a/bin/tests/system/nsupdate/ns1/named.conf.in
230545
+++ b/bin/tests/system/nsupdate/ns1/named.conf.in
230545
@@ -36,6 +36,16 @@ key altkey {
230545
 	secret "1234abcd8765";
230545
 };
230545
 
230545
+key restricted.example.nil {
230545
+	algorithm hmac-md5;
230545
+	secret "1234abcd8765";
230545
+};
230545
+
230545
+key zonesub-key.example.nil {
230545
+	algorithm hmac-md5;
230545
+	secret "1234subk8765";
230545
+};
230545
+
230545
 include "ddns.key";
230545
 
230545
 zone "example.nil" {
230545
@@ -44,7 +54,9 @@ zone "example.nil" {
230545
 	check-integrity no;
230545
 	check-mx ignore;
230545
 	update-policy {
230545
+		grant zonesub-key.example.nil zonesub TXT;
230545
 		grant ddns-key.example.nil subdomain example.nil ANY;
230545
+		grant restricted.example.nil subdomain restricted.example.nil ANY;
230545
 	};
230545
 	allow-transfer { any; };
230545
 };
230545
diff --git a/bin/tests/system/nsupdate/tests.sh b/bin/tests/system/nsupdate/tests.sh
230545
index b08c5220e7..5f09e8c5bf 100755
230545
--- a/bin/tests/system/nsupdate/tests.sh
230545
+++ b/bin/tests/system/nsupdate/tests.sh
230545
@@ -428,7 +428,7 @@ EOF
230545
 # this also proves that the server is still running.
230545
 $DIG $DIGOPTS +tcp +noadd +nosea +nostat +noquest +nocmd +norec example.\
230545
 	@10.53.0.3 nsec3param > dig.out.ns3.$n || ret=1
230545
-grep "ANSWER: 0" dig.out.ns3.$n > /dev/null || ret=1
230545
+grep "ANSWER: 0," dig.out.ns3.$n > /dev/null || ret=1
230545
 grep "flags:[^;]* aa[ ;]" dig.out.ns3.$n > /dev/null || ret=1
230545
 [ $ret = 0 ] || { echo_i "failed"; status=1; }
230545
 
230545
@@ -443,7 +443,7 @@ EOF
230545
 
230545
 $DIG $DIGOPTS +tcp +noadd +nosea +nostat +noquest +nocmd +norec nsec3param.test.\
230545
         @10.53.0.3 nsec3param > dig.out.ns3.$n || ret=1
230545
-grep "ANSWER: 1" dig.out.ns3.$n > /dev/null || ret=1
230545
+grep "ANSWER: 1," dig.out.ns3.$n > /dev/null || ret=1
230545
 grep "3600.*NSEC3PARAM" dig.out.ns3.$n > /dev/null || ret=1
230545
 grep "flags:[^;]* aa[ ;]" dig.out.ns3.$n > /dev/null || ret=1
230545
 [ $ret = 0 ] || { echo_i "failed"; status=1; }
230545
@@ -460,7 +460,7 @@ EOF
230545
 _ret=1
230545
 for i in 0 1 2 3 4 5 6 7 8 9; do
230545
 	$DIG $DIGOPTS +tcp +norec +time=1 +tries=1 @10.53.0.3 nsec3param.test. NSEC3PARAM > dig.out.ns3.$n || _ret=1
230545
-	if grep "ANSWER: 2" dig.out.ns3.$n > /dev/null; then
230545
+	if grep "ANSWER: 2," dig.out.ns3.$n > /dev/null; then
230545
 		_ret=0
230545
 		break
230545
 	fi
230545
@@ -485,7 +485,7 @@ EOF
230545
 _ret=1
230545
 for i in 0 1 2 3 4 5 6 7 8 9; do
230545
 	$DIG $DIGOPTS +tcp +norec +time=1 +tries=1 @10.53.0.3 nsec3param.test. NSEC3PARAM > dig.out.ns3.$n || _ret=1
230545
-	if grep "ANSWER: 1" dig.out.ns3.$n > /dev/null; then
230545
+	if grep "ANSWER: 1," dig.out.ns3.$n > /dev/null; then
230545
 		_ret=0
230545
 		break
230545
 	fi
230545
@@ -631,6 +631,58 @@ then
230545
 echo_i "failed"; status=1
230545
 fi
230545
 
230545
+n=`expr $n + 1`
230545
+ret=0
230545
+echo_i "check that 'update-policy subdomain' is properly enforced ($n)"
230545
+# "restricted.example.nil" matches "grant ... subdomain restricted.example.nil"
230545
+# and thus this UPDATE should succeed.
230545
+$NSUPDATE -d <<END > nsupdate.out1-$n 2>&1 || ret=1
230545
+server 10.53.0.1 ${PORT}
230545
+key restricted.example.nil 1234abcd8765
230545
+update add restricted.example.nil 0 IN TXT everywhere.
230545
+send
230545
+END
230545
+$DIG $DIGOPTS +tcp @10.53.0.1 restricted.example.nil TXT > dig.out.1.test$n || ret=1
230545
+grep "TXT.*everywhere" dig.out.1.test$n > /dev/null || ret=1
230545
+# "example.nil" does not match "grant ... subdomain restricted.example.nil" and
230545
+# thus this UPDATE should fail.
230545
+$NSUPDATE -d <<END > nsupdate.out2-$n 2>&1 && ret=1
230545
+server 10.53.0.1 ${PORT}
230545
+key restricted.example.nil 1234abcd8765
230545
+update add example.nil 0 IN TXT everywhere.
230545
+send
230545
+END
230545
+$DIG $DIGOPTS +tcp @10.53.0.1 example.nil TXT > dig.out.2.test$n || ret=1
230545
+grep "TXT.*everywhere" dig.out.2.test$n > /dev/null && ret=1
230545
+[ $ret = 0 ] || { echo_i "failed"; status=1; }
230545
+
230545
+n=`expr $n + 1`
230545
+ret=0
230545
+echo_i "check that 'update-policy zonesub' is properly enforced ($n)"
230545
+# grant zonesub-key.example.nil zonesub TXT;
230545
+# the A record update should be rejected as it is not in the type list
230545
+$NSUPDATE -d <<END > nsupdate.out1-$n 2>&1 && ret=1
230545
+server 10.53.0.1 ${PORT}
230545
+key zonesub-key.example.nil 1234subk8765
230545
+update add zonesub.example.nil 0 IN A 1.2.3.4
230545
+send
230545
+END
230545
+$DIG $DIGOPTS +tcp @10.53.0.1 zonesub.example.nil A > dig.out.1.test$n || ret=1
230545
+grep "status: REFUSED" nsupdate.out1-$n > /dev/null || ret=1
230545
+grep "ANSWER: 0," dig.out.1.test$n > /dev/null || ret=1
230545
+# the TXT record update should be accepted as it is in the type list
230545
+$NSUPDATE -d <<END > nsupdate.out2-$n 2>&1 || ret=1
230545
+server 10.53.0.1 ${PORT}
230545
+key zonesub-key.example.nil 1234subk8765
230545
+update add zonesub.example.nil 0 IN TXT everywhere.
230545
+send
230545
+END
230545
+$DIG $DIGOPTS +tcp @10.53.0.1 zonesub.example.nil TXT > dig.out.2.test$n || ret=1
230545
+grep "status: REFUSED" nsupdate.out2-$n > /dev/null && ret=1
230545
+grep "ANSWER: 1," dig.out.2.test$n > /dev/null || ret=1
230545
+grep "TXT.*everywhere" dig.out.2.test$n > /dev/null || ret=1
230545
+[ $ret = 0 ] || { echo_i "failed"; status=1; }
230545
+
230545
 n=`expr $n + 1`
230545
 ret=0
230545
 echo_i "check that changes to the DNSKEY RRset TTL do not have side effects ($n)"
230545
-- 
230545
2.26.2
230545