From b7b887c5192f2940073d038360a64041fc4f38cc Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Thu, 25 Aug 2016 13:49:35 +1000 Subject: [PATCH] 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 --- keystoneauth1/identity/base.py | 6 ++++-- .../unit/identity/test_identity_common.py | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/keystoneauth1/identity/base.py b/keystoneauth1/identity/base.py index 2e71581f..a64075aa 100644 --- a/keystoneauth1/identity/base.py +++ b/keystoneauth1/identity/base.py @@ -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 diff --git a/keystoneauth1/tests/unit/identity/test_identity_common.py b/keystoneauth1/tests/unit/identity/test_identity_common.py index 97d4e78f..a71565d1 100644 --- a/keystoneauth1/tests/unit/identity/test_identity_common.py +++ b/keystoneauth1/tests/unit/identity/test_identity_common.py @@ -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)