summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMehdi Abaakouk <sileht@redhat.com>2015-09-02 10:57:07 +0200
committerMehdi Abaakouk <sileht@redhat.com>2015-09-02 10:57:07 +0200
commit7257d5a78791c3093c31fb469c423027752a38d7 (patch)
tree761b12285545fa9579e11a58a96932c704a4728a
parentb73aa5c3abcea74716e236e8fd41475a5dc8dbdd (diff)
downloadoslo-middleware-7257d5a78791c3093c31fb469c423027752a38d7.tar.gz
cors: fix filter with oslo_config_project is set
Current paste filter of cors middleware require allowed_origin. But it should be required only if oslo_config_project is unset. Change-Id: I85ae5d5984ea9b2401563c30ba5a83dc8d88acbf Closes-bug: #1491293
-rw-r--r--oslo_middleware/cors.py12
-rw-r--r--oslo_middleware/tests/test_cors.py4
2 files changed, 10 insertions, 6 deletions
diff --git a/oslo_middleware/cors.py b/oslo_middleware/cors.py
index 21ce94c..314d776 100644
--- a/oslo_middleware/cors.py
+++ b/oslo_middleware/cors.py
@@ -80,7 +80,7 @@ class CORS(base.ConfigurableMiddleware):
self._init_conf()
@classmethod
- def factory(cls, global_conf, allowed_origin, **local_conf):
+ def factory(cls, global_conf, **local_conf):
"""factory method for paste.deploy
allowed_origin: Protocol, host, and port for the allowed origin.
@@ -90,11 +90,11 @@ class CORS(base.ConfigurableMiddleware):
allow_methods: List of HTTP methods to permit.
allow_headers: List of HTTP headers to permit from the client.
"""
-
- # Ensures allowed_origin config exists
- return super(CORS, cls).factory(global_conf,
- allowed_origin=allowed_origin,
- **local_conf)
+ if ('allowed_origin' not in local_conf
+ and 'oslo_config_project' not in local_conf):
+ raise TypeError("allowed_origin or oslo_config_project "
+ "is required")
+ return super(CORS, cls).factory(global_conf, **local_conf)
def _init_conf(self):
'''Initialize this middleware from an oslo.config instance.'''
diff --git a/oslo_middleware/tests/test_cors.py b/oslo_middleware/tests/test_cors.py
index 4b8ffb0..1499fc6 100644
--- a/oslo_middleware/tests/test_cors.py
+++ b/oslo_middleware/tests/test_cors.py
@@ -148,6 +148,10 @@ class CORSTestFilterFactory(test_base.BaseTestCase):
allow_methods='GET',
allow_headers='')
+ def test_no_origin_but_oslo_config_project(self):
+ '''Assert that a filter factory with oslo_config_project succeed.'''
+ cors.filter_factory(global_conf=None, oslo_config_project='foobar')
+
class CORSRegularRequestTest(CORSTestBase):
"""CORS Specification Section 6.1