From e008112d0f964b00bd5cb633262365ebc7f9395b Mon Sep 17 00:00:00 2001 From: Thomas Bechtold Date: Fri, 5 Feb 2016 22:52:32 +0100 Subject: [PATCH] Fix "Add API version to identity endpoint URLs" Change Ieff5a6cdd1ad352a9731d46785802e8c36adcdd1 introduced an uncomplete fix when trying to fix the auth_url. Given the case that a auth url already has a version included, an extra version was added. This leads to messages in the keystone.log that horizon is trying to authenticate with "POST /v3/v3/auth/tokens HTTP/1.1". Use urlparse correctly and also add a testcase for fix_auth_url_version(). Change-Id: I80fb310d95e8fdab1212fc5b092a37fd7b26a37a Closes-Bug: 1508421 --- openstack_auth/tests/tests.py | 29 +++++++++++++++++++++++++++++ openstack_auth/utils.py | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/openstack_auth/tests/tests.py b/openstack_auth/tests/tests.py index 894eaf6..06f4291 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 77b7117..747bc36 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: