Merge "Add tests for domain users interacting with services"

This commit is contained in:
Zuul 2019-02-27 18:33:44 +00:00 committed by Gerrit Code Review
commit a4fa5bac5d
1 changed files with 95 additions and 0 deletions

View File

@ -95,6 +95,66 @@ class _SystemReaderAndMemberUserServiceTests(object):
)
class _DomainAndProjectUserServiceTests(object):
def test_user_cannot_create_services(self):
create = {
'service': {
'type': uuid.uuid4().hex,
'name': uuid.uuid4().hex,
}
}
with self.test_client() as c:
c.post(
'/v3/services', json=create, headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
def test_user_cannot_list_services(self):
service = unit.new_service_ref()
PROVIDERS.catalog_api.create_service(service['id'], service)
with self.test_client() as c:
c.get(
'/v3/services', headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
def test_user_cannot_get_a_service(self):
service = unit.new_service_ref()
service = PROVIDERS.catalog_api.create_service(service['id'], service)
with self.test_client() as c:
c.get(
'/v3/services/%s' % service['id'], headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
def test_user_cannot_update_services(self):
service = unit.new_service_ref()
service = PROVIDERS.catalog_api.create_service(service['id'], service)
update = {'service': {'description': uuid.uuid4().hex}}
with self.test_client() as c:
c.patch(
'/v3/services/%s' % service['id'], json=update,
headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
def test_user_cannot_delete_services(self):
service = unit.new_service_ref()
service = PROVIDERS.catalog_api.create_service(service['id'], service)
with self.test_client() as c:
c.delete(
'/v3/services/%s' % service['id'], headers=self.headers,
expected_status_code=http_client.FORBIDDEN
)
class SystemReaderTests(base_classes.TestCaseWithBootstrap,
common_auth.AuthTestMixin,
_SystemUserServiceTests,
@ -218,3 +278,38 @@ class SystemAdminTests(base_classes.TestCaseWithBootstrap,
with self.test_client() as c:
c.delete('/v3/services/%s' % service['id'], headers=self.headers)
class DomainUserTests(base_classes.TestCaseWithBootstrap,
common_auth.AuthTestMixin,
_DomainAndProjectUserServiceTests):
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}