summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLance Bragstad <lbragstad@gmail.com>2018-07-25 15:07:16 +0000
committerLance Bragstad <lbragstad@gmail.com>2018-07-25 15:54:28 +0000
commitade177ad357d28746ab4203e56a74e6e1e89c074 (patch)
tree470c0a0cdddc3ebb0bc36fa9a5ac1e5610e794c6
parentb6a009254f7975bf806c499874ad87746bb8cbd8 (diff)
downloadkeystone-ade177ad357d28746ab4203e56a74e6e1e89c074.tar.gz
Reduce duplication in federated auth APIsocata-em11.0.4
The GET /v3/OS-FEDERATION/projects and GET /v3/OS-FEDERATION/domains APIs were introduced to handle tokens from federated users, but now that GET /v3/auth/projects and GET /v3/auth/domains know how to handle federated tokens, they're just duplicate APIs. In the past we deprecated these federated auth APIs, but they still used separate code paths from GET /v3/auth/projects and GET /v3/auth/domains. The two code paths are true duplication in that they don't expect to differ over time and should provide the same user experience. Instead of running the risk that comes with two code paths that do the same thing, we should consolidate them. Conflicts: keystone/federation/controllers.py due to the fact that pre-Queens code used a different dependency framework. This was reworked in the Queens release, causing a conflict with this patch since it touches the same code. keystone/tests/unit/test_v3_auth.py due to a couple test with similar naming and placement within the same test module. Co-Authored-By: Kristi Nikolla <kristi@nikolla.me> Closes-Bug: 1779205 Change-Id: Ib906c42e1dd2c2408ccd2e256ffd876af02af3fe (cherry picked from commit df5d75571ed274b2964ed52048768c6d9f24d138)
-rw-r--r--keystone/federation/controllers.py19
-rw-r--r--keystone/tests/unit/test_v3_auth.py53
2 files changed, 57 insertions, 15 deletions
diff --git a/keystone/federation/controllers.py b/keystone/federation/controllers.py
index 6748ba1a1..67b434827 100644
--- a/keystone/federation/controllers.py
+++ b/keystone/federation/controllers.py
@@ -447,13 +447,8 @@ class DomainV3(controller.V3Controller):
:returns: list of accessible domains
"""
- domains = self.assignment_api.list_domains_for_groups(
- request.auth_context['group_ids'])
- domains = domains + self.assignment_api.list_domains_for_user(
- request.auth_context['user_id'])
- # remove duplicates
- domains = [dict(t) for t in set([tuple(d.items()) for d in domains])]
- return DomainV3.wrap_collection(request.context_dict, domains)
+ controller = auth_controllers.Auth()
+ return controller.get_auth_domains(request)
@dependency.requires('assignment_api', 'resource_api')
@@ -473,14 +468,8 @@ class ProjectAssignmentV3(controller.V3Controller):
:returns: list of accessible projects
"""
- projects = self.assignment_api.list_projects_for_groups(
- request.auth_context['group_ids'])
- projects = projects + self.assignment_api.list_projects_for_user(
- request.auth_context['user_id'])
- # remove duplicates
- projects = [dict(t) for t in set([tuple(d.items()) for d in projects])]
- return ProjectAssignmentV3.wrap_collection(request.context_dict,
- projects)
+ controller = auth_controllers.Auth()
+ return controller.get_auth_projects(request)
@dependency.requires('federation_api')
diff --git a/keystone/tests/unit/test_v3_auth.py b/keystone/tests/unit/test_v3_auth.py
index 0cd449229..11e30f732 100644
--- a/keystone/tests/unit/test_v3_auth.py
+++ b/keystone/tests/unit/test_v3_auth.py
@@ -5090,6 +5090,59 @@ class TestAuthSpecificData(test_v3.RestfulTestCase):
self.assertThat(r.json['domains'], matchers.HasLength(1))
self.assertValidDomainListResponse(r)
+ def test_get_projects_matches_federated_get_projects(self):
+ # create at least one addition project to make sure it doesn't end up
+ # in the response, since the user doesn't have any authorization on it
+ ref = unit.new_project_ref(domain_id=CONF.identity.default_domain_id)
+ r = self.post('/projects', body={'project': ref})
+ unauthorized_project_id = r.json['project']['id']
+
+ r = self.get('/auth/projects', expected_status=http_client.OK)
+ self.assertThat(r.json['projects'], matchers.HasLength(1))
+ for project in r.json['projects']:
+ self.assertNotEqual(unauthorized_project_id, project['id'])
+
+ expected_project_id = r.json['projects'][0]['id']
+
+ # call GET /v3/OS-FEDERATION/projects
+ r = self.get('/OS-FEDERATION/projects', expected_status=http_client.OK)
+
+ # make sure the response is the same
+ self.assertThat(r.json['projects'], matchers.HasLength(1))
+ for project in r.json['projects']:
+ self.assertEqual(expected_project_id, project['id'])
+
+ def test_get_domains_matches_federated_get_domains(self):
+ # create at least one addition domain to make sure it doesn't end up
+ # in the response, since the user doesn't have any authorization on it
+ ref = unit.new_domain_ref()
+ r = self.post('/domains', body={'domain': ref})
+ unauthorized_domain_id = r.json['domain']['id']
+
+ ref = unit.new_domain_ref()
+ r = self.post('/domains', body={'domain': ref})
+ authorized_domain_id = r.json['domain']['id']
+
+ path = '/domains/%(domain_id)s/users/%(user_id)s/roles/%(role_id)s' % {
+ 'domain_id': authorized_domain_id,
+ 'user_id': self.user_id,
+ 'role_id': self.role_id
+ }
+ self.put(path, expected_status=http_client.NO_CONTENT)
+
+ r = self.get('/auth/domains', expected_status=http_client.OK)
+ self.assertThat(r.json['domains'], matchers.HasLength(1))
+ self.assertEqual(authorized_domain_id, r.json['domains'][0]['id'])
+ self.assertNotEqual(unauthorized_domain_id, r.json['domains'][0]['id'])
+
+ # call GET /v3/OS-FEDERATION/domains
+ r = self.get('/OS-FEDERATION/domains', expected_status=http_client.OK)
+
+ # make sure the response is the same
+ self.assertThat(r.json['domains'], matchers.HasLength(1))
+ self.assertEqual(authorized_domain_id, r.json['domains'][0]['id'])
+ self.assertNotEqual(unauthorized_domain_id, r.json['domains'][0]['id'])
+
class TestTrustAuthFernetTokenProvider(TrustAPIBehavior, TestTrustChain):
def config_overrides(self):