Browse Source

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
Jamie Lennox 2 years ago
parent
commit
b7b887c519

+ 4
- 2
keystoneauth1/identity/base.py View File

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

+ 21
- 0
keystoneauth1/tests/unit/identity/test_identity_common.py View File

@@ -253,6 +253,27 @@ class CommonIdentityTests(object):
253 253
         self.assertEqual(self.TEST_COMPUTE_ADMIN + '/v2.0', endpoint_v2)
254 254
         self.assertEqual(self.TEST_COMPUTE_ADMIN + '/v3', endpoint_v3)
255 255
 
256
+    def test_discovering_when_version_missing(self):
257
+        # need to construct list this way for relative
258
+        disc = fixture.DiscoveryList(v2=False, v3=False)
259
+        disc.add_v2('v2.0')
260
+
261
+        self.stub_url('GET', [], base_url=self.TEST_COMPUTE_ADMIN, json=disc)
262
+
263
+        a = self.create_auth_plugin()
264
+        s = session.Session(auth=a)
265
+
266
+        endpoint_v2 = s.get_endpoint(service_type='compute',
267
+                                     interface='admin',
268
+                                     version=(2, 0))
269
+
270
+        endpoint_v3 = s.get_endpoint(service_type='compute',
271
+                                     interface='admin',
272
+                                     version=(3, 0))
273
+
274
+        self.assertEqual(self.TEST_COMPUTE_ADMIN + '/v2.0', endpoint_v2)
275
+        self.assertIsNone(endpoint_v3)
276
+
256 277
     def test_asking_for_auth_endpoint_ignores_checks(self):
257 278
         a = self.create_auth_plugin()
258 279
         s = session.Session(auth=a)

Loading…
Cancel
Save