Skip to content
Snippets Groups Projects
Commit 9f5aff78 authored by Jan Kadlec's avatar Jan Kadlec
Browse files

tests-extra: DDNS tests

 - random test used for chain fix testing
 - manual test, some of the cases copied from the old tests, but not all.
parent d5530f9a
Branches
Tags
No related merge requests found
$ORIGIN ddns.
$TTL 3600
@ SOA dns1 hostmaster 2010111213 10800 3600 1209600 7200
NS dns1
NS dns2
MX 10 mail
dns1 A 192.0.2.1
AAAA 2001:DB8::1
dns2 A 192.0.2.2
AAAA 2001:DB8::2
mail A 192.0.2.3
AAAA 2001:DB8::3
existing A 1.2.3.4
*.wildcard A 4.3.2.1
#!/usr/bin/env python3
'''Manual DDNS testing'''
from dnstest.utils import *
from dnstest.test import Test
def verify(master, zone, dnssec):
if not dnssec:
return
master.flush()
t.sleep(1)
master.zone_verify(zone)
def do_test(master, zone, dnssec=False):
# add record
check_log("Record addition")
up = master.update(zone)
up.add("rrtest.ddns.", 3600, "A", "1.2.3.4")
up.send("NOERROR")
resp = master.dig("rrtest.ddns.", "A")
resp.check(rcode="NOERROR", rdata="1.2.3.4")
verify(master, zone, dnssec)
detail_log(SEP)
# add record to existing node
check_log("Node update")
up = master.update(zone)
up.add("rrtest.ddns.", 3600, "TXT", "abcedf")
up.send("NOERROR")
resp = master.dig("rrtest.ddns.", "TXT")
resp.check(rcode="NOERROR", rdata="abcedf")
verify(master, zone, dnssec)
detail_log(SEP)
# remove record
check_log("Record removal")
up = master.update(zone)
up.delete("rrtest.ddns.", "A", "1.2.3.4")
up.send("NOERROR")
resp = master.dig("rrtest.ddns.", "A")
resp.check(rcode="NOERROR")
if (resp.count(section="answer") > 0):
check_log("Did not delete A record")
set_err("Did not delete A record")
verify(master, zone, dnssec)
detail_log(SEP)
# add delegation
check_log("Delegation addition")
up = master.update(zone)
up.add("deleg.ddns.", 3600, "NS", "a.deleg.ddns.")
up.add("a.deleg.ddns.", 3600, "A", "1.2.3.4")
up.send("NOERROR")
resp = master.dig("deleg.ddns.", "NS")
resp.check_record(section="authority", rtype="NS", rdata="a.deleg.ddns.")
resp.check_record(section="additional", rtype="A", rdata="1.2.3.4")
verify(master, zone, dnssec)
detail_log(SEP)
# add DS for existing delegation
if dnssec:
check_log("DS addition")
up = master.update(zone)
up.add("deleg.ddns.", 3600, "DS", "54576 10 2 397E50C85EDE9CDE33F363A9E66FD1B216D788F8DD438A57A423A386869C8F06")
up.send("NOERROR")
resp = master.dig("deleg.ddns.", "NS", dnssec=True)
resp.check(rcode="NOERROR")
resp.check_record(section="authority", rtype="DS", rdata="54576 10 2 397E50C85EDE9CDE33F363A9E66FD1B216D788F8DD438A57A423A386869C8F06")
resp.check_record(section="authority", rtype="NS", rdata="a.deleg.ddns.")
verify(master, zone, dnssec)
detail_log(SEP)
# remove all from APEX (NS should stay)
check_log("Remove all")
up = master.update(zone)
up.delete("ddns.", "ANY")
up.send("NOERROR")
resp = master.dig("ddns.", "NS")
resp.check(rcode="NOERROR")
resp.check_record(rtype="NS", rdata="dns1.ddns.")
resp.check_record(rtype="NS", rdata="dns2.ddns.")
resp = master.dig("ddns.", "MX")
resp.check(rcode="NOERROR")
if (resp.count(section="answer") > 0):
set_err("DID NOT DELETE MX")
verify(master, zone, dnssec)
detail_log(SEP)
# add and remove the same record
check_log("Add and remove same record")
up = master.update(zone)
up.add("testaddrem.ddns.", 3600, "TXT", "record")
up.delete("testaddrem.ddns.", "TXT")
up.send("NOERROR")
resp = master.dig("testaddrem.ddns.", "TXT")
resp.check(rcode="NXDOMAIN")
verify(master, zone, dnssec)
detail_log(SEP)
t = Test()
zone = t.zone("ddns.", "ddns.zone", storage=".")
master_plain = t.server("knot")
t.link(zone, master_plain, ddns=True)
master_nsec = t.server("knot")
t.link(zone, master_nsec, ddns=True)
master_nsec.dnssec_enable = True
master_nsec.gen_key(zone, ksk=True, alg="RSASHA256")
master_nsec.gen_key(zone, alg="RSASHA256")
master_nsec.gen_confile()
master_nsec3 = t.server("knot")
t.link(zone, master_nsec3, ddns=True)
master_nsec3.dnssec_enable = True
master_nsec3.gen_key(zone, ksk=True, alg="RSASHA256")
master_nsec3.gen_key(zone, alg="RSASHA256")
master_nsec3.gen_confile()
master_nsec3.enable_nsec3(zone)
t.start()
detail_log(SEP)
detail_log(" ============ Plain test ===========")
detail_log(SEP)
# DNSSEC-less test
do_test(master_plain, zone)
detail_log(SEP)
detail_log(" ============ NSEC test ============")
detail_log(SEP)
# test with NSEC
do_test(master_nsec, zone, dnssec=True)
detail_log(SEP)
detail_log(" ============ NSEC3 test ===========")
detail_log(SEP)
# test with NSEC3
do_test(master_nsec3, zone, dnssec=True)
t.end()
#!/usr/bin/env python3
'''Randomized test for DDNS NSEC(3) chain fix'''
import random
from string import digits, ascii_uppercase, ascii_lowercase
from dnstest.utils import *
from dnstest.test import Test
################################ SETUP #######################################
MAX_LABELS = 16
MAX_UPDATE_SIZE = 256
RUNS = 2
############################### HELPERS ######################################
DNAME_ALLOWED = ascii_uppercase + ascii_lowercase + digits
def gen_dname(origin):
name = ""
label_count = random.randint(1, MAX_LABELS)
label_lengths = []
for i in range(label_count):
label_lengths.append(random.randint(1, 16))
for l in label_lengths:
for i in range(l):
name += random.choice(DNAME_ALLOWED)
name += "."
name += origin
return name
names = []
def add_rand_name(up, zone, version):
name = gen_dname(zone[0].name)
names.append(name)
up.add(name, 3600, "TXT", "generated_v" + str(version))
def remove_added_name(up):
name = random.choice(names)
up.delete(name, "TXT")
def modify_added_name(up):
name = random.choice(names)
up.add(name, 3600, "SPF", "text")
def verify(master, zone):
t.sleep(3)
master.flush()
t.sleep(3)
master.zone_verify(zone)
def test_run(master, zone, msg):
names = []
for i in range(RUNS):
check_log(msg + " Run " + str(i + 1) + " of " + str(RUNS))
update = master.update(zone)
# add records
check_log(msg + " Additions")
add_count = random.randint(1, MAX_UPDATE_SIZE)
for j in range(add_count):
add_rand_name(update, zone, i)
update.send("NOERROR")
verify(master, zone)
detail_log(SEP)
update = master.update(zone)
#remove some of previously added records
check_log(msg + " Removals")
remove_count = random.randint(1, int(add_count / 2) + 1)
for j in range(remove_count):
remove_added_name(update)
update.send("NOERROR")
verify(master, zone)
detail_log(SEP)
update = master.update(zone)
#modify existing names
check_log(msg + " Modifications")
mod_count = random.randint(1, int(add_count / 2) + 1)
for j in range(mod_count):
modify_added_name(update)
update.send("NOERROR")
verify(master, zone)
detail_log(SEP)
update = master.update(zone)
check_log(msg + " Add / Remove mix")
#add and remove records
for j in range(mod_count):
add_rand_name(update, zone, i)
remove_added_name(update)
update.send("NOERROR")
verify(master, zone)
detail_log(SEP)
############################## TEST START #####################################
random.seed()
t = Test()
master = t.server("knot")
zone = t.zone_rnd(1, dnssec=False)
t.link(zone, master, ddns=True)
# Enable autosigning.
master.dnssec_enable = True
master.gen_key(zone, ksk=True, alg="RSASHA256")
master.gen_key(zone, alg="RSASHA256")
master.gen_confile()
t.start()
# Test NSEC fix
detail_log(SEP)
detail_log(" ============ NSEC test ============")
detail_log(SEP)
test_run(master, zone, "NSEC")
master.enable_nsec3(zone)
master.reload()
t.sleep(1)
# Test NSEC3 fix
detail_log(SEP)
detail_log(" ============ NSEC3 test ===========")
detail_log(SEP)
test_run(master, zone, "NSEC3")
t.end()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment