diff options
| author | Bob Halley <halley@dnspython.org> | 2020-07-02 19:02:24 -0700 |
|---|---|---|
| committer | Bob Halley <halley@dnspython.org> | 2020-07-02 19:32:38 -0700 |
| commit | f089bf648c0b58981aa9eb9a57f207600b5d632a (patch) | |
| tree | 7a6abd0369a7cd2878b457f1d4ebb4bff56c5522 /tests/test_wire.py | |
| parent | 1dd3d5ac639bd4f65755d17e86704044f4235638 (diff) | |
| download | dnspython-f089bf648c0b58981aa9eb9a57f207600b5d632a.tar.gz | |
more coverage for wire
Diffstat (limited to 'tests/test_wire.py')
| -rw-r--r-- | tests/test_wire.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/tests/test_wire.py b/tests/test_wire.py index ac4401c..2cfaa1b 100644 --- a/tests/test_wire.py +++ b/tests/test_wire.py @@ -51,5 +51,37 @@ class BinaryTestCase(unittest.TestCase): self.assertEqual(p.get_name(), expected1) self.assertEqual(p.get_name(), expected2) self.assertEqual(p.remaining(), 0) - # verify the unseek() + # verify the restore_furthest() self.assertEqual(p.current, len(wire)) + + def test_seek(self): + wire = b'\x09dnspython\x03org\x00' + p = dns.wire.Parser(wire) + p.seek(10) + self.assertEqual(p.get_uint8(), 3) + # seeking to the end index is OK + p.seek(len(wire)) + self.assertEqual(p.current, p.end) + with self.assertRaises(dns.exception.FormError): + # but reading there will not succeed + p.get_uint8() + with self.assertRaises(dns.exception.FormError): + p.seek(-1) + with self.assertRaises(dns.exception.FormError): + p.seek(len(wire) + 1) + + def test_not_reading_everything_in_restriction(self): + wire = bytes.fromhex('0102010203040102') + p = dns.wire.Parser(wire) + with self.assertRaises(dns.exception.FormError): + with p.restrict_to(5): + v = p.get_uint8() + self.assertEqual(v, 1) + # don't read the other 4 bytes + + def test_restriction_does_not_mask_exception(self): + wire = bytes.fromhex('0102010203040102') + p = dns.wire.Parser(wire) + with self.assertRaises(NotImplementedError): + with p.restrict_to(5): + raise NotImplementedError |
