Append a forward slash to the base_url
six.moves.urllib.parse.urljoin strips everything that doesn't end with a forward slash, so for example, if the barbican URL is http://ip-address/key-manager, the "key-manager" part will be removed. If the URL is http://ip-address/key-manager/, everything will be fine. Change-Id: I1afcd7ae460633e451bc365fdb87f6e30bb3a60b
This commit is contained in:
parent
6fe37f79a4
commit
233febb0c1
@ -202,8 +202,12 @@ class BarbicanKeyManager(key_manager.KeyManager):
|
||||
latest_version = raw_data[-1]
|
||||
api_version = latest_version.get('id')
|
||||
|
||||
if endpoint[-1] != '/':
|
||||
endpoint += '/'
|
||||
|
||||
base_url = urllib.parse.urljoin(
|
||||
endpoint, api_version)
|
||||
|
||||
return base_url
|
||||
|
||||
def create_key(self, context, algorithm, length,
|
||||
|
@ -76,6 +76,24 @@ class BarbicanKeyManagerTestCase(test_key_manager.KeyManagerTestCase):
|
||||
self.key_mgr._barbican_client = self.mock_barbican
|
||||
self.key_mgr._current_context = self.ctxt
|
||||
|
||||
def test_base_url_old_version(self):
|
||||
version = "v1"
|
||||
self.key_mgr.conf.barbican.barbican_api_version = version
|
||||
endpoint = "http://localhost:9311"
|
||||
base_url = self.key_mgr._create_base_url(mock.Mock(),
|
||||
mock.Mock(),
|
||||
endpoint)
|
||||
self.assertEqual(endpoint + "/" + version, base_url)
|
||||
|
||||
def test_base_url_new_version(self):
|
||||
version = "v1"
|
||||
self.key_mgr.conf.barbican.barbican_api_version = version
|
||||
endpoint = "http://localhost/key_manager"
|
||||
base_url = self.key_mgr._create_base_url(mock.Mock(),
|
||||
mock.Mock(),
|
||||
endpoint)
|
||||
self.assertEqual(endpoint + "/" + version, base_url)
|
||||
|
||||
def test_create_key(self):
|
||||
# Create order_ref_url and assign return value
|
||||
order_ref_url = ("http://localhost:9311/v1/orders/"
|
||||
|
Loading…
x
Reference in New Issue
Block a user