get_endpoint should return None when no version found

After patch Ia08538ccf00c9063dc0d284c5ece9a969c15500a the urljoin would
ensure that a URL was always returned from the get_endpoint method even
when the version was not available. This breaks plugin discovery and a
number of other areas.

Change-Id: I04014b6e770c2e9708c5f9c81c3160d51603ad0c
Closes-Bug: #1616720
This commit is contained in:
Jamie Lennox 2016-08-25 13:49:35 +10:00
parent 5f34cb14d4
commit b7b887c519
2 changed files with 25 additions and 2 deletions

View File

@ -246,8 +246,10 @@ class BaseIdentityPlugin(plugin.BaseAuthPlugin):
# for example a "v2" path from http://host/admin should resolve as
# http://host/admin/v2 where it would otherwise be host/v2.
# This has no effect on absolute urls returned from url_for.
url_for = disc.url_for(version, **allow)
url = urllib.parse.urljoin(hacked_url.rstrip('/') + '/', url_for)
url = disc.url_for(version, **allow)
if url:
url = urllib.parse.urljoin(hacked_url.rstrip('/') + '/', url)
return url

View File

@ -253,6 +253,27 @@ class CommonIdentityTests(object):
self.assertEqual(self.TEST_COMPUTE_ADMIN + '/v2.0', endpoint_v2)
self.assertEqual(self.TEST_COMPUTE_ADMIN + '/v3', endpoint_v3)
def test_discovering_when_version_missing(self):
# need to construct list this way for relative
disc = fixture.DiscoveryList(v2=False, v3=False)
disc.add_v2('v2.0')
self.stub_url('GET', [], base_url=self.TEST_COMPUTE_ADMIN, json=disc)
a = self.create_auth_plugin()
s = session.Session(auth=a)
endpoint_v2 = s.get_endpoint(service_type='compute',
interface='admin',
version=(2, 0))
endpoint_v3 = s.get_endpoint(service_type='compute',
interface='admin',
version=(3, 0))
self.assertEqual(self.TEST_COMPUTE_ADMIN + '/v2.0', endpoint_v2)
self.assertIsNone(endpoint_v3)
def test_asking_for_auth_endpoint_ignores_checks(self):
a = self.create_auth_plugin()
s = session.Session(auth=a)