diff --git a/octodns/record/__init__.py b/octodns/record/__init__.py index b6e15aa..c945aaf 100644 --- a/octodns/record/__init__.py +++ b/octodns/record/__init__.py @@ -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: diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index cdaa483..d4497e8 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -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, '', {