diff options
author | Bob Halley <halley@dnspython.org> | 2021-09-27 09:33:13 -0700 |
---|---|---|
committer | Bob Halley <halley@dnspython.org> | 2021-10-23 16:38:34 -0700 |
commit | 30508f8e1ceed4949763e19b31e70fffa2b3afdd (patch) | |
tree | 430bf5a99e732d540f747eccefff884821173d5b | |
parent | b349b1b5b6bc769a78fec059a6856fb4bc185268 (diff) | |
download | dnspython-30508f8e1ceed4949763e19b31e70fffa2b3afdd.tar.gz |
add test of continue_on_error
-rw-r--r-- | tests/test_message.py | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/test_message.py b/tests/test_message.py index 8fcc674..1ea87aa 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -562,7 +562,7 @@ www.example. IN CNAME ;AUTHORITY example. 300 IN SOA . . 1 2 3 4 5 ''') - # passing is actuall not going into an infinite loop in this call + # passing is not going into an infinite loop in this call result = r.resolve_chaining() self.assertEqual(result.canonical_name, dns.name.from_text('www.example.')) @@ -684,6 +684,43 @@ flags QR m = dns.message.from_wire(goodwire) self.assertIsInstance(m.flags, dns.flags.Flag) self.assertEqual(m.flags, dns.flags.Flag.RD) + + def test_continue_on_error(self): + good_message = dns.message.from_text( +"""id 1234 +opcode QUERY +rcode NOERROR +flags QR AA RD +;QUESTION +www.dnspython.org. IN SOA +;ANSWER +www.dnspython.org. 300 IN SOA . . 1 2 3 4 5 +www.dnspython.org. 300 IN A 1.2.3.4 +www.dnspython.org. 300 IN AAAA ::1 +""") + wire = good_message.to_wire() + # change ANCOUNT to 255 + bad_wire = wire[:6] + b'\x00\xff' + wire[8:] + # change AAAA into rdata with rdlen 0 + bad_wire = bad_wire[:-18] + b'\x00' * 2 + # change SOA MINIMUM field to 0xffffffff (too large) + bad_wire = bad_wire.replace(b'\x00\x00\x00\x05', b'\xff' * 4) + m = dns.message.from_wire(bad_wire, continue_on_error=True) + self.assertEqual(len(m.errors), 3) + self.assertEqual(m.errors[0][:2], (69, 'value too large')) + self.assertEqual(m.errors[1][:2], (97, 'IPv6 addresses are 16 bytes long')) + self.assertEqual(m.errors[2][:2], (97, 'not enough RRs in section 1')) + expected_message = dns.message.from_text( +"""id 1234 +opcode QUERY +rcode NOERROR +flags QR AA RD +;QUESTION +www.dnspython.org. IN SOA +;ANSWER +www.dnspython.org. 300 IN A 1.2.3.4 +""") + self.assertEqual(m, expected_message) if __name__ == '__main__': |