Merge "Validate matching double quotes in TXT recordsets."

This commit is contained in:
Zuul 2022-07-20 23:13:49 +00:00 committed by Gerrit Code Review
commit 3423a3e656
3 changed files with 31 additions and 0 deletions

View File

@ -36,12 +36,22 @@ class TXT(Record):
def _is_wrapped_in_double_quotes(value):
return value.startswith('"') and value.endswith('"')
@staticmethod
def _is_missing_double_quote(value):
return ((value.startswith('"') and not value.endswith('"')) or
(not value.startswith('"') and value.endswith('"')))
def _validate_record_single_string(self, value):
if len(value) > 255:
err = ("Any TXT record string exceeding "
"255 characters has to be split.")
raise InvalidObject(err)
if self._is_missing_double_quote(value):
err = ("TXT record is missing a double quote either at beginning "
"or at end.")
raise InvalidObject(err)
if not self._is_wrapped_in_double_quotes(value):
# value with spaces should be quoted as per RFC1035 5.1
for element in value:

View File

@ -44,3 +44,20 @@ class RRDataTXTTest(oslotest.base.BaseTestCase):
'Provided object does not match schema',
record.validate
)
def test_reject_non_matched_quotes(self):
record = objects.TXT()
self.assertRaisesRegex(
exceptions.InvalidObject,
"TXT record is missing a double quote either at beginning "
"or at end.",
record._from_string,
'"foo'
)
self.assertRaisesRegex(
exceptions.InvalidObject,
"TXT record is missing a double quote either at beginning "
"or at end.",
record._from_string,
'foo"'
)

View File

@ -0,0 +1,4 @@
---
fixes:
- Verify that if a TXT record starts with a double quote, it also ends with
a double quote.