def test_filter_factory_multiorigin(self): self.useFixture(fixture.Config()).conf([]) # Test a valid filter. filter = cors.filter_factory(None, allowed_origin="http://valid.example.com," "http://other.example.com") application = filter(test_application) self.assertIn("http://valid.example.com", application.allowed_origins) self.assertIn("http://other.example.com", application.allowed_origins)
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_factory_latent_properties(self): """Assert latent properties in paste.ini config. If latent_* properties are added to a paste.ini config, assert that they are persisted in the middleware. """ # Spaces in config are deliberate to frobb the config parsing. filter = cors.filter_factory( global_conf=None, oslo_config_project="foobar", latent_expose_headers=" X-Header-1 , X-2", latent_allow_headers="X-Header-1 , X-2", latent_allow_methods="GET,PUT, POST", ) app = filter(test_application) # Ensure that the properties are in latent configuration. self.assertEqual(["X-Header-1", "X-2"], app._latent_configuration["expose_headers"]) self.assertEqual(["X-Header-1", "X-2"], app._latent_configuration["allow_headers"]) self.assertEqual(["GET", "PUT", "POST"], app._latent_configuration["methods"])
def test_filter_factory(self): config = self.useFixture(fixture.Config()) config.conf([]) # 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(None, config['max_age']) self.assertEqual([], config['expose_headers']) self.assertEqual(['GET'], config['allow_methods']) self.assertEqual([], config['allow_headers'])
def test_filter_factory(self): self.useFixture(fixture.Config()).conf([]) # 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(None, config["max_age"]) self.assertEqual([], config["expose_headers"]) self.assertEqual(["GET"], config["allow_methods"]) self.assertEqual([], config["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")