Commit cc12f2e0 authored by Tomas Krizek's avatar Tomas Krizek

respdiff/match: remove qcase, qname, qtype criteria

parent 3ca0d42c
Pipeline #39475 passed with stage
in 51 seconds
......@@ -62,4 +62,7 @@ Respdiff is conceptually chain of independent tools:
Changelog
---------
- 2018-08-21: ``qname``, ``qcase`` and ``qtype`` field comparisons were removed.
``question`` comparison now performs all these check in a case sensitive manner.
Remove these checks from ``criteria`` and ``field_weights`` in ``respdiff.cfg``.
- 2018-06-01: reorganized tools and created a new git repo with cleaned-up history
......@@ -33,10 +33,10 @@ restart_script = {{ resolver['respdiff']['restart_script'] }}
target = {{ respdiff['target'] }}
# fields and comparison methods used when comparing two DNS messages
criteria = opcode, rcode, flags, question, qname, qtype, answertypes, answerrrsigs
criteria = opcode, rcode, flags, question, answertypes, answerrrsigs
# other supported criteria values: authority, additional, edns, nsid
[report]
# diffsum reports mismatches in field values in this order
# if particular message has multiple mismatches, it is counted only once into category with highest weight
field_weights = timeout, malformed, opcode, qcase, qtype, rcode, flags, answertypes, answerrrsigs, answer, authority, additional, edns, nsid
field_weights = timeout, malformed, opcode, question, rcode, flags, answertypes, answerrrsigs, answer, authority, additional, edns, nsid
......@@ -41,10 +41,10 @@ transport = udp
target = cznic
# fields and comparison methods used when comparing two DNS messages
criteria = opcode, rcode, flags, question, qname, qtype, answertypes, answerrrsigs
criteria = opcode, rcode, flags, question, answertypes, answerrrsigs
# other supported criteria values: authority, additional, edns, nsid
[report]
# diffsum reports mismatches in field values in this order
# if particular message has multiple mismatches, it is counted only once into category with highest weight
field_weights = timeout, malformed, opcode, qcase, qtype, rcode, flags, answertypes, answerrrsigs, answer, authority, additional, edns, nsid
field_weights = timeout, malformed, opcode, question, rcode, flags, answertypes, answerrrsigs, answer, authority, additional, edns, nsid
......@@ -12,9 +12,9 @@ import dns.inet
ALL_FIELDS = [
'timeout', 'malformed', 'opcode', 'qcase', 'qname', 'qtype', 'question', 'rcode',
'flags', 'answertypes', 'answerrrsigs', 'answer', 'authority', 'additional',
'edns', 'nsid']
'timeout', 'malformed', 'opcode', 'question', 'rcode', 'flags', 'answertypes',
'answerrrsigs', 'answer', 'authority', 'additional', 'edns', 'nsid']
ALL_FIELDS_SET = set(ALL_FIELDS)
def ipaddr_check(addr):
......@@ -127,21 +127,17 @@ def cfg2dict_check_diff(cdict):
def cfg2dict_check_fields(cdict):
"""Check if all fields are known and that all have a weight assigned"""
def get_unknown_fields(fields):
return [field for field in fields if field not in ALL_FIELDS]
unknown_criteria = get_unknown_fields(cdict['diff']['criteria'])
unknown_criteria = set(cdict['diff']['criteria']) - ALL_FIELDS_SET
if unknown_criteria:
raise ValueError('[diff] criteria: unknown fields: {}'.format(
', '.join(['"{}"'.format(field) for field in unknown_criteria])))
unknown_field_weights = get_unknown_fields(cdict['report']['field_weights'])
unknown_field_weights = set(cdict['report']['field_weights']) - ALL_FIELDS_SET
if unknown_field_weights:
raise ValueError('[report] field_weights: unknown fields: {}'.format(
', '.join(['"{}"'.format(field) for field in unknown_field_weights])))
missing_field_weights = [
field for field in ALL_FIELDS if field not in cdict['report']['field_weights']]
missing_field_weights = ALL_FIELDS_SET - set(cdict['report']['field_weights'])
if missing_field_weights:
raise ValueError('[report] field_weights: missing fields: {}'.format(
', '.join(['"{}"'.format(field) for field in missing_field_weights])))
......
......@@ -73,7 +73,7 @@ def compare_val(exp_val: MismatchValue, got_val: MismatchValue):
return True
def compare_rrs(expected: RRset, got: RRset):
def compare_rrs(expected: Sequence[RRset], got: Sequence[RRset]):
""" Compare lists of RR sets, throw exception if different. """
for rr in expected:
if rr not in got:
......@@ -81,12 +81,15 @@ def compare_rrs(expected: RRset, got: RRset):
for rr in got:
if rr not in expected:
raise DataMismatch(expected, got)
if len(expected) != len(got):
if len(expected) != len(got): # detect duplicates
raise DataMismatch(expected, got)
return True
def compare_rrs_types(exp_val: RRset, got_val: RRset, compare_rrsigs: bool):
def compare_rrs_types(
exp_val: Sequence[RRset],
got_val: Sequence[RRset],
compare_rrsigs: bool):
"""sets of RR types in both sections must match"""
def rr_ordering_key(rrset):
return rrset.covers if compare_rrsigs else rrset.rdtype
......@@ -120,22 +123,17 @@ def match_part( # pylint: disable=inconsistent-return-statements
""" Compare scripted reply to given message using single criteria. """
if criteria == 'opcode':
return compare_val(exp_msg.opcode(), got_msg.opcode())
elif criteria == 'qtype':
if not exp_msg.question:
return True
return compare_val(exp_msg.question[0].rdtype, got_msg.question[0].rdtype)
elif criteria == 'qname':
if not exp_msg.question:
return True
return compare_val(exp_msg.question[0].name, got_msg.question[0].name)
elif criteria == 'qcase':
return compare_val(got_msg.question[0].name.labels, exp_msg.question[0].name.labels)
elif criteria == 'flags':
return compare_val(dns.flags.to_text(exp_msg.flags), dns.flags.to_text(got_msg.flags))
elif criteria == 'rcode':
return compare_val(dns.rcode.to_text(exp_msg.rcode()), dns.rcode.to_text(got_msg.rcode()))
elif criteria == 'question':
return compare_rrs(exp_msg.question, got_msg.question)
question_match = compare_rrs(exp_msg.question, got_msg.question)
if not exp_msg.question: # 0 RRs, nothing else to compare
return True
assert len(exp_msg.question) == 1, "multiple question in single DNS query unsupported"
case_match = compare_val(got_msg.question[0].name.labels, exp_msg.question[0].name.labels)
return question_match and case_match
elif criteria in ('answer', 'ttl'):
return compare_rrs(exp_msg.answer, got_msg.answer)
elif criteria == 'answertypes':
......
......@@ -41,10 +41,10 @@ transport = udp
target = deckard1
# fields and comparison methods used when comparing two DNS messages
criteria = opcode, rcode, flags, question, qname, qtype, answertypes, answerrrsigs
criteria = opcode, rcode, flags, question, answertypes, answerrrsigs
# other supported criteria values: authority, additional, edns, nsid
[report]
# diffsum reports mismatches in field values in this order
# if particular message has multiple mismatches, it is counted only once into category with highest weight
field_weights = timeout, malformed, opcode, qcase, qtype, rcode, flags, answertypes, answerrrsigs, answer, authority, additional, edns, nsid
field_weights = timeout, malformed, opcode, question, rcode, flags, answertypes, answerrrsigs, answer, authority, additional, edns, nsid
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