diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py index 5333567b47..9d17bd9ef6 100644 --- a/swift/proxy/controllers/base.py +++ b/swift/proxy/controllers/base.py @@ -1287,7 +1287,7 @@ class Controller(object): def generate_request_headers(self, orig_req=None, additional=None, transfer=False): """ - Create a list of headers to be used in backend requets + Create a list of headers to be used in backend requests :param orig_req: the original request sent by the client to the proxy :param additional: additional headers to send to the backend diff --git a/test/unit/proxy/controllers/test_base.py b/test/unit/proxy/controllers/test_base.py index 48300340c8..204a9b88f0 100644 --- a/test/unit/proxy/controllers/test_base.py +++ b/test/unit/proxy/controllers/test_base.py @@ -452,6 +452,28 @@ class TestFuncs(unittest.TestCase): resp = base.OPTIONS(req) self.assertEqual(resp.status_int, 200) + def test_options_with_null_allow_origin(self): + base = Controller(self.app) + base.account_name = 'a' + base.container_name = 'c' + + def my_container_info(*args): + return { + 'cors': { + 'allow_origin': '*', + } + } + base.container_info = my_container_info + req = Request.blank('/v1/a/c/o', + environ={'swift.cache': FakeCache()}, + headers={'Origin': '*', + 'Access-Control-Request-Method': 'GET'}) + + with patch('swift.proxy.controllers.base.' + 'http_connect', fake_http_connect(200)): + resp = base.OPTIONS(req) + self.assertEqual(resp.status_int, 200) + def test_options_unauthorized(self): base = Controller(self.app) base.account_name = 'a' @@ -507,6 +529,16 @@ class TestFuncs(unittest.TestCase): resp, headers_to_container_info(headers.items(), 200)) + def test_container_info_without_req(self): + base = Controller(self.app) + base.account_name = 'a' + base.container_name = 'c' + + container_info = \ + base.container_info(base.account_name, + base.container_name) + self.assertEqual(container_info['status'], 0) + def test_headers_to_account_info_missing(self): resp = headers_to_account_info({}, 404) self.assertEqual(resp['status'], 404) @@ -684,6 +716,19 @@ class TestFuncs(unittest.TestCase): for k, v in bad_hdrs.items(): self.assertFalse(k.lower() in dst_headers) + def test_generate_request_headers_with_no_orig_req(self): + base = Controller(self.app) + src_headers = {'x-remove-base-meta-owner': 'x', + 'x-base-meta-size': '151M', + 'new-owner': 'Kun'} + dst_headers = base.generate_request_headers(None, + additional=src_headers) + expected_headers = {'x-base-meta-size': '151M', + 'connection': 'close'} + for k, v in expected_headers.items(): + self.assertDictContainsSubset(expected_headers, dst_headers) + self.assertEqual('', dst_headers['Referer']) + def test_client_chunk_size(self): class TestSource(object):