Merge "Tags: harden validations"
This commit is contained in:
commit
0ee1099335
@ -71,7 +71,7 @@ def validate_tag(tag):
|
||||
|
||||
|
||||
def validate_tags(body):
|
||||
if 'tags' not in body:
|
||||
if not isinstance(body, dict) or 'tags' not in body:
|
||||
raise exceptions.InvalidInput(error_message=_("Invalid tags body"))
|
||||
msg = validators.validate_list_of_unique_strings(body['tags'], MAX_TAG_LEN)
|
||||
if msg:
|
||||
|
@ -161,8 +161,13 @@ class TestTagApiBase(test_securitygroup.SecurityGroupsTestCase,
|
||||
subresource='tags', sub_id=tag)
|
||||
return req.get_response(self.ext_api)
|
||||
|
||||
def _put_tags(self, tags):
|
||||
body = {'tags': tags}
|
||||
def _put_tags(self, tags=None, body=None):
|
||||
if tags:
|
||||
body = {'tags': tags}
|
||||
elif body:
|
||||
body = body
|
||||
else:
|
||||
body = {}
|
||||
req = self._req('PUT', self.collection, data=body, id=self.resource_id,
|
||||
subresource='tags')
|
||||
return req.get_response(self.ext_api)
|
||||
@ -273,6 +278,14 @@ class TestResourceTagApi(TestTagApiBase):
|
||||
self._assertEqualTags(['red', 'green'], tags)
|
||||
self._test_notification_report(expect_notify)
|
||||
|
||||
def test_put_invalid_tags(self):
|
||||
res = self._put_tags()
|
||||
self.assertEqual(400, res.status_int)
|
||||
res = self._put_tags(body=7)
|
||||
self.assertEqual(400, res.status_int)
|
||||
res = self._put_tags(body={'invalid': True})
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_put_tags_replace(self):
|
||||
res = self._put_tags(['red', 'green'])
|
||||
self.assertEqual(200, res.status_int)
|
||||
|
Loading…
Reference in New Issue
Block a user