Add tests for domain users interacting with endpoints
This commit introduces some tests that show how domain users are expected to behave with the endpoints API. A subsequent patch will do the same for project users. Change-Id: If3186c6fc1cba68426eedf83f31ae87cbe2060da Related-Bug: 1804482
This commit is contained in:
@@ -111,6 +111,90 @@ class _SystemReaderAndMemberUserEndpointTests(object):
|
||||
)
|
||||
|
||||
|
||||
class _DomainAndProjectUserEndpointTests(object):
|
||||
|
||||
def test_user_cannot_create_endpoints(self):
|
||||
create = {
|
||||
'endpoint': {
|
||||
'interface': 'public',
|
||||
'service_id': uuid.uuid4().hex,
|
||||
'url': 'https://' + uuid.uuid4().hex + '.com'
|
||||
}
|
||||
}
|
||||
|
||||
with self.test_client() as c:
|
||||
c.post(
|
||||
'/v3/endpoints', json=create, headers=self.headers,
|
||||
expected_status_code=http_client.FORBIDDEN
|
||||
)
|
||||
|
||||
def test_user_cannot_list_endpoints(self):
|
||||
# Domain and project users should access this information through the
|
||||
# token response they get when they authenticate for or validate a
|
||||
# token.
|
||||
service = PROVIDERS.catalog_api.create_service(
|
||||
uuid.uuid4().hex, unit.new_service_ref()
|
||||
)
|
||||
endpoint = unit.new_endpoint_ref(service['id'], region_id=None)
|
||||
endpoint = PROVIDERS.catalog_api.create_endpoint(
|
||||
endpoint['id'], endpoint
|
||||
)
|
||||
|
||||
with self.test_client() as c:
|
||||
c.get(
|
||||
'/v3/endpoints', headers=self.headers,
|
||||
expected_status_code=http_client.FORBIDDEN
|
||||
)
|
||||
|
||||
def test_user_cannot_get_an_endpoint(self):
|
||||
service = PROVIDERS.catalog_api.create_service(
|
||||
uuid.uuid4().hex, unit.new_service_ref()
|
||||
)
|
||||
endpoint = unit.new_endpoint_ref(service['id'], region_id=None)
|
||||
endpoint = PROVIDERS.catalog_api.create_endpoint(
|
||||
endpoint['id'], endpoint
|
||||
)
|
||||
|
||||
with self.test_client() as c:
|
||||
c.get(
|
||||
'/v3/endpoints/%s' % endpoint['id'], headers=self.headers,
|
||||
expected_status_code=http_client.FORBIDDEN
|
||||
)
|
||||
|
||||
def test_user_cannot_update_endpoints(self):
|
||||
service = PROVIDERS.catalog_api.create_service(
|
||||
uuid.uuid4().hex, unit.new_service_ref()
|
||||
)
|
||||
endpoint = unit.new_endpoint_ref(service['id'], region_id=None)
|
||||
endpoint = PROVIDERS.catalog_api.create_endpoint(
|
||||
endpoint['id'], endpoint
|
||||
)
|
||||
|
||||
update = {'endpoint': {'interface': 'internal'}}
|
||||
|
||||
with self.test_client() as c:
|
||||
c.patch(
|
||||
'/v3/endpoints/%s' % endpoint['id'], json=update,
|
||||
headers=self.headers,
|
||||
expected_status_code=http_client.FORBIDDEN
|
||||
)
|
||||
|
||||
def test_user_cannot_delete_endpoints(self):
|
||||
service = PROVIDERS.catalog_api.create_service(
|
||||
uuid.uuid4().hex, unit.new_service_ref()
|
||||
)
|
||||
endpoint = unit.new_endpoint_ref(service['id'], region_id=None)
|
||||
endpoint = PROVIDERS.catalog_api.create_endpoint(
|
||||
endpoint['id'], endpoint
|
||||
)
|
||||
|
||||
with self.test_client() as c:
|
||||
c.delete(
|
||||
'/v3/endpoints/%s' % endpoint['id'], headers=self.headers,
|
||||
expected_status_code=http_client.FORBIDDEN
|
||||
)
|
||||
|
||||
|
||||
class SystemReaderTests(base_classes.TestCaseWithBootstrap,
|
||||
common_auth.AuthTestMixin,
|
||||
_SystemUserEndpointTests,
|
||||
@@ -250,3 +334,38 @@ class SystemAdminTests(base_classes.TestCaseWithBootstrap,
|
||||
c.delete(
|
||||
'/v3/endpoints/%s' % endpoint['id'], headers=self.headers,
|
||||
)
|
||||
|
||||
|
||||
class DomainUserTests(base_classes.TestCaseWithBootstrap,
|
||||
common_auth.AuthTestMixin,
|
||||
_DomainAndProjectUserEndpointTests):
|
||||
|
||||
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}
|
||||
|
||||
Reference in New Issue
Block a user