From 5522507bd7ff51ad8a55f8318c327ace3157675d Mon Sep 17 00:00:00 2001 From: Roland Hochmuth Date: Sat, 21 Jul 2012 10:52:41 +0100 Subject: Return 400 in get_console_output for bad length. Fixes bug 1027069. Prior to this fix if the length in the request body was set to a non-integer value a error code of 500 was returned. The documentation also shows an integer in the example request body. The fix tests if the optional length is provided and if it is either an "int" or "long". If not, a 400 error is returned. Additionally, cleaned up some error message to be more descriptive. Change-Id: I27a66fb1111e74665969f98e1101a9c37c665abc --- .../compute/contrib/test_console_output.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/compute/contrib/test_console_output.py b/nova/tests/api/openstack/compute/contrib/test_console_output.py index ab0fe35b9..aa722ee8a 100644 --- a/nova/tests/api/openstack/compute/contrib/test_console_output.py +++ b/nova/tests/api/openstack/compute/contrib/test_console_output.py @@ -74,6 +74,27 @@ class ConsoleOutputExtensionTest(test.TestCase): self.assertEqual(res.status_int, 200) self.assertEqual(output, {'output': '2\n3\n4'}) + def test_get_console_output_with_length_as_str(self): + body = {'os-getConsoleOutput': {'length': '3'}} + req = webob.Request.blank('/v2/fake/servers/1/action') + req.method = "POST" + req.body = jsonutils.dumps(body) + req.headers["content-type"] = "application/json" + res = req.get_response(fakes.wsgi_app()) + output = jsonutils.loads(res.body) + self.assertEqual(res.status_int, 200) + self.assertEqual(output, {'output': '2\n3\n4'}) + + def test_get_console_output_with_non_integer_length(self): + body = {'os-getConsoleOutput': {'length': 'NaN'}} + req = webob.Request.blank('/v2/fake/servers/1/action') + req.method = "POST" + req.body = jsonutils.dumps(body) + req.headers["content-type"] = "application/json" + res = req.get_response(fakes.wsgi_app()) + output = jsonutils.loads(res.body) + self.assertEqual(res.status_int, 400) + def test_get_text_console_no_instance(self): self.stubs.Set(compute.API, 'get', fake_get_not_found) body = {'os-getConsoleOutput': {}} -- cgit