diff options
author | Michael Krotscheck <krotscheck@gmail.com> | 2015-06-12 14:31:14 -0700 |
---|---|---|
committer | Michael Krotscheck <krotscheck@gmail.com> | 2015-06-30 09:01:48 -0700 |
commit | 655de16a871bb0b4768f18a88e9f573fea18ed41 (patch) | |
tree | 21b37e890b0780f517702428f7e9314b95c7d3ab /oslo_middleware/tests | |
parent | 0caa7a9e4509ef337925c9586a8b8617cd847158 (diff) | |
download | oslo-middleware-655de16a871bb0b4768f18a88e9f573fea18ed41.tar.gz |
Support PasteDeploy
This patch removes the oslo_config specific code out of the
middleware's class, and instead provides a factory method by which
this middleware may be constructed. It then also provides a similar
factory method that supports pastedeploy's filter_factory protocol.
Change-Id: I68d9c5439707a624aa24f3dbe7bbfd616b382a6d
Diffstat (limited to 'oslo_middleware/tests')
-rw-r--r-- | oslo_middleware/tests/test_cors.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/oslo_middleware/tests/test_cors.py b/oslo_middleware/tests/test_cors.py index 229bb80..d078d14 100644 --- a/oslo_middleware/tests/test_cors.py +++ b/oslo_middleware/tests/test_cors.py @@ -111,6 +111,42 @@ class CORSTestBase(test_base.BaseTestCase): self.assertNotIn(header, response.headers) +class CORSTestFilterFactory(test_base.BaseTestCase): + """Test the CORS filter_factory method.""" + + def test_filter_factory(self): + # Test a valid filter. + filter = cors.filter_factory(None, + allowed_origin='http://valid.example.com', + allow_credentials='False', + max_age='', + expose_headers='', + allow_methods='GET', + allow_headers='') + application = filter(test_application) + + self.assertIn('http://valid.example.com', application.allowed_origins) + + config = application.allowed_origins['http://valid.example.com'] + self.assertEqual('False', config['allow_credentials']) + self.assertEqual('', config['max_age']) + self.assertEqual('', config['expose_headers']) + self.assertEqual('GET', config['allow_methods']) + self.assertEqual('', config['allow_headers']) + + def test_no_origin_fail(self): + '''Assert that a filter factory with no allowed_origin fails.''' + self.assertRaises(TypeError, + cors.filter_factory, + global_conf=None, + # allowed_origin=None, # Expected value. + allow_credentials='False', + max_age='', + expose_headers='', + allow_methods='GET', + allow_headers='') + + class CORSRegularRequestTest(CORSTestBase): """CORS Specification Section 6.1 |