diff --git a/designate/objects/rrdata_txt.py b/designate/objects/rrdata_txt.py index b811dadc8..7526bda56 100644 --- a/designate/objects/rrdata_txt.py +++ b/designate/objects/rrdata_txt.py @@ -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: diff --git a/designate/tests/unit/objects/test_rrdata_txt.py b/designate/tests/unit/objects/test_rrdata_txt.py index 3802884a8..40ec06a96 100644 --- a/designate/tests/unit/objects/test_rrdata_txt.py +++ b/designate/tests/unit/objects/test_rrdata_txt.py @@ -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"' + ) diff --git a/releasenotes/notes/validate-doublequotes-6c4ed4f65a9d5e4b.yaml b/releasenotes/notes/validate-doublequotes-6c4ed4f65a9d5e4b.yaml new file mode 100644 index 000000000..d406f79c8 --- /dev/null +++ b/releasenotes/notes/validate-doublequotes-6c4ed4f65a9d5e4b.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - Verify that if a TXT record starts with a double quote, it also ends with + a double quote.