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)