Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Pradet <quentinp@apache.org>
  • Loading branch information
micafer authored and pquentin committed Jan 30, 2018
1 parent 22545c7 commit 7ef969c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
13 changes: 12 additions & 1 deletion libcloud/common/openstack_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,12 +1525,23 @@ def _get_project_id(self, token):
"""
Get the first project ID accessible with the specified access token
"""
path = '/v3/OS-FEDERATION/projects'
# Try new path first (from ver 1.1)
path = '/v3/auth/projects'
response = self.request(path,
headers={'Content-Type': 'application/json',
'X-Auth-Token': token},
method='GET')

if response.status not in [httplib.UNAUTHORIZED, httplib.OK,
httplib.CREATED]:
# In case of error try old one
path = '/v3/OS-FEDERATION/projects'
response = self.request(path,
headers={'Content-Type':
'application/json',
'X-Auth-Token': token},
method='GET')

if response.status == httplib.UNAUTHORIZED:
# Invalid credentials
raise InvalidCredsError()
Expand Down
47 changes: 47 additions & 0 deletions libcloud/test/common/test_openstack_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,30 @@ def test_revoke_project_role_from_user(self):
self.assertTrue(result)


class OpenStackIdentity_3_0_Connection_OIDC_access_token_federation_projectsTests(
unittest.TestCase):
def setUp(self):
mock_cls = OpenStackIdentity_3_0_federation_projects_MockHttp
mock_cls.type = None
OpenStackIdentity_3_0_Connection_OIDC_access_token.conn_class = mock_cls

self.auth_instance = OpenStackIdentity_3_0_Connection_OIDC_access_token(auth_url='http://none',
user_id='idp',
key='token',
tenant_name='oidc',
domain_name='test_domain')
self.auth_instance.auth_token = 'mock'

def test_authenticate(self):
auth = OpenStackIdentity_3_0_Connection_OIDC_access_token(auth_url='http://none',
user_id='idp',
key='token',
token_scope='project',
tenant_name="oidc",
domain_name='test_domain')
auth.authenticate()


class OpenStackIdentity_3_0_Connection_OIDC_access_tokenTests(
unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -729,6 +753,29 @@ def _v3_OS_FEDERATION_projects(self, method, url, body, headers):
return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
raise NotImplementedError()

def _v3_auth_projects(self, method, url, body, headers):
if method == 'GET':
# get user projects
body = json.dumps({"projects": [{"id": "project_id"}]})
return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
raise NotImplementedError()


class OpenStackIdentity_3_0_federation_projects_MockHttp(OpenStackIdentity_3_0_MockHttp):
fixtures = ComputeFileFixtures('openstack_identity/v3')
json_content_headers = {'content-type': 'application/json; charset=UTF-8'}

def _v3_OS_FEDERATION_projects(self, method, url, body, headers):
if method == 'GET':
# get user projects
body = json.dumps({"projects": [{"id": "project_id"}]})
return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
raise NotImplementedError()

def _v3_auth_projects(self, method, url, body, headers):
return (httplib.INTERNAL_SERVER_ERROR, body, self.json_content_headers,
httplib.responses[httplib.INTERNAL_SERVER_ERROR])


class OpenStackIdentity_2_0_Connection_VOMSMockHttp(MockHttp):
fixtures = ComputeFileFixtures('openstack_identity/v2')
Expand Down

0 comments on commit 7ef969c

Please sign in to comment.