1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Fix name length validation

Closes #626
This commit is contained in:
Guillaume Gelin
2020-11-16 14:53:58 +01:00
parent 6a169be47a
commit 9c20d0015b
2 changed files with 27 additions and 6 deletions

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)
for label in name.split('.'):
n = len(label)
if n > 63:
reasons.append('invalid name, "{}" is too long at {} chars, max '
'is 63'.format(name, n))
reasons.append('invalid label, "{}" is too long at {} chars, '
'max is 63'.format(label, n))
try:
ttl = int(data['ttl'])
if ttl < 0:

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, '', {