From d280e0850cfdb7fae6ec989dded67a5d654cd433 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Fri, 31 Dec 2021 08:48:47 -0800 Subject: [PATCH] Add a validation to catch name=@ and suggest name='' instead --- octodns/record/__init__.py | 2 ++ tests/test_octodns_record.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/octodns/record/__init__.py b/octodns/record/__init__.py index 9492eb9..9147592 100644 --- a/octodns/record/__init__.py +++ b/octodns/record/__init__.py @@ -124,6 +124,8 @@ class Record(EqualityTupleMixin): @classmethod def validate(cls, name, fqdn, data): reasons = [] + if name == '@': + reasons.append('invalid name "@", use "" instead') n = len(fqdn) if n > 253: reasons.append(f'invalid fqdn, "{fqdn}" is too long at {n} ' diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index 1a4a58c..60a8ff9 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -1643,6 +1643,17 @@ class TestRecordValidation(TestCase): zone = Zone('unit.tests.', []) def test_base(self): + # name = '@' + with self.assertRaises(ValidationError) as ctx: + name = '@' + Record.new(self.zone, name, { + 'ttl': 300, + 'type': 'A', + 'value': '1.2.3.4', + }) + reason = ctx.exception.reasons[0] + self.assertTrue(reason.startswith('invalid name "@", use "" instead')) + # fqdn length, DNS defins max as 253 with self.assertRaises(ValidationError) as ctx: # The . will put this over the edge