Merge "Pick up general URI when constructing barbican endpoint"

This commit is contained in:
Jenkins 2017-09-22 02:55:55 +00:00 committed by Gerrit Code Review
commit 6da6b0a0aa
3 changed files with 34 additions and 1 deletions

View File

@ -43,6 +43,8 @@ def _get_versioned_url(version):
version += '/'
# If host_href is not set in barbican conf, then derive it from request url
host_part = utils.get_base_url_from_request()
if host_part[-1] != '/':
host_part += '/'
return parse.urljoin(host_part, version)

View File

@ -78,7 +78,10 @@ def get_base_url_from_request():
"""
if not CONF.host_href and hasattr(pecan.request, 'url'):
p_url = parse.urlsplit(pecan.request.url)
base_url = '%s://%s' % (p_url.scheme, p_url.netloc)
if p_url.path:
base_url = '%s://%s%s' % (p_url.scheme, p_url.netloc, p_url.path)
else:
base_url = '%s://%s' % (p_url.scheme, p_url.netloc)
return base_url
else: # when host_href is set or flow is not within wsgi request context
return CONF.host_href

View File

@ -79,6 +79,34 @@ class WhenTestingVersionsResource(utils.BarbicanAPIBaseTestCase):
self.assertNotIn(dummy_root, v_info['links'][0]['href'])
self.assertNotIn(host_hdr, v_info['links'][0]['href'])
def test_when_host_href_is_general(self):
host_href = 'http://myapp.server.com/key-manager'
cmn_utils.CONF.set_override('host_href', host_href)
host_hdr = 'http://myproxy.server.com:9311'
utils.mock_pecan_request(self, host=host_hdr)
dummy_root = 'http://mylocalhost:9999'
resp = self.app.get(dummy_root)
versions_response = resp.json['versions']['values']
for v_info in versions_response:
self.assertIn(host_href, v_info['links'][0]['href'])
self.assertNotIn(dummy_root, v_info['links'][0]['href'])
self.assertNotIn(host_hdr, v_info['links'][0]['href'])
def test_when_host_href_is_not_set_with_general_request_url(self):
cmn_utils.CONF.set_override('host_href', '')
host_hdr = 'http://myproxy.server.com/key-manager'
utils.mock_pecan_request(self, host=host_hdr)
dummy_root = 'http://mylocalhost:9999'
resp = self.app.get(dummy_root)
versions_response = resp.json['versions']['values']
for v_info in versions_response:
self.assertIn(host_hdr, v_info['links'][0]['href'])
self.assertNotIn(dummy_root, v_info['links'][0]['href'])
class WhenTestingV1Resource(utils.BarbicanAPIBaseTestCase):