diff --git a/keystone/tests/unit/protection/v3/test_protocols.py b/keystone/tests/unit/protection/v3/test_protocols.py index d836376131..78e0c28220 100644 --- a/keystone/tests/unit/protection/v3/test_protocols.py +++ b/keystone/tests/unit/protection/v3/test_protocols.py @@ -25,36 +25,7 @@ CONF = keystone.conf.CONF PROVIDERS = provider_api.ProviderAPIs -class SystemReaderTests(base_classes.TestCaseWithBootstrap, - common_auth.AuthTestMixin): - - def setUp(self): - super(SystemReaderTests, self).setUp() - self.loadapp() - self.useFixture(ksfixtures.Policy(self.config_fixture)) - self.config_fixture.config(group='oslo_policy', enforce_scope=True) - - system_reader = unit.new_user_ref( - domain_id=CONF.identity.default_domain_id - ) - self.user_id = PROVIDERS.identity_api.create_user( - system_reader - )['id'] - PROVIDERS.assignment_api.create_system_grant_for_user( - self.user_id, self.bootstrapper.reader_role_id - ) - - auth = self.build_authentication_request( - user_id=self.user_id, password=system_reader['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: - r = c.post('/v3/auth/tokens', json=auth) - self.token_id = r.headers['X-Subject-Token'] - self.headers = {'X-Auth-Token': self.token_id} +class _CommonUtilities(object): def _create_protocol_and_deps(self): identity_provider = unit.new_identity_provider_ref() @@ -71,6 +42,9 @@ class SystemReaderTests(base_classes.TestCaseWithBootstrap, ) return (protocol, mapping, identity_provider) + +class _SystemReaderAndMemberProtocolTests(object): + def test_user_cannot_create_protocols(self): identity_provider = unit.new_identity_provider_ref() identity_provider = PROVIDERS.federation_api.create_idp( @@ -146,3 +120,71 @@ class SystemReaderTests(base_classes.TestCaseWithBootstrap, path, headers=self.headers, expected_status_code=http_client.FORBIDDEN ) + + +class SystemReaderTests(base_classes.TestCaseWithBootstrap, + common_auth.AuthTestMixin, + _CommonUtilities, + _SystemReaderAndMemberProtocolTests): + + def setUp(self): + super(SystemReaderTests, self).setUp() + self.loadapp() + self.useFixture(ksfixtures.Policy(self.config_fixture)) + self.config_fixture.config(group='oslo_policy', enforce_scope=True) + + system_reader = unit.new_user_ref( + domain_id=CONF.identity.default_domain_id + ) + self.user_id = PROVIDERS.identity_api.create_user( + system_reader + )['id'] + PROVIDERS.assignment_api.create_system_grant_for_user( + self.user_id, self.bootstrapper.reader_role_id + ) + + auth = self.build_authentication_request( + user_id=self.user_id, password=system_reader['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: + r = c.post('/v3/auth/tokens', json=auth) + self.token_id = r.headers['X-Subject-Token'] + self.headers = {'X-Auth-Token': self.token_id} + + +class SystemMemberTests(base_classes.TestCaseWithBootstrap, + common_auth.AuthTestMixin, + _CommonUtilities, + _SystemReaderAndMemberProtocolTests): + + 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( + self.user_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: + r = c.post('/v3/auth/tokens', json=auth) + self.token_id = r.headers['X-Subject-Token'] + self.headers = {'X-Auth-Token': self.token_id}