Merge "Ensure request's object type is dict"

This commit is contained in:
Zuul 2018-07-17 02:38:10 +00:00 committed by Gerrit Code Review
commit 5d8a0d9ca3
2 changed files with 11 additions and 0 deletions

View File

@ -710,6 +710,9 @@ class Controller(object):
if res_dict is None:
msg = _("Unable to find '%s' in request body") % resource
raise webob.exc.HTTPBadRequest(msg)
if not isinstance(res_dict, dict):
msg = _("Object '%s' contains invalid data") % resource
raise webob.exc.HTTPBadRequest(msg)
attr_ops = attributes.AttributeInfo(attr_info)
attr_ops.populate_project_id(context, res_dict, is_create)

View File

@ -832,6 +832,14 @@ class JSONV2TestCase(APIv2TestBase, testlib_api.WebTestCase):
data = {}
self._test_create_failure_bad_request('networks', data)
def test_create_object_string_not_json(self):
data = {'network': 'a string'}
self._test_create_failure_bad_request('networks', data)
def test_create_object_boolean_not_json(self):
data = {'network': True}
self._test_create_failure_bad_request('networks', data)
def test_create_missing_attr(self):
data = {'port': {'what': 'who', 'tenant_id': _uuid()}}
self._test_create_failure_bad_request('ports', data)