diff --git a/neutron/extensions/tagging.py b/neutron/extensions/tagging.py index 36d48117919..6a130d94dcb 100644 --- a/neutron/extensions/tagging.py +++ b/neutron/extensions/tagging.py @@ -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: diff --git a/neutron/tests/unit/extensions/test_tag.py b/neutron/tests/unit/extensions/test_tag.py index 359c38f1638..0db7736e98c 100644 --- a/neutron/tests/unit/extensions/test_tag.py +++ b/neutron/tests/unit/extensions/test_tag.py @@ -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)