From bc4a0c4066cda46b598537ff072f3e956d77a579 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Fri, 5 May 2017 14:39:05 +0800 Subject: [PATCH] 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 --- openstack/session.py | 3 ++- openstack/tests/unit/test_session.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/openstack/session.py b/openstack/session.py index 3d3323cc..f3a55e90 100644 --- a/openstack/session.py +++ b/openstack/session.py @@ -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 diff --git a/openstack/tests/unit/test_session.py b/openstack/tests/unit/test_session.py index 528fe507..82cdeeca 100644 --- a/openstack/tests/unit/test_session.py +++ b/openstack/tests/unit/test_session.py @@ -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)