From 306f9a150f4490a5af0fd41f0b08c5fcd2d5a32a Mon Sep 17 00:00:00 2001 From: Samuel Merritt Date: Fri, 22 Jun 2018 16:09:26 -0700 Subject: [PATCH] py3: port domain_remap tests The domain_remap middleware didn't need to change, only its tests. Change-Id: I5edf05b609ce263708f851219c38c1bd1b645a6f --- .../common/middleware/test_domain_remap.py | 68 +++++++++---------- tox.ini | 1 + 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/test/unit/common/middleware/test_domain_remap.py b/test/unit/common/middleware/test_domain_remap.py index 63a0b8aa96..8492a1dd7e 100644 --- a/test/unit/common/middleware/test_domain_remap.py +++ b/test/unit/common/middleware/test_domain_remap.py @@ -24,7 +24,7 @@ class FakeApp(object): def __call__(self, env, start_response): start_response('200 OK', []) - return [env['PATH_INFO']] + return [env['PATH_INFO'].encode('latin-1')] class RedirectSlashApp(object): @@ -48,54 +48,54 @@ class TestDomainRemap(unittest.TestCase): 'SERVER_NAME': 'example.com'}, headers={'Host': None}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/']) + self.assertEqual(resp, [b'/']) req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/']) + self.assertEqual(resp, [b'/']) req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'example.com:8080'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/']) + self.assertEqual(resp, [b'/']) def test_domain_remap_account(self): req = Request.blank('/', environ={'REQUEST_METHOD': 'GET', 'SERVER_NAME': 'AUTH_a.example.com'}, headers={'Host': None}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/']) + self.assertEqual(resp, [b'/v1/AUTH_a/']) req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/']) + self.assertEqual(resp, [b'/v1/AUTH_a/']) req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'AUTH-uuid.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_uuid/']) + self.assertEqual(resp, [b'/v1/AUTH_uuid/']) def test_domain_remap_account_container(self): req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c/']) + self.assertEqual(resp, [b'/v1/AUTH_a/c/']) def test_domain_remap_extra_subdomains(self): req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'x.y.c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['Bad domain in host header']) + self.assertEqual(resp, [b'Bad domain in host header']) def test_domain_remap_account_with_path_root_container(self): req = Request.blank('/v1', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/v1']) + self.assertEqual(resp, [b'/v1/AUTH_a/v1']) def test_domain_remap_account_container_with_path_root_obj(self): req = Request.blank('/v1', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c/v1']) + self.assertEqual(resp, [b'/v1/AUTH_a/c/v1']) def test_domain_remap_account_container_with_path_obj_slash_v1(self): # Include http://localhost because urlparse used in Request.__init__ @@ -104,44 +104,44 @@ class TestDomainRemap(unittest.TestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c//v1']) + self.assertEqual(resp, [b'/v1/AUTH_a/c//v1']) def test_domain_remap_account_container_with_root_path_obj_slash_v1(self): req = Request.blank('/v1//v1', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c/v1//v1']) + self.assertEqual(resp, [b'/v1/AUTH_a/c/v1//v1']) def test_domain_remap_account_container_with_path_trailing_slash(self): req = Request.blank('/obj/', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c/obj/']) + self.assertEqual(resp, [b'/v1/AUTH_a/c/obj/']) def test_domain_remap_account_container_with_path(self): req = Request.blank('/obj', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c/obj']) + self.assertEqual(resp, [b'/v1/AUTH_a/c/obj']) def test_domain_remap_account_container_with_path_root_and_path(self): req = Request.blank('/v1/obj', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c/v1/obj']) + self.assertEqual(resp, [b'/v1/AUTH_a/c/v1/obj']) def test_domain_remap_with_path_root_and_path_no_slash(self): req = Request.blank('/v1obj', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c/v1obj']) + self.assertEqual(resp, [b'/v1/AUTH_a/c/v1obj']) def test_domain_remap_account_matching_ending_not_domain(self): req = Request.blank('/dontchange', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.aexample.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/dontchange']) + self.assertEqual(resp, [b'/dontchange']) def test_domain_remap_configured_with_empty_storage_domain(self): self.app = domain_remap.DomainRemapMiddleware(FakeApp(), @@ -149,7 +149,7 @@ class TestDomainRemap(unittest.TestCase): req = Request.blank('/test', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/test']) + self.assertEqual(resp, [b'/test']) def test_storage_domains_conf_format(self): conf = {'storage_domain': 'foo.com'} @@ -178,7 +178,7 @@ class TestDomainRemap(unittest.TestCase): req = Request.blank('/test', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.prefix_uuid.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/PREFIX_uuid/c/test']) + self.assertEqual(resp, [b'/v1/PREFIX_uuid/c/test']) def test_domain_remap_configured_with_bad_prefixes(self): conf = {'reseller_prefixes': 'UNKNOWN'} @@ -186,7 +186,7 @@ class TestDomainRemap(unittest.TestCase): req = Request.blank('/test', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.prefix_uuid.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/test']) + self.assertEqual(resp, [b'/test']) def test_domain_remap_configured_with_no_prefixes(self): conf = {'reseller_prefixes': ''} @@ -194,7 +194,7 @@ class TestDomainRemap(unittest.TestCase): req = Request.blank('/test', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.uuid.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/uuid/c/test']) + self.assertEqual(resp, [b'/v1/uuid/c/test']) def test_domain_remap_add_prefix(self): conf = {'default_reseller_prefix': 'FOO'} @@ -202,7 +202,7 @@ class TestDomainRemap(unittest.TestCase): req = Request.blank('/test', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'uuid.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/FOO_uuid/test']) + self.assertEqual(resp, [b'/v1/FOO_uuid/test']) def test_domain_remap_add_prefix_already_there(self): conf = {'default_reseller_prefix': 'AUTH'} @@ -210,7 +210,7 @@ class TestDomainRemap(unittest.TestCase): req = Request.blank('/test', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'auth-uuid.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_uuid/test']) + self.assertEqual(resp, [b'/v1/AUTH_uuid/test']) def test_multiple_storage_domains(self): conf = {'storage_domain': 'storage1.com, storage2.com'} @@ -222,13 +222,13 @@ class TestDomainRemap(unittest.TestCase): return self.app(req.environ, start_response) resp = do_test('auth-uuid.storage1.com') - self.assertEqual(resp, ['/v1/AUTH_uuid/test']) + self.assertEqual(resp, [b'/v1/AUTH_uuid/test']) resp = do_test('auth-uuid.storage2.com') - self.assertEqual(resp, ['/v1/AUTH_uuid/test']) + self.assertEqual(resp, [b'/v1/AUTH_uuid/test']) resp = do_test('auth-uuid.storage3.com') - self.assertEqual(resp, ['/test']) + self.assertEqual(resp, [b'/test']) def test_domain_remap_redirect(self): app = domain_remap.DomainRemapMiddleware(RedirectSlashApp(), {}) @@ -264,13 +264,13 @@ class TestDomainRemapClientMangling(unittest.TestCase): req = Request.blank('/v1', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/']) + self.assertEqual(resp, [b'/v1/AUTH_a/']) def test_domain_remap_account_container_with_path_root_obj(self): req = Request.blank('/v1', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c/']) + self.assertEqual(resp, [b'/v1/AUTH_a/c/']) def test_domain_remap_account_container_with_path_obj_slash_v1(self): # Include http://localhost because urlparse used in Request.__init__ @@ -279,32 +279,32 @@ class TestDomainRemapClientMangling(unittest.TestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c//v1']) + self.assertEqual(resp, [b'/v1/AUTH_a/c//v1']) def test_domain_remap_account_container_with_root_path_obj_slash_v1(self): req = Request.blank('/v1//v1', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c//v1']) + self.assertEqual(resp, [b'/v1/AUTH_a/c//v1']) def test_domain_remap_account_container_with_path_trailing_slash(self): req = Request.blank('/obj/', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c/obj/']) + self.assertEqual(resp, [b'/v1/AUTH_a/c/obj/']) def test_domain_remap_account_container_with_path_root_and_path(self): req = Request.blank('/v1/obj', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c/obj']) + self.assertEqual(resp, [b'/v1/AUTH_a/c/obj']) def test_domain_remap_with_path_root_and_path_no_slash(self): req = Request.blank('/v1obj', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'c.AUTH_a.example.com'}) resp = self.app(req.environ, start_response) - self.assertEqual(resp, ['/v1/AUTH_a/c/v1obj']) + self.assertEqual(resp, [b'/v1/AUTH_a/c/v1obj']) class TestSwiftInfo(unittest.TestCase): diff --git a/tox.ini b/tox.ini index 1bec86a68b..2d9ded8ad2 100644 --- a/tox.ini +++ b/tox.ini @@ -38,6 +38,7 @@ commands = test/unit/cli/test_ringbuilder.py \ test/unit/common/middleware/test_catch_errors.py \ test/unit/common/middleware/test_crossdomain.py \ + test/unit/common/middleware/test_domain_remap.py \ test/unit/common/middleware/test_gatekeeper.py \ test/unit/common/middleware/test_healthcheck.py \ test/unit/common/middleware/test_proxy_logging.py \