summaryrefslogtreecommitdiffstats
path: root/tests-extra
diff options
context:
space:
mode:
authorFilip Siroky <filip.siroky@nic.cz>2016-09-01 15:21:36 +0200
committerDaniel Salzman <daniel.salzman@nic.cz>2016-09-06 12:22:37 +0200
commit838dd64b631f9885028aa2212d1d34b4a07e2b57 (patch)
tree91fab3a9e1f17042247659e310e045d94285f964 /tests-extra
parentdoc: add warning against concurrent zone modification (diff)
downloadknot-838dd64b631f9885028aa2212d1d34b4a07e2b57.tar.xz
knot-838dd64b631f9885028aa2212d1d34b4a07e2b57.zip
modules: add rosedb module test
Diffstat (limited to 'tests-extra')
-rw-r--r--tests-extra/tests/modules/rosedb/test.py67
-rw-r--r--tests-extra/tools/dnstest/module.py37
-rw-r--r--tests-extra/tools/dnstest/params.py6
3 files changed, 104 insertions, 6 deletions
diff --git a/tests-extra/tests/modules/rosedb/test.py b/tests-extra/tests/modules/rosedb/test.py
new file mode 100644
index 000000000..2b3775190
--- /dev/null
+++ b/tests-extra/tests/modules/rosedb/test.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+
+''' Check 'rosedb' query module functionality. '''
+
+import os.path
+from dnstest.test import Test
+from dnstest.utils import *
+from dnstest.module import ModRosedb
+
+t = Test()
+
+ModRosedb.check()
+
+# Initialize server configuration.
+zone = t.zone("example.com.")
+knot = t.server("knot")
+t.link(zone, knot)
+
+# Attach rosedb.
+module = ModRosedb(os.path.join(knot.dir, "rosedb"))
+knot.add_module(None, module)
+
+t.start()
+
+# Check before rosedb applied.
+resp = knot.dig("mail.example.com", "A")
+resp.check(rcode="NOERROR", rdata="192.0.2.3", ttl=3600, flags="AA")
+
+# Set rosedb records.
+module.add_record("mail.example.com", "A", "1000", "127.0.0.1")
+module.add_record("mail6.example.com", "AAAA", "1000", "::1")
+knot.reload()
+
+# Check if zone record is overridden with rosedb.
+resp = knot.dig("mail.example.com", "A")
+resp.check(rcode="NOERROR", rdata="127.0.0.1", ttl=1000, noflags="AA")
+
+# Check for subdomain match.
+resp = knot.dig("sub.sub.mail.example.com", "A")
+resp.check(rcode="NOERROR", rdata="127.0.0.1", ttl=1000, noflags="AA")
+
+# Check for new record.
+resp = knot.dig("mail6.example.com", "AAAA")
+resp.check(rcode="NOERROR", rdata="::1", ttl=1000, noflags="AA")
+
+# Check for new record with bad type (NODATA).
+resp = knot.dig("mail6.example.com", "A")
+resp.check(rcode="NOERROR", noflags="AA")
+compare(resp.count(), 0, "A count")
+
+# Add autority information.
+module.add_record("example.net", "SOA", "1", "ns1 host 1 3600 60 3600 3600")
+module.add_record("example.net", "NS", "2", "ns1.example.net")
+module.add_record("ns1.example.net", "A", "3", "127.0.0.2")
+knot.reload()
+
+# Check for authoritative answer.
+resp = knot.dig("example.net", "NS")
+resp.check(rcode="NOERROR", rdata="ns1.example.net.", ttl=2, flags="AA")
+resp.check_count(1, rtype="SOA", section="authority")
+
+# Check for NXDOMAIN.
+resp = knot.dig("example.net", "MX")
+resp.check(rcode="NXDOMAIN", flags="AA")
+resp.check_count(1, rtype="SOA", section="authority")
+
+t.end()
diff --git a/tests-extra/tools/dnstest/module.py b/tests-extra/tools/dnstest/module.py
index 178250ab6..5b6457754 100644
--- a/tests-extra/tools/dnstest/module.py
+++ b/tests-extra/tools/dnstest/module.py
@@ -1,11 +1,11 @@
#!/usr/bin/env python3
+import os
import re
-from subprocess import Popen, PIPE, check_call, CalledProcessError
+from subprocess import Popen, PIPE, check_call
from dnstest.utils import *
import dnstest.config
import dnstest.params as params
-import dnstest.server
class KnotModule(object):
'''Query module configuration'''
@@ -152,3 +152,36 @@ class ModWhoami(KnotModule):
conf.end()
return conf
+
+class ModRosedb(KnotModule):
+ '''Rosedb module'''
+
+ src_name = "rosedb_load"
+ conf_name = "mod-rosedb"
+
+ def __init__(self, dbdir):
+ super().__init__()
+ self.dbdir = dbdir
+
+ def get_conf(self, conf=None):
+ if not conf:
+ conf = dnstest.config.KnotConf()
+
+ conf.begin(self.conf_name)
+ conf.id_item("id", self.conf_id)
+ conf.item_str("dbdir", "%s" % (self.dbdir))
+ conf.end()
+
+ return conf
+
+ def add_record(self, owner, rtype, ttl, rdata, code="-", target="-"):
+ prepare_dir(self.dbdir)
+ try:
+ check_call([params.rosedb_tool, self.dbdir, 'add', owner, rtype,
+ ttl, rdata, code, target],
+ stdout=open(os.path.join(params.out_dir, "rosedb-tool.out"), mode="a"),
+ stderr=open(os.path.join(params.out_dir, "rosedb-tool.err"), mode="a"))
+ except:
+ set_err("ROSEDB_TOOL")
+ detail_log("!Failed to add a record into rosedb '%s'" % self.dbdir)
+ detail_log(SEP)
diff --git a/tests-extra/tools/dnstest/params.py b/tests-extra/tools/dnstest/params.py
index 82444c91f..f1c1de898 100644
--- a/tests-extra/tools/dnstest/params.py
+++ b/tests-extra/tools/dnstest/params.py
@@ -60,10 +60,8 @@ keymgr_bin = get_binary("KNOT_TEST_KEYMGR", repo_binary("src/keymgr"))
bind_bin = get_binary("KNOT_TEST_BIND", "named")
# KNOT_TEST_BINDC - Bind control binary.
bind_ctl = get_binary("KNOT_TEST_BINDC", "rndc")
-# KNOT_TEST_NSD - Nsd binary.
-#nsd_bin = get_binary("KNOT_TEST_NSD", "nsd")
-# KNOT_TEST_NSDC - Nsd control binary.
-#nsd_ctl = get_binary("KNOT_TEST_NSDC", "nsdc")
+# KNOT_TEST_ROSEDB_TOOL - Rosedb tool binary.
+rosedb_tool = get_binary("KNOT_TEST_ROSEDB_TOOL", repo_binary("src/rosedb_tool"))
# KNOT_TEST_OUTS_DIR - working directories location.
outs_dir = get_param("KNOT_TEST_OUTS_DIR", "/tmp")