diff options
| author | Bob Halley <halley@dnspython.org> | 2020-07-26 10:57:47 -0700 |
|---|---|---|
| committer | Bob Halley <halley@dnspython.org> | 2020-07-26 10:57:47 -0700 |
| commit | 49beea0f67deea7f47dd3c53d753fbf84bc42979 (patch) | |
| tree | 6c8b00335cae29cbeac8f3ce1a93c5bc83f91d08 /tests/test_edns.py | |
| parent | f96e95c4593b1e39816c20b30dc528a6497717ea (diff) | |
| download | dnspython-49beea0f67deea7f47dd3c53d753fbf84bc42979.tar.gz | |
increase EDNS coverage
Diffstat (limited to 'tests/test_edns.py')
| -rw-r--r-- | tests/test_edns.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_edns.py b/tests/test_edns.py index e5dca06..6ba0c99 100644 --- a/tests/test_edns.py +++ b/tests/test_edns.py @@ -23,6 +23,7 @@ import unittest from io import BytesIO import dns.edns +import dns.wire class OptionTestCase(unittest.TestCase): def testGenericOption(self): @@ -32,6 +33,7 @@ class OptionTestCase(unittest.TestCase): data = io.getvalue() self.assertEqual(data, b'data') self.assertEqual(dns.edns.option_from_wire(3, data, 0, len(data)), opt) + self.assertEqual(str(opt), 'Generic 3') def testECSOption_prefix_length(self): opt = dns.edns.ECSOption('1.2.255.33', 20) @@ -46,6 +48,13 @@ class OptionTestCase(unittest.TestCase): opt.to_wire(io) data = io.getvalue() self.assertEqual(data, b'\x00\x01\x18\x00\x01\x02\x03') + # default srclen + opt = dns.edns.ECSOption('1.2.3.4') + io = BytesIO() + opt.to_wire(io) + data = io.getvalue() + self.assertEqual(data, b'\x00\x01\x18\x00\x01\x02\x03') + self.assertEqual(opt.to_text(), 'ECS 1.2.3.4/24 scope/0') def testECSOption25(self): opt = dns.edns.ECSOption('1.2.3.255', 25) @@ -106,6 +115,12 @@ class OptionTestCase(unittest.TestCase): dns.edns.ECSOption.from_text('1.2.3.4/twentyfour') with self.assertRaises(ValueError): + dns.edns.ECSOption.from_text('BOGUS 1.2.3.4/5/6/7') + + with self.assertRaises(ValueError): + dns.edns.ECSOption.from_text('1.2.3.4/5/6/7') + + with self.assertRaises(ValueError): dns.edns.ECSOption.from_text('1.2.3.4/24/O') # <-- that's not a zero with self.assertRaises(ValueError): @@ -114,6 +129,12 @@ class OptionTestCase(unittest.TestCase): with self.assertRaises(ValueError): dns.edns.ECSOption.from_text('1.2.3.4/2001:4b98::1/24') + def testECSOption_from_wire_invalid(self): + with self.assertRaises(ValueError): + opt = dns.edns.option_from_wire(dns.edns.ECS, + b'\x00\xff\x18\x00\x01\x02\x03', + 0, 7) + def test_basic_relations(self): o1 = dns.edns.ECSOption.from_text('1.2.3.0/24/0') o2 = dns.edns.ECSOption.from_text('1.2.4.0/24/0') |
