diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c90abf..328b5bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## v1.?.? - 2024-??-?? - ??? +* Zone name validation checking for double dots, and throwing InvalidNameError + rather than base Exception * 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. diff --git a/octodns/zone.py b/octodns/zone.py index 2a623ae..5f23267 100644 --- a/octodns/zone.py +++ b/octodns/zone.py @@ -53,6 +53,10 @@ class InvalidNodeException(Exception): super().__init__(msg) +class InvalidNameError(Exception): + pass + + class Zone(object): log = getLogger('Zone') @@ -64,9 +68,17 @@ class Zone(object): delete_pcent_threshold=None, ): if not name[-1] == '.': - raise Exception(f'Invalid zone name {name}, missing ending dot') + raise InvalidNameError( + f'Invalid zone name {name}, missing ending dot' + ) + elif '..' in name: + raise InvalidNameError( + f'Invalid zone name {name}, double dot not allowed' + ) elif ' ' in name or '\t' in name: - raise Exception(f'Invalid zone name {name}, whitespace not allowed') + raise InvalidNameError( + f'Invalid zone name {name}, whitespace not allowed' + ) # internally everything is idna self.name = idna_encode(str(name)) if name else name diff --git a/tests/test_octodns_zone.py b/tests/test_octodns_zone.py index 735a0b0..4008210 100644 --- a/tests/test_octodns_zone.py +++ b/tests/test_octodns_zone.py @@ -19,6 +19,7 @@ from octodns.record import ( ) from octodns.zone import ( DuplicateRecordException, + InvalidNameError, InvalidNodeException, SubzoneRecordException, Zone, @@ -247,12 +248,21 @@ class TestZone(TestCase): self.assertIsInstance(changes[0], Delete) def test_missing_dot(self): - with self.assertRaises(Exception) as ctx: + with self.assertRaises(InvalidNameError) as ctx: Zone('not.allowed', []) self.assertTrue('missing ending dot' in str(ctx.exception)) + def test_double_dot(self): + with self.assertRaises(InvalidNameError) as ctx: + Zone('ending.double.dot..', []) + self.assertTrue('double dot not allowed' in str(ctx.exception)) + + with self.assertRaises(InvalidNameError) as ctx: + Zone('mid.double..dot.', []) + self.assertTrue('double dot not allowed' in str(ctx.exception)) + def test_whitespace(self): - with self.assertRaises(Exception) as ctx: + with self.assertRaises(InvalidNameError) as ctx: Zone('space not allowed.', []) self.assertTrue('whitespace not allowed' in str(ctx.exception))