From 53226b3262a95e4e62472416c125ee3ebd58b52e Mon Sep 17 00:00:00 2001 From: Satyanarayana Patibandla Date: Sat, 27 Apr 2013 18:18:44 -0400 Subject: Added validation for networks parameter value A validation check is added for networks parameter value. In server create request body, if networks parameter value is not stored in a list then 'Bad networks format' error is thrown with bad request exception.A new test case is added to verify whether it is returning bad request exception when invalid syntax is used. Fixes: bug #1175683 Change-Id: I457a1626c56281f89d8c4a606ccc0d0e3aea05fa --- nova/api/openstack/compute/servers.py | 3 +++ nova/tests/api/openstack/compute/test_servers.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 166c8b10e..a63a39860 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -791,6 +791,9 @@ class Controller(wsgi.Controller): requested_networks = server_dict.get('networks') if requested_networks is not None: + if not isinstance(requested_networks, list): + expl = _('Bad networks format') + raise exc.HTTPBadRequest(explanation=expl) requested_networks = self._get_requested_networks( requested_networks) diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index 22aecf020..4253c2d57 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -1857,6 +1857,27 @@ class ServersControllerCreateTest(test.TestCase): req, body) + def test_create_server_with_invalid_networks_parameter(self): + self.ext_mgr.extensions = {'os-networks': 'fake'} + image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6' + flavor_ref = 'http://localhost/123/flavors/3' + body = { + 'server': { + 'name': 'server_test', + 'imageRef': image_href, + 'flavorRef': flavor_ref, + 'networks': {'uuid': '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'}, + } + } + req = fakes.HTTPRequest.blank('/v2/fake/servers') + req.method = 'POST' + req.body = jsonutils.dumps(body) + req.headers["content-type"] = "application/json" + self.assertRaises(webob.exc.HTTPBadRequest, + self.controller.create, + req, + body) + def test_create_server_with_deleted_image(self): image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6' # Get the fake image service so we can set the status to deleted -- cgit