Browse Source

Root CNAMEs are not allowed

pull/74/head
Ross McFarland 9 years ago
parent
commit
d2af8efe5c
3 changed files with 23 additions and 4 deletions
  1. +8
    -0
      octodns/record.py
  2. +4
    -2
      tests/test_octodns_provider_route53.py
  3. +11
    -2
      tests/test_octodns_record.py

+ 8
- 0
octodns/record.py View File

@ -400,6 +400,14 @@ class AliasRecord(_ValueMixin, Record):
class CnameRecord(_ValueMixin, Record): class CnameRecord(_ValueMixin, Record):
_type = 'CNAME' _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 @classmethod
def _validate_value(cls, value): def _validate_value(cls, value):
reasons = [] reasons = []


+ 4
- 2
tests/test_octodns_provider_route53.py View File

@ -1260,8 +1260,10 @@ class TestRoute53Records(TestCase):
False) False)
self.assertEquals(c, c) self.assertEquals(c, c)
d = _Route53Record(None, Record.new(existing, '', d = _Route53Record(None, Record.new(existing, '',
{'ttl': 42, 'type': 'CNAME',
'value': 'foo.bar.'}),
{'ttl': 42, 'type': 'MX',
'value': {
'priority': 10,
'value': 'foo.bar.'}}),
False) False)
self.assertEquals(d, d) self.assertEquals(d, d)


+ 11
- 2
tests/test_octodns_record.py View File

@ -859,15 +859,24 @@ class TestRecordValidation(TestCase):
def test_CNAME(self): def test_CNAME(self):
# doesn't blow up # doesn't blow up
Record.new(self.zone, '', {
Record.new(self.zone, 'www', {
'type': 'CNAME', 'type': 'CNAME',
'ttl': 600, 'ttl': 600,
'value': 'foo.bar.com.', 'value': 'foo.bar.com.',
}) })
# missing trailing .
# root cname is a no-no
with self.assertRaises(ValidationError) as ctx: with self.assertRaises(ValidationError) as ctx:
Record.new(self.zone, '', { 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', 'type': 'CNAME',
'ttl': 600, 'ttl': 600,
'value': 'foo.bar.com', 'value': 'foo.bar.com',


Loading…
Cancel
Save