Merge "Add tests for domain users interacting with sps"

This commit is contained in:
Zuul 2019-01-25 16:26:46 +00:00 committed by Gerrit Code Review
commit d9897d9318

View File

@ -107,6 +107,79 @@ class _SystemReaderAndMemberUserServiceProviderTests(object):
)
class _DomainAndProjectUserServiceProviderTests(object):
"""Common functionality for all domain and project users."""
def test_user_cannot_create_service_providers(self):
service_provider = PROVIDERS.federation_api.create_sp(
uuid.uuid4().hex, unit.new_service_provider_ref()
)
service_provider = unit.new_service_provider_ref()
create = {'service_provider': service_provider}
with self.test_client() as c:
c.put(
'/v3/OS-FEDERATION/service_providers/%s' % uuid.uuid4().hex,
headers=self.headers,
json=create,
expected_status_code=http_client.FORBIDDEN
)
def test_user_cannot_update_service_providers(self):
service_provider = PROVIDERS.federation_api.create_sp(
uuid.uuid4().hex, unit.new_service_provider_ref()
)
update = {'service_provider': {'enabled': False}}
with self.test_client() as c:
c.patch(
'/v3/OS-FEDERATION/service_providers/%s' %
service_provider['id'],
headers=self.headers,
json=update,
expected_status_code=http_client.FORBIDDEN
)
def test_user_cannot_list_service_providers(self):
PROVIDERS.federation_api.create_sp(
uuid.uuid4().hex, unit.new_service_provider_ref()
)
with self.test_client() as c:
c.get(
'/v3/OS-FEDERATION/service_providers', headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
def test_user_cannot_get_a_service_provider(self):
service_provider = PROVIDERS.federation_api.create_sp(
uuid.uuid4().hex, unit.new_service_provider_ref()
)
with self.test_client() as c:
c.get(
'/v3/OS-FEDERATION/service_providers/%s' %
service_provider['id'],
headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
def test_user_cannot_delete_service_providers(self):
service_provider = PROVIDERS.federation_api.create_sp(
uuid.uuid4().hex, unit.new_service_provider_ref()
)
with self.test_client() as c:
c.delete(
'/v3/OS-FEDERATION/service_providers/%s' %
service_provider['id'],
headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
class SystemReaderTests(base_classes.TestCaseWithBootstrap,
common_auth.AuthTestMixin,
_SystemUserServiceProviderTests,
@ -243,3 +316,38 @@ class SystemAdminTests(base_classes.TestCaseWithBootstrap,
service_provider['id'],
headers=self.headers
)
class DomainUserTests(base_classes.TestCaseWithBootstrap,
common_auth.AuthTestMixin,
_DomainAndProjectUserServiceProviderTests):
def setUp(self):
super(DomainUserTests, self).setUp()
self.loadapp()
self.useFixture(ksfixtures.Policy(self.config_fixture))
self.config_fixture.config(group='oslo_policy', enforce_scope=True)
domain = PROVIDERS.resource_api.create_domain(
uuid.uuid4().hex, unit.new_domain_ref()
)
self.domain_id = domain['id']
domain_admin = unit.new_user_ref(domain_id=self.domain_id)
self.user_id = PROVIDERS.identity_api.create_user(domain_admin)['id']
PROVIDERS.assignment_api.create_grant(
self.bootstrapper.admin_role_id, user_id=self.user_id,
domain_id=self.domain_id
)
auth = self.build_authentication_request(
user_id=self.user_id,
password=domain_admin['password'],
domain_id=self.domain_id
)
# 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}