From c5d62ed38568a56dac3c2ccea45acebab513fe17 Mon Sep 17 00:00:00 2001 From: Francesco Vollero Date: Fri, 27 Sep 2013 00:56:31 +0200 Subject: [PATCH] WSGI: added the control for non empty X-PROJECT-ID Closes-bug: #1228249 Change-Id: I6fbf0344fd45f9581a28a55ef852139b32e93ed7 --- marconi/queues/transport/wsgi/driver.py | 5 +++++ .../transport/wsgi/test_queue_lifecycle.py | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/marconi/queues/transport/wsgi/driver.py b/marconi/queues/transport/wsgi/driver.py index 8bb9fb8ea..10d355628 100644 --- a/marconi/queues/transport/wsgi/driver.py +++ b/marconi/queues/transport/wsgi/driver.py @@ -52,6 +52,11 @@ media type support with the "Accept" header.''', def _extract_project_id(req, resp, params): params['project_id'] = req.get_header('X-PROJECT-ID') + if params['project_id'] == "": + raise falcon.HTTPBadRequest('Empty project header not allowed', + _(u''' +X-PROJECT-ID cannot be an empty string. Specify the right header X-PROJECT-ID +and retry.''')) class Driver(transport.DriverBase): diff --git a/tests/unit/queues/transport/wsgi/test_queue_lifecycle.py b/tests/unit/queues/transport/wsgi/test_queue_lifecycle.py index 5fe4e91c1..5dbbc63a6 100644 --- a/tests/unit/queues/transport/wsgi/test_queue_lifecycle.py +++ b/tests/unit/queues/transport/wsgi/test_queue_lifecycle.py @@ -36,7 +36,22 @@ class QueueLifecycleBaseTest(base.TestBase): self.wsgi_cfg = config.namespace( 'drivers:transport:wsgi').from_options() - @ddt.data('480924', 'foo', '', None) + def test_empty_project_id(self): + path = '/v1/queues/gumshoe' + + self.simulate_get(path, '') + self.assertEquals(self.srmock.status, falcon.HTTP_400) + + self.simulate_put(path, '') + self.assertEquals(self.srmock.status, falcon.HTTP_400) + + self.simulate_head(path, '') + self.assertEquals(self.srmock.status, falcon.HTTP_400) + + self.simulate_delete(path, '') + self.assertEquals(self.srmock.status, falcon.HTTP_400) + + @ddt.data('480924', 'foo', None) def test_basics_thoroughly(self, project_id): path = '/v1/queues/gumshoe'