Browse Source

Validate double dots for zone names too

pull/1203/head
Ross McFarland 1 year ago
parent
commit
5ae7716dae
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
3 changed files with 28 additions and 4 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +14
    -2
      octodns/zone.py
  3. +12
    -2
      tests/test_octodns_zone.py

+ 2
- 0
CHANGELOG.md View File

@ -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.


+ 14
- 2
octodns/zone.py View File

@ -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


+ 12
- 2
tests/test_octodns_zone.py View File

@ -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))


Loading…
Cancel
Save