Merge "Allow empty reseller prefixes in domain_remap"
This commit is contained in:
commit
c5013783ac
@ -98,18 +98,19 @@ class DomainRemapMiddleware(object):
|
|||||||
body='Bad domain in host header',
|
body='Bad domain in host header',
|
||||||
content_type='text/plain')
|
content_type='text/plain')
|
||||||
return resp(env, start_response)
|
return resp(env, start_response)
|
||||||
if '_' not in account and '-' in account:
|
if len(self.reseller_prefixes) > 0:
|
||||||
account = account.replace('-', '_', 1)
|
if '_' not in account and '-' in account:
|
||||||
account_reseller_prefix = account.split('_', 1)[0].lower()
|
account = account.replace('-', '_', 1)
|
||||||
if account_reseller_prefix not in self.reseller_prefixes_lower:
|
account_reseller_prefix = account.split('_', 1)[0].lower()
|
||||||
# account prefix is not in config list. bail.
|
if account_reseller_prefix not in self.reseller_prefixes_lower:
|
||||||
return self.app(env, start_response)
|
# account prefix is not in config list. bail.
|
||||||
prefix_index = self.reseller_prefixes_lower.index(
|
return self.app(env, start_response)
|
||||||
account_reseller_prefix)
|
prefix_index = self.reseller_prefixes_lower.index(
|
||||||
real_prefix = self.reseller_prefixes[prefix_index]
|
account_reseller_prefix)
|
||||||
if not account.startswith(real_prefix):
|
real_prefix = self.reseller_prefixes[prefix_index]
|
||||||
account_suffix = account[len(real_prefix):]
|
if not account.startswith(real_prefix):
|
||||||
account = real_prefix + account_suffix
|
account_suffix = account[len(real_prefix):]
|
||||||
|
account = real_prefix + account_suffix
|
||||||
path = env['PATH_INFO'].strip('/')
|
path = env['PATH_INFO'].strip('/')
|
||||||
new_path_parts = ['', self.path_root, account]
|
new_path_parts = ['', self.path_root, account]
|
||||||
if container:
|
if container:
|
||||||
|
@ -130,6 +130,14 @@ class TestDomainRemap(unittest.TestCase):
|
|||||||
resp = self.app(req.environ, start_response)
|
resp = self.app(req.environ, start_response)
|
||||||
self.assertEquals(resp, '/test')
|
self.assertEquals(resp, '/test')
|
||||||
|
|
||||||
|
def test_domain_remap_configured_with_no_prefixes(self):
|
||||||
|
conf = {'reseller_prefixes': ''}
|
||||||
|
self.app = domain_remap.DomainRemapMiddleware(FakeApp(), conf)
|
||||||
|
req = Request.blank('/test', environ={'REQUEST_METHOD': 'GET'},
|
||||||
|
headers={'Host': 'c.uuid.example.com'})
|
||||||
|
resp = self.app(req.environ, start_response)
|
||||||
|
self.assertEquals(resp, '/v1/uuid/c/test')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user