diff options
author | Thomas Bechtold <tbechtold@suse.com> | 2016-02-05 22:52:32 +0100 |
---|---|---|
committer | Johannes Grassler <johannes.grassler@suse.com> | 2016-02-16 09:24:02 +0100 |
commit | 3f035859bd6b52e1e25ecdb163ff76c5a8509d68 (patch) | |
tree | b17acadf87c357a969bfe2864ddc953aa6a3bf9a | |
parent | dc981578062a6a8d2f026cd8a03b892fd1e779dd (diff) | |
download | django_openstack_auth-3f035859bd6b52e1e25ecdb163ff76c5a8509d68.tar.gz |
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
(cherry picked from commit e008112d0f964b00bd5cb633262365ebc7f9395b)
Closes-Bug: 1508421
-rw-r--r-- | openstack_auth/tests/tests.py | 29 | ||||
-rw-r--r-- | openstack_auth/utils.py | 2 |
2 files changed, 30 insertions, 1 deletions
diff --git a/openstack_auth/tests/tests.py b/openstack_auth/tests/tests.py index 241fd00..f18fafb 100644 --- a/openstack_auth/tests/tests.py +++ b/openstack_auth/tests/tests.py @@ -1007,3 +1007,32 @@ class PolicyTestCaseAdmin(PolicyTestCase): value = policy.check((("compute", "context_is_admin"),), request=self.request) self.assertTrue(value) + + +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 5abcbac..95e007c 100644 --- a/openstack_auth/utils.py +++ b/openstack_auth/utils.py @@ -264,7 +264,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: |