Get endpoint versions with domain scope session

Session.get_endpoint() failed when using domain scope
authentcation, that cause by missing of project id in auth,
that is regluar use case for admin to operate the resource
(user, project, role and so on) of identity service with
domain scope token. This patch fix the issue.

Change-Id: I7f1f656918f6bfc1ea7333c49b97003022184d99
Closes-Bug: #1688241
This commit is contained in:
Rui Chen 2017-05-05 14:39:05 +08:00
parent 84d44a8d24
commit bc4a0c4066
2 changed files with 23 additions and 1 deletions

View File

@ -186,7 +186,8 @@ class Session(_session.Session):
# However, we do need to know that the project id was
# previously there, so keep it.
project_id = self.get_project_id()
project_id_location = parts.path.find(project_id)
# Domain scope token don't include project id
project_id_location = parts.path.find(project_id) if project_id else -1
if project_id_location > -1:
usable_path = parts.path[slice(0, project_id_location)]
needs_project_id = True

View File

@ -328,6 +328,27 @@ class TestSession(testtools.TestCase):
self.assertEqual(result, responses[0])
self.assertFalse(result.needs_project_id)
def test__get_endpoint_versions_with_domain_scope(self):
# This test covers a common case of services deployed under
# subdomains. Additionally, it covers the case of getting endpoint
# versions with domain scope token
sc_uri = "https://service.cloud.com/identity"
versions_uri = "https://service.cloud.com"
sot = session.Session(None)
# Project id is None when domain scope session present
sot.get_project_id = mock.Mock(return_value=None)
responses = [session.Session._Endpoint(versions_uri, "versions")]
sot._parse_versions_response = mock.Mock(side_effect=responses)
result = sot._get_endpoint_versions("type", sc_uri)
sot._parse_versions_response.assert_called_once_with(versions_uri)
self.assertEqual(result, responses[0])
self.assertFalse(result.needs_project_id)
self.assertIsNone(result.project_id)
def test__parse_version(self):
sot = session.Session(None)