From dc62dd894f6e6b75c93424556543b4993d2060c4 Mon Sep 17 00:00:00 2001 From: Dan Wendlandt Date: Wed, 27 Jul 2011 09:33:21 -0700 Subject: [PATCH] fix bug 814012, add unit tests for it --- quantum/common/wsgi.py | 5 ++++- tests/unit/test_api.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/quantum/common/wsgi.py b/quantum/common/wsgi.py index d883746ac..6a5d35055 100644 --- a/quantum/common/wsgi.py +++ b/quantum/common/wsgi.py @@ -425,7 +425,10 @@ class Serializer(object): The string must be in the format of a supported MIME type. """ - return self.get_deserialize_handler(content_type)(datastring) + try: + return self.get_deserialize_handler(content_type)(datastring) + except Exception: + raise webob.exc.HTTPBadRequest("Could not deserialize data") def get_deserialize_handler(self, content_type): handlers = { diff --git a/tests/unit/test_api.py b/tests/unit/test_api.py index c09af7699..ad9a216be 100644 --- a/tests/unit/test_api.py +++ b/tests/unit/test_api.py @@ -614,6 +614,23 @@ class APITest(unittest.TestCase): LOG.debug("_test_delete_attachment_portnotfound - " \ "format:%s - END", format) + def _test_unparsable_data(self, format): + LOG.debug("_test_unparsable_data - " \ + " format:%s - START", format) + + data = "this is not json or xml" + method = 'POST' + content_type = "application/%s" % format + tenant_id = self.tenant_id + path = "/tenants/%(tenant_id)s/networks.%(format)s" % locals() + network_req = testlib.create_request(path, data, content_type, method) + network_res = network_req.get_response(self.api) + self.assertEqual(network_res.status_int, 400) + + LOG.debug("_test_unparsable_data - " \ + "format:%s - END", format) + + def setUp(self): options = {} options['plugin_provider'] = 'quantum.plugins.SamplePlugin.FakePlugin' @@ -829,3 +846,10 @@ class APITest(unittest.TestCase): def test_delete_attachment_portnotfound_json(self): self._test_delete_attachment_portnotfound('json') + + def test_unparsable_data_xml(self): + self._test_unparsable_data('xml') + + def test_unparsable_data_json(self): + self._test_unparsable_data('json') + -- 2.45.2