From 71172ac4bb190496c4ef668c3cba6fa9bf5834aa Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Fri, 23 Mar 2012 09:50:39 -0700 Subject: Send a more appropriate error response for 403 in osapi * Don't use resizeNotAllowed for 403 * Fixes bug 949444 Change-Id: Ib2b5acba291a04e0c0296fa5e8438019983dda20 --- nova/api/openstack/wsgi.py | 2 +- nova/tests/api/openstack/test_faults.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 26c51d8f4..f65425246 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -1022,7 +1022,7 @@ class Fault(webob.exc.HTTPException): _fault_names = { 400: "badRequest", 401: "unauthorized", - 403: "resizeNotAllowed", + 403: "forbidden", 404: "itemNotFound", 405: "badMethod", 409: "conflictingRequest", diff --git a/nova/tests/api/openstack/test_faults.py b/nova/tests/api/openstack/test_faults.py index 96a62017b..3eb2bb8dc 100644 --- a/nova/tests/api/openstack/test_faults.py +++ b/nova/tests/api/openstack/test_faults.py @@ -96,6 +96,19 @@ class TestFaults(test.TestCase): self.assertEqual(resp.status_int, 404) self.assertTrue('whut?' in resp.body) + def test_raise_403(self): + """Ensure the ability to raise :class:`Fault` in WSGI-ified methods.""" + @webob.dec.wsgify + def raiser(req): + raise wsgi.Fault(webob.exc.HTTPForbidden(explanation='whut?')) + + req = webob.Request.blank('/.xml') + resp = req.get_response(raiser) + self.assertEqual(resp.content_type, "application/xml") + self.assertEqual(resp.status_int, 403) + self.assertTrue('resizeNotAllowed' not in resp.body) + self.assertTrue('forbidden' in resp.body) + def test_fault_has_status_int(self): """Ensure the status_int is set correctly on faults""" fault = wsgi.Fault(webob.exc.HTTPBadRequest(explanation='what?')) -- cgit