Browse Source

Update system grant policies for system member

This commit ensures users with the ``member`` role on the system can
perform read-only operations against the system assignment API.

 - system admin functionality
 - domain user test coverage
 - project user test coverage

Change-Id: I834475da2343ba87fb169689f71d4cb4713f6786
Related-Bug: 1805368
Related-Bug: 1750669
Related-Bug: 1806762
(cherry picked from commit bb4192e88d)
changes/74/647674/1
Lance Bragstad 3 years ago
committed by Colleen Murphy
parent
commit
0786fde393
  1. 92
      keystone/tests/unit/protection/v3/test_system_assignments.py

92
keystone/tests/unit/protection/v3/test_system_assignments.py

@ -61,9 +61,43 @@ class _SystemUserSystemAssignmentTests(object):
)
class _SystemMemberAndReaderSystemAssignmentTests(object):
def test_user_cannot_grant_system_assignments(self):
user = PROVIDERS.identity_api.create_user(
unit.new_user_ref(CONF.identity.default_domain_id)
)
with self.test_client() as c:
c.put(
'/v3/system/users/%s/roles/%s' % (
user['id'], self.bootstrapper.member_role_id
), headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
def test_user_cannot_revoke_system_assignments(self):
user = PROVIDERS.identity_api.create_user(
unit.new_user_ref(CONF.identity.default_domain_id)
)
PROVIDERS.assignment_api.create_system_grant_for_user(
user['id'], self.bootstrapper.member_role_id
)
with self.test_client() as c:
c.delete(
'/v3/system/users/%s/roles/%s' % (
user['id'], self.bootstrapper.member_role_id
), headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
class SystemReaderTests(base_classes.TestCaseWithBootstrap,
common_auth.AuthTestMixin,
_SystemUserSystemAssignmentTests):
_SystemUserSystemAssignmentTests,
_SystemMemberAndReaderSystemAssignmentTests):
def setUp(self):
super(SystemReaderTests, self).setUp()
@ -93,32 +127,44 @@ class SystemReaderTests(base_classes.TestCaseWithBootstrap,
self.token_id = r.headers['X-Subject-Token']
self.headers = {'X-Auth-Token': self.token_id}
def test_user_cannot_grant_system_assignments(self):
user = PROVIDERS.identity_api.create_user(
unit.new_user_ref(CONF.identity.default_domain_id)
)
with self.test_client() as c:
c.put(
'/v3/system/users/%s/roles/%s' % (
user['id'], self.bootstrapper.member_role_id
), headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
class SystemMemberTests(base_classes.TestCaseWithBootstrap,
common_auth.AuthTestMixin,
_SystemUserSystemAssignmentTests,
_SystemMemberAndReaderSystemAssignmentTests):
def test_user_cannot_revoke_system_assignments(self):
user = PROVIDERS.identity_api.create_user(
unit.new_user_ref(CONF.identity.default_domain_id)
)
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(
user['id'], self.bootstrapper.member_role_id
self.user_id, self.bootstrapper.member_role_id
)
self.expected = [
# assignment of the user running the test case
{
'user_id': self.user_id,
'system': 'all',
'role_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:
c.delete(
'/v3/system/users/%s/roles/%s' % (
user['id'], self.bootstrapper.member_role_id
), headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
r = c.post('/v3/auth/tokens', json=auth)
self.token_id = r.headers['X-Subject-Token']
self.headers = {'X-Auth-Token': self.token_id}
Loading…
Cancel
Save