Root CNAMEs are not allowed

This commit is contained in:
Ross McFarland
2017-06-23 09:49:11 -07:00
parent a69ff64ae1
commit d2af8efe5c
3 changed files with 23 additions and 4 deletions
+8
View File
@@ -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 = []
+4 -2
View File
@@ -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)
+11 -2
View File
@@ -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',