diff options
-rw-r--r-- | oslo_middleware/cors.py | 12 | ||||
-rw-r--r-- | oslo_middleware/tests/test_cors.py | 4 |
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 |