From 40b30e512489c73222e66ce8277b75d6216d097e Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Sun, 6 Oct 2024 18:21:33 -0700 Subject: [PATCH] Record validation for double dots .. --- CHANGELOG.md | 1 + octodns/record/base.py | 3 +++ tests/test_octodns_record.py | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82a298d..7c90abf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## v1.?.? - 2024-??-?? - ??? +* Record validation checks for double dots in names * MetaProcessor.include_extra to add support for arbitrary extra values to be set on the meta record. * Correctly handled quoted svcparams when parsing SVCB/HTTPS rdata text diff --git a/octodns/record/base.py b/octodns/record/base.py index 2cc27f9..ab35755 100644 --- a/octodns/record/base.py +++ b/octodns/record/base.py @@ -102,6 +102,9 @@ class Record(EqualityTupleMixin): f'invalid label, "{label}" is too long at {n}' ' chars, max is 63' ) + # in the case of endswith there's an implicit second . from the Zone + if '..' in name or name.endswith('.'): + reasons.append(f'invalid name, double `.` in "{idna_decode(fqdn)}"') # TODO: look at the idna lib for a lot more potential validations... try: ttl = int(data['ttl']) diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index e03fa74..b87b13c 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -666,6 +666,32 @@ class TestRecordValidation(TestCase): # does) self.assertEqual('Label too long', reason) + # double dots are not valid, ends with + with self.assertRaises(ValidationError) as ctx: + Record.new( + self.zone, + 'this.ends.with.a.dot.', + {'ttl': 301, 'type': 'A', 'value': '1.2.3.4'}, + ) + reason = ctx.exception.reasons[0] + self.assertEqual( + 'invalid name, double `.` in "this.ends.with.a.dot..unit.tests."', + reason, + ) + + # double dots are not valid when eplxicit + with self.assertRaises(ValidationError) as ctx: + Record.new( + self.zone, + 'this.has.double..dots', + {'ttl': 301, 'type': 'A', 'value': '1.2.3.4'}, + ) + reason = ctx.exception.reasons[0] + self.assertEqual( + 'invalid name, double `.` in "this.has.double..dots.unit.tests."', + reason, + ) + # no ttl with self.assertRaises(ValidationError) as ctx: Record.new(self.zone, '', {'type': 'A', 'value': '1.2.3.4'})