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

Merge branch 'ttl-tests' into 'master'

Ttl Tests
parents e60335fb 5c77b440
No related branches found
No related tags found
No related merge requests found
......@@ -844,29 +844,29 @@ static int add_rr(zone_node_t *node, const knot_rrset_t *rr,
return ret;
}
}
// Insert new RR to RRSet, data will be copied.
int ret = node_add_rrset(node, rr);
if (ret != KNOT_EOK) {
if (ret == KNOT_EOK || ret == KNOT_ETTL) {
// RR added, store for possible rollback.
knot_rdataset_t *rrs = node_rdataset(node, rr->type);
int data_ret = add_new_data(chset, rrs->data);
if (data_ret != KNOT_EOK) {
knot_rdataset_clear(rrs, NULL);
return data_ret;
}
if (ret == KNOT_ETTL) {
// Handle possible TTL errors.
log_ttl_error(node, rr);
if (master) {
// TTL errors fatal on master.
return KNOT_ETTL;
if (!master) {
// TTL errors fatal only for master.
return KNOT_EOK;
}
} else {
return ret;
}
}
// Get changed RRS and store for possible rollback.
knot_rdataset_t *rrs = node_rdataset(node, rr->type);
ret = add_new_data(chset, rrs->data);
if (ret != KNOT_EOK) {
knot_rdataset_clear(rrs, NULL);
return ret;
}
return KNOT_EOK;
return ret;
}
static int xfrin_apply_add(knot_zone_contents_t *contents,
......
#!/usr/bin/env python3
'''TTL mismatch test'''
from dnstest.utils import *
from dnstest.test import Test
t = Test()
zone = t.zone("example.com.")
master = t.server("knot")
t.link(zone, master, ddns=True)
t.start()
# Add new RR with different TTL to a RRSet that is already in the zone
# The UPDATE should be REFUSED
check_log("Add RR with different TTL")
up = master.update(zone)
up.add("mail.example.com.", 1000, "A", "1.2.3.4")
up.send("REFUSED")
resp = master.dig("mail.example.com.", "A")
resp.check_record(section="answer", rtype="A", ttl="3600", rdata="192.0.2.3")
resp.check_record(section="answer", rtype="A", nordata="1.2.3.4")
# Try to add two RRs belonging to one RRSet, but with different TTLs
# The UPDATE should be REFUSED
# This also tests rollback in case of addition
check_log("Add RRSet with incoherent TTLs")
up = master.update(zone)
up.add("test.example.com.", 1000, "A", "1.2.3.4")
up.add("test.example.com.", 2000, "A", "2.3.4.5")
up.send("REFUSED")
resp = master.dig("test.example.com.", "A")
resp.check(rcode="NXDOMAIN")
# First, delete RRSet already in zone, then add new RR with different TTL
# The UPDATE should be accepted and the new RR should be present in the zone
check_log("Delete RRSet from zone + add new RR with different TTL instead")
up = master.update(zone)
up.delete("mail.example.com.", "A")
up.add("mail.example.com.", 1000, "A", "1.2.3.4")
up.send("NOERROR")
resp = master.dig("mail.example.com.", "ANY")
resp.check_record(section="answer", rtype="A", ttl="1000", rdata="1.2.3.4")
resp.check_record(section="answer", rtype="A", nordata="192.0.2.3")
resp.check_record(section="answer", rtype="AAAA", ttl="3600", rdata="2001:db8::3")
# Some prerequisities for the next test
up = master.update(zone)
up.add("test2.example.com.", 3600, "A", "1.2.3.4")
up.add("test2.example.com.", 3600, "A", "2.3.4.5")
up.send("NOERROR")
# Delete one of RRs in a zone RRSet, then add new RR with different TTL
# The UPDATE should be REFUSED
# This also tests rollback in case of deletion
check_log("Delete one RR from a RRSet + try to add RR with different TTL instead")
up = master.update(zone)
up.delete("test2.example.com.", "A", "1.2.3.4")
up.add("test2.example.com.", 1000, "A", "3.4.5.6")
up.send("REFUSED")
resp = master.dig("test2.example.com.", "A")
resp.check_record(section="answer", rtype="A", ttl="3600", rdata="1.2.3.4")
resp.check_record(section="answer", rtype="A", nordata="3.4.5.6")
# Test for rollback - a lot of changes and a invalid RR
check_log("Rollback test: a lot of changes")
up = master.update(zone)
# Add to existing RRSet
up.add("test2.example.com.", 3600 , "A", "3.4.5.6")
up.add("test2.example.com.", 3600 , "A", "3.4.5.7")
# Add new RRSet to an existing node
up.add("test2.example.com.", 1000, "MX", "10 somewhere.com.");
# Add new node
up.add("test3.example.com.", 2000, "A", "5.6.7.8")
# Remove specific RR
up.delete("test2.example.com.", "A", "1.2.3.4")
# Remove whole RRSet
up.delete("mail.example.com.", "A")
# Remove whole node
up.delete("dns1.example.com.", "ANY")
# Add invalid RR so that the UPDATE is refused
up.add("test2.example.com.", 1000, "A", "7.8.9.0")
up.send("REFUSED")
resp = master.dig("test2.example.com.", "ANY")
resp.check_record(section="answer", rtype="A", ttl="3600", rdata="1.2.3.4")
resp.check_record(section="answer", rtype="A", ttl="3600", rdata="2.3.4.5")
resp.check_record(section="answer", rtype="MX", nordata="10 somewhere.com.")
resp.check_record(section="answer", rtype="A", nordata="7.8.9.0")
resp = master.dig("test3.example.com", "ANY")
resp.check(rcode="NXDOMAIN")
resp = master.dig("mail.example.com.", "ANY")
resp.check_record(section="answer", rtype="A", ttl="1000", rdata="1.2.3.4")
resp.check_record(section="answer", rtype="AAAA", ttl="3600", rdata="2001:db8::3")
resp = master.dig("dns1.example.com.", "ANY")
resp.check_record(section="answer", rtype="A", ttl="3600", rdata="192.0.2.1")
resp.check_record(section="answer", rtype="AAAA", ttl="3600", rdata="2001:db8::1")
t.end()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment