Inject /v3 in token path for v3 plugins

Without this, it's possible to get HTTP 404 errors from keystone if
OS_AUTH_URL isn't versioned (e.g., instead
of, even if OS_IDENTITY_API is set to

This commit works around this issue by checking the AUTH_URL before
building the token_url and appending '/v3' to the URL before sending the

Closes-Bug: 1876317

Change-Id: Ic75f0c9b36022b884105b87bfe05f4f8292d53b2
This commit is contained in:
Lance Bragstad 2020-05-01 01:02:12 +00:00 committed by Monty Taylor
parent fdd4078202
commit ad46262148
3 changed files with 35 additions and 1 deletions

View File

@ -173,9 +173,13 @@ class Auth(BaseAuth):
if self.system_scope == 'all':
body['auth']['scope'] = {'system': {'all': True}}
token_url = self.token_url
if not self.auth_url.rstrip('/').endswith('v3'):
token_url = '%s/v3/auth/tokens' % self.auth_url.rstrip('/')
# NOTE(jamielennox): we add nocatalog here rather than in token_url
# directly as some federation plugins require the base token_url
token_url = self.token_url
if not self.include_catalog:
token_url += '?nocatalog'

View File

@ -798,3 +798,27 @@ class V3IdentityPlugin(utils.TestCase):
self.assertRequestHeaderEqual("Content-Type", "application/json")
self.assertRequestHeaderEqual("Accept", "application/json")
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
def test_authenticate_with_unversioned_endpoint(self):
# We use the root url here because it doesn't reference the API version
# (e.g., '/v3'). We want to make sure the authentication plugin handles
# this and appends /v3 if it's not present.
a = v3.Password(self.TEST_ROOT_URL,
s = session.Session(auth=a)
self.assertEqual({'X-Auth-Token': self.TEST_TOKEN},
req = {'auth': {'identity':
{'methods': ['password'],
'password': {'user': {'name': self.TEST_USER,
'password': self.TEST_PASS}}}}}
self.assertRequestHeaderEqual('Content-Type', 'application/json')
self.assertRequestHeaderEqual('Accept', 'application/json')
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)

View File

@ -0,0 +1,6 @@
- |
[`bug 1876317 <>`_]
The v3 authentication plugins now attempt to add /v3 to the token path if
it's not present on the authentication URL.