]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Lowercase SRV records in to_digestable(), fixes #496 497/head
authorNils Wisiol <mail@nils-wisiol.de>
Mon, 1 Jun 2020 14:12:28 +0000 (16:12 +0200)
committerNils Wisiol <mail@nils-wisiol.de>
Mon, 1 Jun 2020 14:54:06 +0000 (16:54 +0200)
dns/rdtypes/IN/SRV.py
tests/test_bugs.py

index f8598e9d4fa4aefc1cb675b079c8434552b90693..bfd25ea6f9774c04cbed1f7599d779e3a7f43bdb 100644 (file)
@@ -15,6 +15,7 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
+import io
 import struct
 
 import dns.exception
@@ -57,6 +58,13 @@ class SRV(dns.rdata.Rdata):
         file.write(three_ints)
         self.target.to_wire(file, compress, origin)
 
+    def to_digestable(self, origin=None):
+        # TODO how to avoid code duplication here? This is mostly identical to self.to_wire.
+        f = io.BytesIO()
+        f.write(struct.pack("!HHH", self.priority, self.weight, self.port))
+        f.write(self.target.to_digestable(origin))
+        return f.getvalue()
+
     @classmethod
     def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
         (priority, weight, port) = struct.unpack('!HHH',
index 59e5f0eb3d64eedc9ed4483f4e1ce92fb6108d95..e10f826806cee2db77b26111ebef93fc4befbc8b 100644 (file)
@@ -25,6 +25,8 @@ import dns.rdataclass
 import dns.rdatatype
 import dns.rdtypes.ANY.TXT
 import dns.ttl
+from dns import rdata, rdataclass, rdatatype
+
 
 class BugsTestCase(unittest.TestCase):
 
@@ -95,5 +97,26 @@ class BugsTestCase(unittest.TestCase):
         self.assertEqual(t1, t2)
         self.assertEqual(t1, t4)
 
+    def test_lowercase_canonicals(self):
+        for t, presentation_format in [
+            ('SRV', '100 1 5061 EXAMPLE.com.'),
+            # TODO also check NS, MD, MF, CNAME, SOA, MB, MG, MR, PTR,
+            #  HINFO, MINFO, MX, HINFO, RP, AFSDB, RT, SIG, PX, NXT,
+            #  NAPTR, KX, SRV, DNAME, A6, RRSIG, or NSEC
+        ]:
+            canonical_format = rdata.from_text(
+                    rdclass=rdataclass.IN,
+                    rdtype=rdatatype.from_text(t),
+                    tok=presentation_format,
+                    relativize=False
+                ).to_digestable()
+            self.assertIn(
+                b'example',
+                canonical_format,
+                f'Expected canonical format of {t} record type to have '
+                f'lowercase DNS names, but saw {canonical_format}.'
+            )
+
+
 if __name__ == '__main__':
     unittest.main()