From 4521af4e197d79246305738ae500030df0e63212 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Fri, 23 Jun 2017 16:39:16 -0400 Subject: [PATCH] return 400 Bad Request when empty string resources The nova.api.openstack.placement.util.normalize_resources_qs_param() function was not properly picking up the presence of an empty string for the resources query parameter which would cause other functions to fail. This patch simply plugs that hole. Change-Id: I2803edebce52942818cdbc97559a2839b794fb7c --- nova/api/openstack/placement/util.py | 6 ++++++ nova/tests/unit/api/openstack/placement/test_util.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/nova/api/openstack/placement/util.py b/nova/api/openstack/placement/util.py index d2c92c8282cf..7a1c1e4c0b58 100644 --- a/nova/api/openstack/placement/util.py +++ b/nova/api/openstack/placement/util.py @@ -220,6 +220,12 @@ def normalize_resources_qs_param(qs): :raises `webob.exc.HTTPBadRequest` if the parameter's value isn't in the expected format. """ + if qs.strip() == "": + msg = _('Badly formed resources parameter. Expected resources ' + 'query string parameter in form: ' + '?resources=VCPU:2,MEMORY_MB:1024. Got: empty string.') + raise webob.exc.HTTPBadRequest(msg) + result = {} resource_tuples = qs.split(',') for rt in resource_tuples: diff --git a/nova/tests/unit/api/openstack/placement/test_util.py b/nova/tests/unit/api/openstack/placement/test_util.py index 45756e886442..6145a97f43e5 100644 --- a/nova/tests/unit/api/openstack/placement/test_util.py +++ b/nova/tests/unit/api/openstack/placement/test_util.py @@ -335,6 +335,14 @@ class TestNormalizeResourceQsParam(test.NoDBTestCase): } self.assertEqual(expected, resources) + def test_400_empty_string(self): + qs = "" + self.assertRaises( + webob.exc.HTTPBadRequest, + util.normalize_resources_qs_param, + qs, + ) + def test_400_bad_int(self): qs = "VCPU:foo" self.assertRaises(