Browse Source

Fix name length validation

Closes #626
pull/627/head
Guillaume Gelin 5 years ago
parent
commit
9c20d0015b
2 changed files with 27 additions and 6 deletions
  1. +5
    -4
      octodns/record/__init__.py
  2. +22
    -2
      tests/test_octodns_record.py

+ 5
- 4
octodns/record/__init__.py View File

@ -126,10 +126,11 @@ class Record(EqualityTupleMixin):
if n > 253:
reasons.append('invalid fqdn, "{}" is too long at {} chars, max '
'is 253'.format(fqdn, n))
n = len(name)
if n > 63:
reasons.append('invalid name, "{}" is too long at {} chars, max '
'is 63'.format(name, n))
for label in name.split('.'):
n = len(label)
if n > 63:
reasons.append('invalid label, "{}" is too long at {} chars, '
'max is 63'.format(label, n))
try:
ttl = int(data['ttl'])
if ttl < 0:


+ 22
- 2
tests/test_octodns_record.py View File

@ -1315,7 +1315,7 @@ class TestRecordValidation(TestCase):
self.assertTrue(reason.endswith('.unit.tests." is too long at 254'
' chars, max is 253'))
# label length, DNS defins max as 63
# label length, DNS defines max as 63
with self.assertRaises(ValidationError) as ctx:
# The . will put this over the edge
name = 'x' * 64
@ -1325,10 +1325,30 @@ class TestRecordValidation(TestCase):
'value': '1.2.3.4',
})
reason = ctx.exception.reasons[0]
self.assertTrue(reason.startswith('invalid name, "xxxx'))
self.assertTrue(reason.startswith('invalid label, "xxxx'))
self.assertTrue(reason.endswith('xxx" is too long at 64'
' chars, max is 63'))
with self.assertRaises(ValidationError) as ctx:
name = 'foo.' + 'x' * 64 + '.bar'
Record.new(self.zone, name, {
'ttl': 300,
'type': 'A',
'value': '1.2.3.4',
})
reason = ctx.exception.reasons[0]
self.assertTrue(reason.startswith('invalid label, "xxxx'))
self.assertTrue(reason.endswith('xxx" is too long at 64'
' chars, max is 63'))
# should not raise with dots
name = 'xxxxxxxx.' * 10
Record.new(self.zone, name, {
'ttl': 300,
'type': 'A',
'value': '1.2.3.4',
})
# no ttl
with self.assertRaises(ValidationError) as ctx:
Record.new(self.zone, '', {


Loading…
Cancel
Save