]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Added tests for ipset.
authorGeorge Thessalonikefs <george@nlnetlabs.nl>
Wed, 2 Mar 2022 12:08:16 +0000 (13:08 +0100)
committerGeorge Thessalonikefs <george@nlnetlabs.nl>
Wed, 2 Mar 2022 12:08:16 +0000 (13:08 +0100)
testdata/ipset.tdir/ipset.conf [new file with mode: 0644]
testdata/ipset.tdir/ipset.dsc [new file with mode: 0644]
testdata/ipset.tdir/ipset.post [new file with mode: 0644]
testdata/ipset.tdir/ipset.pre [new file with mode: 0644]
testdata/ipset.tdir/ipset.test [new file with mode: 0644]
testdata/ipset.tdir/ipset.testns [new file with mode: 0644]

diff --git a/testdata/ipset.tdir/ipset.conf b/testdata/ipset.tdir/ipset.conf
new file mode 100644 (file)
index 0000000..a53db66
--- /dev/null
@@ -0,0 +1,23 @@
+server:
+       verbosity: 3
+       num-threads: 1
+       module-config: "ipset iterator"
+       outgoing-range: 16
+       interface: 127.0.0.1
+       port: @PORT@
+       use-syslog: no
+       directory: ""
+       pidfile: "unbound.pid"
+       chroot: ""
+       username: ""
+       do-not-query-localhost: no
+       local-zone: "example.net" ipset
+stub-zone:
+       name: "example.net."
+       stub-addr: "127.0.0.1@@TOPORT@"
+stub-zone:
+       name: "example.com."
+       stub-addr: "127.0.0.1@@TOPORT@"
+ipset:
+       name-v4: atotallymadeupnamefor4
+       name-v6: atotallymadeupnamefor6
diff --git a/testdata/ipset.tdir/ipset.dsc b/testdata/ipset.tdir/ipset.dsc
new file mode 100644 (file)
index 0000000..b7792b7
--- /dev/null
@@ -0,0 +1,16 @@
+BaseName: ipset
+Version: 1.0
+Description: mock test ipset module
+CreationDate: Wed Mar 2 13:00:38 CET 2022
+Maintainer: George Thessalonikefs
+Category:
+Component:
+CmdDepends:
+Depends:
+Help:
+Pre: ipset.pre
+Post: ipset.post
+Test: ipset.test
+AuxFiles:
+Passed:
+Failure:
diff --git a/testdata/ipset.tdir/ipset.post b/testdata/ipset.tdir/ipset.post
new file mode 100644 (file)
index 0000000..7af512a
--- /dev/null
@@ -0,0 +1,14 @@
+# #-- ipset.post --#
+# source the master var file when it's there
+[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
+# source the test var file when it's there
+[ -f .tpkg.var.test ] && source .tpkg.var.test
+#
+# do your teardown here
+. ../common.sh
+PRE="../.."
+if grep "define USE_IPSET 1" $PRE/config.h; then echo test enabled; else echo test skipped; exit 0; fi
+kill_pid $FWD_PID
+kill_pid $UNBOUND_PID
+cat unbound.log
+exit 0
diff --git a/testdata/ipset.tdir/ipset.pre b/testdata/ipset.tdir/ipset.pre
new file mode 100644 (file)
index 0000000..ee1aedc
--- /dev/null
@@ -0,0 +1,33 @@
+# #-- ipset.pre--#
+# source the master var file when it's there
+[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
+# use .tpkg.var.test for in test variable passing
+[ -f .tpkg.var.test ] && source .tpkg.var.test
+
+. ../common.sh
+
+PRE="../.."
+if grep "define USE_IPSET 1" $PRE/config.h; then echo test enabled; else echo test skipped; exit 0; fi
+
+get_random_port 2
+UNBOUND_PORT=$RND_PORT
+FWD_PORT=$(($RND_PORT + 1))
+echo "UNBOUND_PORT=$UNBOUND_PORT" >> .tpkg.var.test
+echo "FWD_PORT=$FWD_PORT" >> .tpkg.var.test
+
+# start forwarder
+get_ldns_testns
+$LDNS_TESTNS -p $FWD_PORT ipset.testns >fwd.log 2>&1 &
+FWD_PID=$!
+echo "FWD_PID=$FWD_PID" >> .tpkg.var.test
+
+# make config file
+sed -e 's/@PORT\@/'$UNBOUND_PORT'/' -e 's/@TOPORT\@/'$FWD_PORT'/' < ipset.conf > ub.conf
+# start unbound in the background
+$PRE/unbound -d -c ub.conf >unbound.log 2>&1 &
+UNBOUND_PID=$!
+echo "UNBOUND_PID=$UNBOUND_PID" >> .tpkg.var.test
+
+cat .tpkg.var.test
+wait_ldns_testns_up fwd.log
+wait_unbound_up unbound.log
diff --git a/testdata/ipset.tdir/ipset.test b/testdata/ipset.tdir/ipset.test
new file mode 100644 (file)
index 0000000..9150e5e
--- /dev/null
@@ -0,0 +1,155 @@
+# #-- ipset.test --#
+# source the master var file when it's there
+[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
+# use .tpkg.var.test for in test variable passing
+[ -f .tpkg.var.test ] && source .tpkg.var.test
+
+. ../common.sh
+PRE="../.."
+if grep "define USE_IPSET 1" $PRE/config.h; then echo test enabled; else echo test skipped; exit 0; fi
+
+# Make all the queries. They need to succeed by the way.
+echo "> dig www.example.net."
+dig @127.0.0.1 -p $UNBOUND_PORT www.example.net. | tee outfile
+echo "> check answer"
+if grep "1.1.1.1" outfile; then
+       echo "OK"
+else
+       echo "> cat logfiles"
+       cat fwd.log
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+echo "> check ipset"
+if grep "ipset: add 1.1.1.1 to atotallymadeupnamefor4 for www.example.net." unbound.log; then
+       echo "ipset OK"
+else
+       echo "> cat logfiles"
+       cat fwd.log
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+
+echo "> dig www.example.net. AAAA"
+dig @127.0.0.1 -p $UNBOUND_PORT www.example.net. AAAA | tee outfile
+echo "> check answer"
+if grep "::1" outfile; then
+       echo "OK"
+else
+       echo "> cat logfiles"
+       cat fwd.log
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+echo "> check ipset"
+if grep "ipset: add ::1 to atotallymadeupnamefor6 for www.example.net." unbound.log; then
+       echo "ipset OK"
+else
+       echo "> cat logfiles"
+       cat fwd.log
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+
+echo "> dig cname.example.net."
+dig @127.0.0.1 -p $UNBOUND_PORT cname.example.net. | tee outfile
+echo "> check answer"
+if grep "2.2.2.2" outfile; then
+       echo "OK"
+else
+       echo "> cat logfiles"
+       cat fwd.log
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+echo "> check ipset"
+if grep "ipset: add 2.2.2.2 to atotallymadeupnamefor4 for target.example.net." unbound.log; then
+       echo "ipset OK"
+else
+       echo "> cat logfiles"
+       cat fwd.log
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+
+echo "> dig cname.example.net. AAAA"
+dig @127.0.0.1 -p $UNBOUND_PORT cname.example.net. AAAA | tee outfile
+echo "> check answer"
+if grep "::2" outfile; then
+       echo "OK"
+else
+       echo "> cat logfiles"
+       cat fwd.log
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+echo "> check ipset"
+if grep "ipset: add ::2 to atotallymadeupnamefor6 for target.example.net." unbound.log; then
+       echo "ipset OK"
+else
+       echo "> cat logfiles"
+       cat fwd.log
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+
+echo "> dig outsidecname.example.net."
+dig @127.0.0.1 -p $UNBOUND_PORT outsidecname.example.net. | tee outfile
+echo "> check answer"
+if grep "3.3.3.3" outfile; then
+       echo "OK"
+else
+       echo "> cat logfiles"
+       cat fwd.log
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+echo "> check ipset"
+if grep "ipset: add 3.3.3.3 to atotallymadeupnamefor4 for target.example.com." unbound.log; then
+       echo "ipset OK"
+else
+       echo "> cat logfiles"
+       cat fwd.log
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+
+echo "> dig outsidecname.example.net. AAAA"
+dig @127.0.0.1 -p $UNBOUND_PORT outsidecname.example.net. AAAA | tee outfile
+echo "> check answer"
+if grep "::3" outfile; then
+       echo "OK"
+else
+       echo "> cat logfiles"
+       cat fwd.log
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+echo "> check ipset"
+if grep "ipset: add ::3 to atotallymadeupnamefor6 for target.example.com." unbound.log; then
+       echo "ipset OK"
+else
+       echo "> cat logfiles"
+       cat fwd.log
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+
+echo "> cat logfiles"
+cat tap.log
+cat tap.errlog
+cat fwd.log
+echo "> OK"
+exit 0
diff --git a/testdata/ipset.tdir/ipset.testns b/testdata/ipset.tdir/ipset.testns
new file mode 100644 (file)
index 0000000..2b626e9
--- /dev/null
@@ -0,0 +1,103 @@
+; nameserver test file
+$ORIGIN example.net.
+$TTL 3600
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id
+SECTION QUESTION
+www    IN      A
+SECTION ANSWER
+www    IN      A       1.1.1.1
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id
+SECTION QUESTION
+www    IN      AAAA
+SECTION ANSWER
+www    IN      AAAA    ::1
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id
+SECTION QUESTION
+cname  IN      A
+SECTION ANSWER
+cname  IN      CNAME   target.example.net.
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id
+SECTION QUESTION
+cname  IN      AAAA
+SECTION ANSWER
+cname  IN      CNAME   target.example.net.
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id
+SECTION QUESTION
+outsidecname   IN      A
+SECTION ANSWER
+outsidecname   IN      CNAME   target.example.com.
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id
+SECTION QUESTION
+outsidecname   IN      AAAA
+SECTION ANSWER
+outsidecname   IN      CNAME   target.example.com.
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id
+SECTION QUESTION
+target IN      A
+SECTION ANSWER
+target IN      A       2.2.2.2
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id
+SECTION QUESTION
+target IN      AAAA
+SECTION ANSWER
+target IN      AAAA    ::2
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id
+SECTION QUESTION
+target.example.com.    IN      A
+SECTION ANSWER
+target.example.com.    IN      A       3.3.3.3
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id
+SECTION QUESTION
+target.example.com.    IN      AAAA
+SECTION ANSWER
+target.example.com.    IN      AAAA    ::3
+ENTRY_END