Merge "Do not follow CNAME when host is in storage_domain"

This commit is contained in:
Jenkins 2017-02-24 00:03:16 +00:00 committed by Gerrit Code Review
commit c749799791
2 changed files with 30 additions and 0 deletions

View File

@ -103,6 +103,7 @@ class CNAMELookupMiddleware(object):
self.logger = get_logger(conf, log_route='cname-lookup')
def _domain_endswith_in_storage_domain(self, a_domain):
a_domain = '.' + a_domain
for domain in self.storage_domain:
if a_domain.endswith(domain):
return True

View File

@ -239,6 +239,35 @@ class TestCNAMELookup(unittest.TestCase):
resp = do_test('c.badtest.com')
self.assertEqual(resp, bad_domain)
def test_host_is_storage_domain(self):
conf = {'storage_domain': 'storage.example.com',
'lookup_depth': 2}
app = cname_lookup.CNAMELookupMiddleware(FakeApp(), conf)
def do_test(host):
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
headers={'Host': host})
return app(req.environ, start_response)
bad_domain = ['CNAME lookup failed after 2 tries']
resp = do_test('c.badtest.com')
self.assertEqual(resp, bad_domain)
resp = do_test('storage.example.com')
self.assertEqual(resp, 'FAKE APP')
def test_resolution_to_storage_domain_exactly(self):
conf = {'storage_domain': 'example.com',
'lookup_depth': 1}
app = cname_lookup.CNAMELookupMiddleware(FakeApp(), conf)
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
headers={'Host': 'mysite.com'})
module = 'swift.common.middleware.cname_lookup.lookup_cname'
with mock.patch(module, lambda x: (0, 'example.com')):
resp = app(req.environ, start_response)
self.assertEqual(resp, 'FAKE APP')
class TestSwiftInfo(unittest.TestCase):
def setUp(self):