From: Bob Halley Date: Sun, 26 Jul 2020 17:57:47 +0000 (-0700) Subject: increase EDNS coverage X-Git-Tag: v2.1.0rc1~130 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49beea0f67deea7f47dd3c53d753fbf84bc42979;p=thirdparty%2Fdnspython.git increase EDNS coverage --- diff --git a/dns/edns.py b/dns/edns.py index 05f76e63..087592b5 100644 --- a/dns/edns.py +++ b/dns/edns.py @@ -190,8 +190,8 @@ class ECSOption(Option): self.family = 1 if srclen is None: srclen = 24 - else: - raise ValueError('Bad ip family') + else: # pragma: no cover (this will never happen) + raise ValueError('Bad address family') self.address = address self.srclen = srclen diff --git a/tests/test_edns.py b/tests/test_edns.py index e5dca062..6ba0c995 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) @@ -105,6 +114,12 @@ class OptionTestCase(unittest.TestCase): with self.assertRaises(ValueError): 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 @@ -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')