def test_set_allowed_headers(self): fake_resp = mock.MagicMock() allowed_header_list = ['header1'] cors = CORS() cors._set_allowed_headers(fake_resp, allowed_header_list) fake_resp.append_header.assert_called_once_with( 'access-control-allow-headers', 'header1')
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_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_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)