def test_process_origin_allow_all(self): fake_req = mock.MagicMock() fake_resp = mock.MagicMock() cors = CORS(allow_all_origins=True) cors._set_allow_origin = mock.Mock() self.assertEqual( cors._process_origin(fake_req, fake_resp, 'rackspace.com'), True) cors._set_allow_origin.assert_called_once_with(fake_resp, '*') cors._set_allow_origin = mock.Mock() cors.supports_credentials = True self.assertEqual( cors._process_origin(fake_req, fake_resp, 'rackspace.com'), True) cors._set_allow_origin.assert_called_once_with(fake_resp, 'rackspace.com')
def test_process_origin_regex_none(self): fake_req = mock.MagicMock() fake_resp = mock.MagicMock() cors = CORS() cors._set_allow_origin = mock.Mock() self.assertEqual( cors._process_origin(fake_req, fake_resp, 'rackspace.com'), False) self.assertEqual(cors._set_allow_origin.call_count, 0)
def test_process_origin_allow_regex(self): fake_req = mock.MagicMock() fake_resp = mock.MagicMock() cors = CORS(allow_origins_regex='rack.*\.com') cors._set_allow_origin = mock.Mock() self.assertEqual( cors._process_origin(fake_req, fake_resp, 'rackspace.com'), True) cors._set_allow_origin.assert_called_once_with(fake_resp, 'rackspace.com')
def test_process_origin_deny(self): fake_req = mock.MagicMock() fake_resp = mock.MagicMock() cors = CORS(allow_origins_list=['rackspace.com'], allow_origins_regex='rack.*\.com') cors._set_allow_origin = mock.Mock() self.assertEqual( cors._process_origin(fake_req, fake_resp, 'not_rackspace.com'), False) self.assertEqual(cors._set_allow_origin.call_count, 0)