From 7e028774ac9ca1977acc2ef5ee134c5c44817dc6 Mon Sep 17 00:00:00 2001 From: Lance Bragstad Date: Wed, 21 Nov 2018 17:22:30 +0000 Subject: [PATCH] Add endpoint tests for system member role From keystone's perspective, the ``member`` and ``reader`` roles are effectively the same, isolating writable endpoint operations to the ``admin`` role. This commit adds explicit testing to make sure the ``member`` role is allowed to perform readable and not writable endpoint operations. Subsequent patches will incorporate: - system admin functionality - domains user test coverage - project user test coverage Change-Id: Ia8ccd808e3863bad5539f6d6ee9ae53e1036b24a Related-Bug: 1804482 Related-Bug: 1804483 --- .../unit/protection/v3/test_endpoints.py | 101 ++++++++++++------ 1 file changed, 70 insertions(+), 31 deletions(-) diff --git a/keystone/tests/unit/protection/v3/test_endpoints.py b/keystone/tests/unit/protection/v3/test_endpoints.py index b3b6fc8325..a08a7687d4 100644 --- a/keystone/tests/unit/protection/v3/test_endpoints.py +++ b/keystone/tests/unit/protection/v3/test_endpoints.py @@ -59,37 +59,8 @@ class _SystemUserEndpointTests(object): c.get('/v3/endpoints/%s' % endpoint['id'], headers=self.headers) -class SystemReaderTests(base_classes.TestCaseWithBootstrap, - common_auth.AuthTestMixin, - _SystemUserEndpointTests): - - def setUp(self): - super(SystemReaderTests, self).setUp() - self.loadapp() - self.useFixture(ksfixtures.Policy(self.config_fixture)) - self.config_fixture.config(group='oslo_policy', enforce_scope=True) - - system_reader = unit.new_user_ref( - domain_id=CONF.identity.default_domain_id - ) - self.user_id = PROVIDERS.identity_api.create_user( - system_reader - )['id'] - PROVIDERS.assignment_api.create_system_grant_for_user( - self.user_id, self.bootstrapper.reader_role_id - ) - - auth = self.build_authentication_request( - user_id=self.user_id, password=system_reader['password'], - system=True - ) - - # Grab a token using the persona we're testing and prepare headers - # for requests we'll be making in the tests. - with self.test_client() as c: - r = c.post('/v3/auth/tokens', json=auth) - self.token_id = r.headers['X-Subject-Token'] - self.headers = {'X-Auth-Token': self.token_id} +class _SystemReaderAndMemberUserEndpointTests(object): + """Common default functionality for system readers and system members.""" def test_user_cannot_create_endpoints(self): create = { @@ -138,3 +109,71 @@ class SystemReaderTests(base_classes.TestCaseWithBootstrap, '/v3/endpoints/%s' % endpoint['id'], headers=self.headers, expected_status_code=http_client.FORBIDDEN ) + + +class SystemReaderTests(base_classes.TestCaseWithBootstrap, + common_auth.AuthTestMixin, + _SystemUserEndpointTests, + _SystemReaderAndMemberUserEndpointTests): + + def setUp(self): + super(SystemReaderTests, self).setUp() + self.loadapp() + self.useFixture(ksfixtures.Policy(self.config_fixture)) + self.config_fixture.config(group='oslo_policy', enforce_scope=True) + + system_reader = unit.new_user_ref( + domain_id=CONF.identity.default_domain_id + ) + self.user_id = PROVIDERS.identity_api.create_user( + system_reader + )['id'] + PROVIDERS.assignment_api.create_system_grant_for_user( + self.user_id, self.bootstrapper.reader_role_id + ) + + auth = self.build_authentication_request( + user_id=self.user_id, password=system_reader['password'], + system=True + ) + + # Grab a token using the persona we're testing and prepare headers + # for requests we'll be making in the tests. + with self.test_client() as c: + r = c.post('/v3/auth/tokens', json=auth) + self.token_id = r.headers['X-Subject-Token'] + self.headers = {'X-Auth-Token': self.token_id} + + +class SystemMemberTests(base_classes.TestCaseWithBootstrap, + common_auth.AuthTestMixin, + _SystemUserEndpointTests, + _SystemReaderAndMemberUserEndpointTests): + + def setUp(self): + super(SystemMemberTests, self).setUp() + self.loadapp() + self.useFixture(ksfixtures.Policy(self.config_fixture)) + self.config_fixture.config(group='oslo_policy', enforce_scope=True) + + system_member = unit.new_user_ref( + domain_id=CONF.identity.default_domain_id + ) + self.user_id = PROVIDERS.identity_api.create_user( + system_member + )['id'] + PROVIDERS.assignment_api.create_system_grant_for_user( + self.user_id, self.bootstrapper.member_role_id + ) + + auth = self.build_authentication_request( + user_id=self.user_id, password=system_member['password'], + system=True + ) + + # Grab a token using the persona we're testing and prepare headers + # for requests we'll be making in the tests. + with self.test_client() as c: + r = c.post('/v3/auth/tokens', json=auth) + self.token_id = r.headers['X-Subject-Token'] + self.headers = {'X-Auth-Token': self.token_id}