diff --git a/openstack_auth/tests/tests.py b/openstack_auth/tests/tests.py index 894eaf6a..06f4291e 100644 --- a/openstack_auth/tests/tests.py +++ b/openstack_auth/tests/tests.py @@ -1127,3 +1127,32 @@ class RoleTestCaseAdmin(test.TestCase): self.assertSetEqual({'openstack.roles.foo', 'openstack.roles.bar', 'openstack.roles.admin'}, admin_permissions) + + +class UtilsTestCase(test.TestCase): + + def test_fix_auth_url_version_v20(self): + settings.OPENSTACK_API_VERSIONS['identity'] = 2.0 + test_urls = [ + ("http://a/", "http://a/v2.0"), + ("http://a", "http://a/v2.0"), + ("http://a:8080/", "http://a:8080/v2.0"), + ("http://a/v2.0", "http://a/v2.0"), + ("http://a/v2.0/", "http://a/v2.0/"), + ] + for src, expected in test_urls: + self.assertEqual(expected, utils.fix_auth_url_version(src)) + + def test_fix_auth_url_version_v3(self): + settings.OPENSTACK_API_VERSIONS['identity'] = 3 + test_urls = [ + ("http://a/", "http://a/v3"), + ("http://a", "http://a/v3"), + ("http://a:8080/", "http://a:8080/v3"), + ("http://a/v3", "http://a/v3"), + ("http://a/v3/", "http://a/v3/"), + ("http://a/v2.0/", "http://a/v3/"), + ("http://a/v2.0", "http://a/v3"), + ] + for src, expected in test_urls: + self.assertEqual(expected, utils.fix_auth_url_version(src)) diff --git a/openstack_auth/utils.py b/openstack_auth/utils.py index 77b71176..747bc36f 100644 --- a/openstack_auth/utils.py +++ b/openstack_auth/utils.py @@ -265,7 +265,7 @@ def fix_auth_url_version(auth_url): # Check for empty path component in endpoint URL and add keystone version # to endpoint: as of Kilo, the identity URLs returned by Keystone might no # longer contain API versions, leaving the version choice up to the user. - if urlparse.urlparse(auth_url)[3] == '': + if urlparse.urlparse(auth_url).path.rstrip('/') == '': if get_keystone_version() >= 3: auth_url = urlparse.urljoin(auth_url, 'v3') else: