diff --git a/octodns/record.py b/octodns/record.py index 3f07c39..11876f5 100644 --- a/octodns/record.py +++ b/octodns/record.py @@ -400,6 +400,14 @@ class AliasRecord(_ValueMixin, Record): class CnameRecord(_ValueMixin, Record): _type = 'CNAME' + @classmethod + def validate(cls, name, data): + reasons = [] + if name == '': + reasons.append('root CNAME not allowed') + reasons.extend(super(CnameRecord, cls).validate(name, data)) + return reasons + @classmethod def _validate_value(cls, value): reasons = [] diff --git a/tests/test_octodns_provider_route53.py b/tests/test_octodns_provider_route53.py index 0a769f9..8960088 100644 --- a/tests/test_octodns_provider_route53.py +++ b/tests/test_octodns_provider_route53.py @@ -1260,8 +1260,10 @@ class TestRoute53Records(TestCase): False) self.assertEquals(c, c) d = _Route53Record(None, Record.new(existing, '', - {'ttl': 42, 'type': 'CNAME', - 'value': 'foo.bar.'}), + {'ttl': 42, 'type': 'MX', + 'value': { + 'priority': 10, + 'value': 'foo.bar.'}}), False) self.assertEquals(d, d) diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index 6e40e18..96a83a0 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -859,15 +859,24 @@ class TestRecordValidation(TestCase): def test_CNAME(self): # doesn't blow up - Record.new(self.zone, '', { + Record.new(self.zone, 'www', { 'type': 'CNAME', 'ttl': 600, 'value': 'foo.bar.com.', }) - # missing trailing . + # root cname is a no-no with self.assertRaises(ValidationError) as ctx: Record.new(self.zone, '', { + 'type': 'CNAME', + 'ttl': 600, + 'value': 'foo.bar.com.', + }) + self.assertEquals(['root CNAME not allowed'], ctx.exception.reasons) + + # missing trailing . + with self.assertRaises(ValidationError) as ctx: + Record.new(self.zone, 'www', { 'type': 'CNAME', 'ttl': 600, 'value': 'foo.bar.com',