Fixup CNAME placement validation

CNAME's may have child records, but may not have sibling records

Change-Id: I50ffb37b20691424f5611dfdc2059536b8fd1688
This commit is contained in:
Kiall Mac Innes 2013-08-23 23:30:33 +01:00
parent a96e345e7a
commit ad80f3f6ea
2 changed files with 39 additions and 56 deletions

View File

@ -156,25 +156,6 @@ class Service(rpc_service.Service):
'share a name with any '
'other records')
if record_type == 'CNAME':
# CNAME's may not have children. Ever.
criterion = {'name': '%%.%s' % record_name}
records = self.storage_api.find_records(context, domain['id'],
criterion=criterion)
if len(records) > 0:
raise exceptions.InvalidRecordLocation('CNAME records may not '
'have any child '
'records')
else:
# No record may have a CNAME as a parent
if self._is_subrecord(context, domain, record_name,
{'type': 'CNAME'}):
raise exceptions.InvalidRecordLocation('CNAME records may not '
'have any child '
'records')
# Duplicate PTR's with the same name are not allowed
if record_type == 'PTR':
criterion = {'name': record_name, 'type': 'PTR'}

View File

@ -800,12 +800,12 @@ class CentralServiceTest(CentralTestCase):
self.central_service.create_record(context, domain['id'],
values=values)
def test_create_cname_record_alongside_an_a_record(self):
def test_create_cname_record_above_an_a_record(self):
context = self.get_admin_context()
domain = self.create_domain()
values = dict(
name='www.%s' % domain['name'],
name='t.www.%s' % domain['name'],
type='A',
data='127.0.0.1'
)
@ -813,23 +813,49 @@ class CentralServiceTest(CentralTestCase):
self.central_service.create_record(context, domain['id'],
values=values)
# Attempt to create a CNAME record alongside an A record
with self.assertRaises(exceptions.InvalidRecordLocation):
# Create a CNAME record alongside an A record
values = dict(
name='www.%s' % domain['name'],
type='CNAME',
data='example.org.'
)
self.central_service.create_record(context, domain['id'],
record = self.central_service.create_record(context, domain['id'],
values=values)
def test_create_cname_record_above_an_a_record(self):
self.assertIn('id', record)
def test_create_cname_record_below_an_a_record(self):
context = self.get_admin_context()
domain = self.create_domain()
values = dict(
name='t.www.%s' % domain['name'],
name='t.%s' % domain['name'],
type='A',
data='127.0.0.1'
)
self.central_service.create_record(context, domain['id'],
values=values)
# Create a CNAME record alongside an A record
values = dict(
name='www.t.%s' % domain['name'],
type='CNAME',
data='example.org.'
)
record = self.central_service.create_record(context, domain['id'],
values=values)
self.assertIn('id', record)
def test_create_cname_record_alongside_an_a_record(self):
context = self.get_admin_context()
domain = self.create_domain()
values = dict(
name='www.%s' % domain['name'],
type='A',
data='127.0.0.1'
)
@ -872,30 +898,6 @@ class CentralServiceTest(CentralTestCase):
self.central_service.create_record(context, domain['id'],
values=values)
def test_create_an_a_record_below_a_cname_record(self):
context = self.get_admin_context()
domain = self.create_domain()
values = dict(
name='www.%s' % domain['name'],
type='CNAME',
data='example.org.'
)
self.central_service.create_record(context, domain['id'],
values=values)
# Attempt to create a CNAME record alongside an A record
with self.assertRaises(exceptions.InvalidRecordLocation):
values = dict(
name='t.www.%s' % domain['name'],
type='A',
data='127.0.0.1'
)
self.central_service.create_record(context, domain['id'],
values=values)
def test_create_duplicate_ptr_record(self):
context = self.get_admin_context()
domain = self.create_domain(values={'name': '2.0.192.in-addr.arpa.'})