Browse Source

Add idp tests for system member role

From keystone's perspective, the ``member`` and ``reader`` roles are
effectively the same, isolating writable idp operations to the
``admin`` role.

This commit adds explicit testing to make sure the ``member`` role is
allowed to perform readable and not writable idp operations.
Subsequent patches will incorporate:

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

 Related-Bug: 1804517
 Related-Bug: 1804516

Change-Id: Ib738c18380f567d0a0b24e218350c9e1cd33691f
tags/15.0.0.0rc1
Lance Bragstad 1 year ago
parent
commit
c347c4ff2f
1 changed files with 68 additions and 29 deletions
  1. +68
    -29
      keystone/tests/unit/protection/v3/test_identity_providers.py

+ 68
- 29
keystone/tests/unit/protection/v3/test_identity_providers.py View File

@@ -55,9 +55,50 @@ class _SystemUserIdentityProviderTests(object):
)


class _SystemReaderAndMemberIdentityProviderTests(object):
"""Common default functionality for system readers and system members."""

def test_user_cannot_create_identity_providers(self):
create = {'identity_provider': {'remote_ids': [uuid.uuid4().hex]}}

with self.test_client() as c:
c.put(
'/v3/OS-FEDERATION/identity_providers/%s' % uuid.uuid4().hex,
json=create, headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)

def test_user_cannot_update_identity_providers(self):
idp = PROVIDERS.federation_api.create_idp(
uuid.uuid4().hex, unit.new_identity_provider_ref()
)

update = {'identity_provider': {'enabled': False}}

with self.test_client() as c:
c.patch(
'/v3/OS-FEDERATION/identity_providers/%s' % idp['id'],
json=update, headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)

def test_user_cannot_delete_identity_providers(self):
idp = PROVIDERS.federation_api.create_idp(
uuid.uuid4().hex, unit.new_identity_provider_ref()
)

with self.test_client() as c:
c.delete(
'/v3/OS-FEDERATION/identity_providers/%s' % idp['id'],
headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)


class SystemReaderTests(base_classes.TestCaseWithBootstrap,
common_auth.AuthTestMixin,
_SystemUserIdentityProviderTests):
_SystemUserIdentityProviderTests,
_SystemReaderAndMemberIdentityProviderTests):

def setUp(self):
super(SystemReaderTests, self).setUp()
@@ -87,38 +128,36 @@ 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_create_identity_providers(self):
create = {'identity_provider': {'remote_ids': [uuid.uuid4().hex]}}

with self.test_client() as c:
c.put(
'/v3/OS-FEDERATION/identity_providers/%s' % uuid.uuid4().hex,
json=create, headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)

def test_user_cannot_update_identity_providers(self):
idp = PROVIDERS.federation_api.create_idp(
uuid.uuid4().hex, unit.new_identity_provider_ref()
)
class SystemMemberTests(base_classes.TestCaseWithBootstrap,
common_auth.AuthTestMixin,
_SystemUserIdentityProviderTests,
_SystemReaderAndMemberIdentityProviderTests):

update = {'identity_provider': {'enabled': False}}
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)

with self.test_client() as c:
c.patch(
'/v3/OS-FEDERATION/identity_providers/%s' % idp['id'],
json=update, headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
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
)

def test_user_cannot_delete_identity_providers(self):
idp = PROVIDERS.federation_api.create_idp(
uuid.uuid4().hex, unit.new_identity_provider_ref()
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/OS-FEDERATION/identity_providers/%s' % idp['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