File 0001-Fix-duplicate-paths-in-secret-hrefs.patch of Package openstack-barbican
diff --git a/barbican/common/utils.py b/barbican/common/utils.py
index 09f92378..ad204a57 100644
--- a/barbican/common/utils.py
+++ b/barbican/common/utils.py
@@ -24,6 +24,7 @@ import uuid
from oslo_log import log
from oslo_utils import uuidutils
import pecan
+import re
import six
from six.moves.urllib import parse
@@ -76,8 +77,8 @@ def get_base_url_from_request():
Some of unit tests does not have pecan context that's why using request
attr check on pecan instance.
"""
- if not CONF.host_href and hasattr(pecan.request, 'url'):
- p_url = parse.urlsplit(pecan.request.url)
+ if not CONF.host_href and hasattr(pecan.request, 'application_url'):
+ p_url = parse.urlsplit(pecan.request.application_url)
# Pecan does not handle X_FORWARDED_PROTO yet, so we need to
# handle it ourselves. see lp#1445290
scheme = pecan.request.environ.get('HTTP_X_FORWARDED_PROTO', 'http')
@@ -86,7 +87,10 @@ def get_base_url_from_request():
netloc = pecan.request.environ.get('HTTP_HOST', p_url.netloc)
# FIXME: implement SERVER_NAME lookup if HTTP_HOST is not set
if p_url.path:
- base_url = '%s://%s%s' % (scheme, netloc, p_url.path)
+ # Remove the version from the path to extract the base path
+ base_path = re.sub('/{version}$'.format(version=API_VERSION),
+ '', p_url.path)
+ base_url = '%s://%s%s' % (scheme, netloc, base_path)
else:
base_url = '%s://%s' % (scheme, netloc)
return base_url
diff --git a/barbican/tests/utils.py b/barbican/tests/utils.py
index 1adf08b4..b4eafaba 100644
--- a/barbican/tests/utils.py
+++ b/barbican/tests/utils.py
@@ -49,6 +49,7 @@ def mock_pecan_request(test_instance, host=None):
mock_req = patcher_obj.start()
test_instance.addCleanup(patcher_obj.stop)
mock_req.url = host
+ mock_req.application_url = host
@contextmanager