Validate matching double quotes in TXT recordsets.
Currently, designate does not validate that if a TXT recordset starts with a double quote, it also ends with a double quote. So, if user has provided TXT record in this unmatched doublequote format, zone ends up in error. This change verifies that if a TXT record starts with a double quote, it also ends with a double quote. Closes-Bug: 1980757 Change-Id: I75bd7c1657a9178c8e7ef2d66fa7318255c67582
This commit is contained in:
parent
d05232fc07
commit
7f428e8ab5
@ -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:
|
||||
|
@ -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"'
|
||||
)
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- Verify that if a TXT record starts with a double quote, it also ends with
|
||||
a double quote.
|
Loading…
Reference in New Issue
Block a user