Commit 0037fc52 authored by Štěpán Balážik's avatar Štěpán Balážik Committed by Petr Špaček

matchpart: fix handling empty question sections

parent 5436af53
Pipeline #39601 passed with stage
in 1 minute and 18 seconds
......@@ -98,26 +98,51 @@ def compare_rrs_types(exp_val, got_val, skip_rrsigs):
raise DataMismatch(exp_types, got_types)
def check_question(question):
if len(question) > 2:
raise NotImplementedError("More than one record in QUESTION SECTION.")
def match_opcode(exp, got):
return compare_val(exp.opcode(),
got.opcode())
def match_qtype(exp, got):
if not exp.question:
check_question(exp.question)
check_question(got.question)
if not exp.question and not got.question:
return True
if not exp.question:
raise DataMismatch("<empty question>", got.question[0].rdtype)
if not got.question:
raise DataMismatch(exp.question[0].rdtype, "<empty question>")
return compare_val(exp.question[0].rdtype,
got.question[0].rdtype)
def match_qname(exp, got):
if not exp.question:
check_question(exp.question)
check_question(got.question)
if not exp.question and not got.question:
return True
if not exp.question:
raise DataMismatch("<empty question>", got.question[0].name)
if not got.question:
raise DataMismatch(exp.question[0].name, "<empty question>")
return compare_val(exp.question[0].name,
got.question[0].name)
def match_qcase(exp, got):
check_question(exp.question)
check_question(got.question)
if not exp.question and not got.question:
return True
if not exp.question:
raise DataMismatch("<empty question>", got.question[0].name.labels)
if not got.question:
raise DataMismatch(exp.question[0].name.labels, "<empty question>")
return compare_val(exp.question[0].name.labels,
got.question[0].name.labels)
......@@ -125,7 +150,10 @@ def match_qcase(exp, got):
def match_subdomain(exp, got):
if not exp.question:
return True
qname = dns.name.from_text(got.question[0].name.to_text().lower())
if got.question:
qname = got.question[0].name
else:
qname = dns.name.root
if exp.question[0].name.is_superdomain(qname):
return True
raise DataMismatch(exp, got)
......
......@@ -279,9 +279,7 @@ def range_shadowing_match_rules(test: RplintTest) -> List[RplintFail]:
for e1, e2 in itertools.combinations(r.stored, 2):
try:
e1.match(e2.message)
# IndexError is here especially because of how we handle empty question section
# in matchpart
except (ValueError, IndexError):
except ValueError:
pass
else:
info = "previous entry on line %d" % get_line_number(test.path, e1.node.char)
......
Markdown is supported
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