summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2020-07-25 06:29:08 -0700
committerBob Halley <halley@dnspython.org>2020-07-25 06:29:08 -0700
commit55ab7215cfc2300410deeda60beff5eedcebdcad (patch)
tree81438173cc5509d0a57fe6490628eff93cad0fe0
parentb904694b12193a5782d5cee46dcc74d43483e1eb (diff)
downloaddnspython-55ab7215cfc2300410deeda60beff5eedcebdcad.tar.gz
even on errors where we tolerate no question, check question if present
-rw-r--r--dns/message.py8
-rw-r--r--tests/test_message.py12
2 files changed, 17 insertions, 3 deletions
diff --git a/dns/message.py b/dns/message.py
index ab3de5b..bc4cced 100644
--- a/dns/message.py
+++ b/dns/message.py
@@ -248,9 +248,11 @@ class Message:
return False
if other.rcode() in {dns.rcode.FORMERR, dns.rcode.SERVFAIL,
dns.rcode.NOTIMP, dns.rcode.REFUSED}:
- # We don't check the question section in these cases, even
- # though they still ought to have the same question.
- return True
+ # We don't check the question section in these cases if
+ # the other question section is empty, even though they
+ # still really ought to have a question section.
+ if len(other.question) == 0:
+ return True
if dns.opcode.is_update(self.flags):
# This is assuming the "sender doesn't include anything
# from the update", but we don't care to check the other
diff --git a/tests/test_message.py b/tests/test_message.py
index bfc137f..f004b92 100644
--- a/tests/test_message.py
+++ b/tests/test_message.py
@@ -368,6 +368,13 @@ class MessageTestCase(unittest.TestCase):
q.additional = [rrset]
self.assertEqual(q.sections[3], [rrset])
+ def test_is_a_response_empty_question(self):
+ q = dns.message.make_query('www.dnspython.org.', 'a')
+ r = dns.message.make_response(q)
+ r.question = []
+ r.set_rcode(dns.rcode.FORMERR)
+ self.assertTrue(q.is_response(r))
+
def test_not_a_response(self):
q = dns.message.QueryMessage(id=1)
self.assertFalse(q.is_response(q))
@@ -384,6 +391,11 @@ class MessageTestCase(unittest.TestCase):
q2.id = 1
r = dns.message.make_response(q2)
self.assertFalse(q1.is_response(r))
+ # Now set rcode to FORMERR and check again. It should still
+ # not be a response as we check the question section for FORMERR
+ # if it is present.
+ r.set_rcode(dns.rcode.FORMERR)
+ self.assertFalse(q1.is_response(r))
# Test the other case of differing questions, where there is
# something in the response's question section that is not in
# the question's. We have to do multiple questions to test