Add validation of RRSet Type

Change-Id: I91861dbbd9f74edd76cb2d2c8cf3ac9507278aba
Closes-Bug: #1443348
This commit is contained in:
Graham Hayes 2015-04-13 12:17:42 +02:00
parent 83f6d28fdb
commit 29869a648b
2 changed files with 40 additions and 3 deletions

View File

@ -129,9 +129,24 @@ class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin,
def validate(self):
errors = ValidationErrorList()
# Get the right classes (e.g. A for Recordsets with type: 'A')
record_list_cls = self.obj_cls_from_name('%sList' % self.type)
record_cls = self.obj_cls_from_name(self.type)
try:
record_list_cls = self.obj_cls_from_name('%sList' % self.type)
record_cls = self.obj_cls_from_name(self.type)
except KeyError as e:
e = ValidationError()
e.path = ['recordset', 'type']
e.validator = 'value'
e.validator_value = [self.type]
e.message = ("'%(type)s' is not a supported Record type"
% {'type': self.type})
# Add it to the list for later
errors.append(e)
raise exceptions.InvalidObject(
"Provided object does not match "
"schema", errors=errors, object=self)
# Get any rules that the record type imposes on the record
changes = record_cls.get_recordset_schema_changes()
@ -142,7 +157,6 @@ class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin,
old_fields = deepcopy(self.FIELDS)
self.FIELDS = utils.deep_dict_merge(self.FIELDS, changes)
errors = ValidationErrorList()
error_indexes = []
# Copy these for safekeeping
old_records = deepcopy(self.records)

View File

@ -107,6 +107,29 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
self._assert_exception(
'invalid_object', 400, self.client.post_json, url, body)
def test_create_recordset_with_invalid_type(self):
# Prepare a RecordSet fixture
body = self.get_recordset_fixture(
self.domain['name'],
'A',
fixture=0,
values={
'name': 'name.%s' % self.domain['name'],
'records': [
'192.0.2.1',
'192.0.2.2',
]
}
)
del body['type']
url = '/zones/%s/recordsets' % self.domain['id']
# Ensure it fails with a 400
self._assert_exception(
'invalid_object', 400, self.client.post_json, url, body)
def test_create_recordset_invalid_id(self):
self._assert_invalid_uuid(self.client.post, '/zones/%s/recordsets')