def test_process_allow_headers_list_camelcase(self): fake_req = mock.MagicMock() fake_resp = mock.MagicMock() cors = CORS(allow_headers_list=['Content-Type']) cors._set_allowed_headers = mock.Mock() self.assertEqual( cors._process_allow_headers(fake_req, fake_resp, ['Content-Type']), True) cors._set_allowed_headers.assert_called_once_with( fake_resp, ['Content-Type'])
def test_process_allow_headers_regex(self): fake_req = mock.MagicMock() fake_resp = mock.MagicMock() cors = CORS(allow_headers_regex='.*_header') cors._set_allowed_headers = mock.Mock() self.assertEqual( cors._process_allow_headers(fake_req, fake_resp, ['test_header']), True) cors._set_allowed_headers.assert_called_once_with( fake_resp, ['test_header'])
def test_process_allow_headers_disallow(self): fake_req = mock.MagicMock() fake_resp = mock.MagicMock() cors = CORS(allow_headers_list=['test_header'], allow_headers_regex='.*_header') cors._set_allowed_headers = mock.Mock() self.assertEqual( cors._process_allow_headers(fake_req, fake_resp, ['test_header', 'header_not_allowed']), False) self.assertEqual(cors._set_allowed_headers.call_count, 0)
def test_method_not_allowed(self): cors = CORS(allow_all_origins=True, allow_methods_list=['GET']) cors._get_requested_headers = mock.Mock(return_value=True) cors._process_allow_headers = mock.Mock() headers = [('origin', 'rackspace.com')] self.simulate_cors_request(cors, headers=headers, preflight=True, preflight_method='POST') self.assertEqual(cors._get_requested_headers.call_count, 1) self.assertEqual(cors._process_allow_headers.call_count, 0)