]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
increase TXT coverage
authorBob Halley <halley@dnspython.org>
Sun, 26 Jul 2020 21:12:01 +0000 (14:12 -0700)
committerBob Halley <halley@dnspython.org>
Sun, 26 Jul 2020 21:12:01 +0000 (14:12 -0700)
dns/rdtypes/txtbase.py
tests/test_rdata.py

index 38c56011d77a3694e4ae17e09fe6550ff2cab014..6d0b6abeb69647c7cf64a15f1d9507f05360aed5 100644 (file)
@@ -65,7 +65,10 @@ class TXTBase(dns.rdata.Rdata):
         strings = []
         for token in tok.get_remaining():
             token = token.unescape_to_bytes()
-            if not (token.is_quoted_string() or token.is_identifier()):
+            # The 'if' below is always true in the current code, but we
+            # are leaving this check in in case things change some day.
+            if not (token.is_quoted_string() or
+                    token.is_identifier()):  # pragma: no cover
                 raise dns.exception.SyntaxError("expected a string")
             if len(token.value) > 255:
                 raise dns.exception.SyntaxError("string too long")
index 82d150ddfb7bab1f7a0e92166d2a3702fbb705e1..8d9937e19bf273ad259f8022d5af4af08dede26b 100644 (file)
@@ -614,6 +614,15 @@ class RdataTestCase(unittest.TestCase):
                                 '20200101000000 2003010100000 ' +
                                 '2143 foo Ym9ndXM=')
 
+    def test_empty_TXT(self):
+        # hit too long
+        with self.assertRaises(dns.exception.SyntaxError):
+            dns.rdata.from_text('in', 'txt', '')
+
+    def test_too_long_TXT(self):
+        # hit too long
+        with self.assertRaises(dns.exception.SyntaxError):
+            dns.rdata.from_text('in', 'txt', 'a' * 256)
 
 
 class UtilTestCase(unittest.TestCase):