How to use check_token_existence method in tempest

Best Python code snippet using tempest_python

test_token.py

Source:test_token.py Github

copy

Full Screen

1# Copyright 2020 SUSE LLC2#3# Licensed under the Apache License, Version 2.0 (the "License"); you may4# not use this file except in compliance with the License. You may obtain5# a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the12# License for the specific language governing permissions and limitations13# under the License.14import abc15from tempest.api.identity import base16from tempest import clients17from tempest.lib import auth18from tempest.lib.common.utils import data_utils19from tempest.lib import exceptions20from keystone_tempest_plugin.tests.rbac.v3 import base as rbac_base21class IdentityV3RbacTokenTest(rbac_base.IdentityV3RbacBaseTests,22 metaclass=abc.ABCMeta):23 @classmethod24 def setup_clients(cls):25 super(IdentityV3RbacTokenTest, cls).setup_clients()26 cls.persona = getattr(cls, 'os_%s' % cls.credentials[0])27 cls.client = cls.persona.identity_v3_client28 @classmethod29 def resource_setup(cls):30 admin_client = cls.os_system_admin31 cls.user = {32 'name': data_utils.rand_name('user'),33 'password': data_utils.rand_password(),34 }35 cls.user_id = admin_client.users_v3_client.create_user(36 **cls.user)['user']['id']37 cls.addClassResourceCleanup(38 admin_client.users_v3_client.delete_user, user_id=cls.user_id)39 cls.project_id = admin_client.projects_client.create_project(40 name=data_utils.rand_name()41 )['project']['id']42 cls.addClassResourceCleanup(43 admin_client.projects_client.delete_project,44 project_id=cls.project_id)45 cls.domain_id = admin_client.domains_client.create_domain(46 name=data_utils.rand_name()47 )['domain']['id']48 cls.addClassResourceCleanup(49 admin_client.domains_client.delete_domain,50 domain_id=cls.domain_id)51 cls.addClassResourceCleanup(52 admin_client.domains_client.update_domain,53 domain_id=cls.domain_id, enabled=False)54 role_id = admin_client.roles_v3_client.create_role(55 name=data_utils.rand_name())['role']['id']56 cls.addClassResourceCleanup(57 admin_client.roles_v3_client.delete_role,58 role_id=role_id)59 admin_client.roles_v3_client.create_user_role_on_project(60 project_id=cls.project_id,61 user_id=cls.user_id,62 role_id=role_id63 )64 admin_client.roles_v3_client.create_user_role_on_domain(65 domain_id=cls.domain_id,66 user_id=cls.user_id,67 role_id=role_id68 )69 admin_client.roles_v3_client.create_user_role_on_system(70 user_id=cls.user_id,71 role_id=role_id72 )73 def setUp(self):74 super(IdentityV3RbacTokenTest, self).setUp()75 own_creds = auth.KeystoneV3Credentials(**self.own_keystone_creds)76 own_creds = clients.get_auth_provider(own_creds).fill_credentials()77 self.own_token = clients.Manager(78 credentials=own_creds).identity_v3_client.token79 project_creds = auth.KeystoneV3Credentials(80 user_id=self.user_id,81 password=self.user['password'],82 project_id=self.project_id)83 project_creds = clients.get_auth_provider(84 project_creds).fill_credentials()85 self.project_token = clients.Manager(86 credentials=project_creds).identity_v3_client.token87 domain_creds = auth.KeystoneV3Credentials(88 user_id=self.user_id,89 password=self.user['password'],90 domain_id=self.domain_id)91 domain_creds = clients.get_auth_provider(92 domain_creds).fill_credentials()93 self.domain_token = clients.Manager(94 credentials=domain_creds).identity_v3_client.token95 system_creds = auth.KeystoneV3Credentials(96 user_id=self.user_id,97 password=self.user['password'],98 system='all')99 system_creds = clients.get_auth_provider(100 system_creds).fill_credentials()101 self.system_token = clients.Manager(102 credentials=system_creds).identity_v3_client.token103 @abc.abstractmethod104 def test_identity_check_token(self):105 """Test identity:check_token policy.106 This test must check:107 * whether the persona can check their own token in their current108 scope109 * whether the persona can check a system-scoped token for a different110 user111 * whether the persona can check a domain-scoped token for a different112 user113 * whether the persona can check a project-scoped token for a114 different user115 """116 pass117 @abc.abstractmethod118 def test_identity_validate_token(self):119 """Test identity:validate_token policy.120 This test must validate:121 * whether the persona can validate their own token in their current122 scope123 * whether the persona can validate a system-scoped token for a124 different user125 * whether the persona can validate a domain-scoped token for a126 different user127 * whether the persona can validate a project-scoped token for a128 different user129 """130 pass131 @abc.abstractmethod132 def test_identity_revoke_token(self):133 """Test identity:revoke_token policy.134 This test must revoke:135 * whether the persona can revoke their own token in their current136 scope137 * whether the persona can revoke a system-scoped token for a138 different user139 * whether the persona can revoke a domain-scoped token for a140 different user141 * whether the persona can revoke a project-scoped token for a142 different user143 """144 pass145class SystemAdminTests(IdentityV3RbacTokenTest, base.BaseIdentityTest):146 credentials = ['system_admin']147 def setUp(self):148 self.own_keystone_creds = {149 'user_id': self.persona.credentials.user_id,150 'password': self.persona.credentials.password,151 'system': 'all'152 }153 super(SystemAdminTests, self).setUp()154 def test_identity_check_token(self):155 # user can check own token156 self.do_request('check_token_existence', resp_token=self.own_token)157 # user can check other system user's token158 self.do_request('check_token_existence', resp_token=self.system_token)159 # user can check domain user's token160 self.do_request('check_token_existence', resp_token=self.domain_token)161 # user can check project user's token162 self.do_request('check_token_existence', resp_token=self.project_token)163 def test_identity_validate_token(self):164 # user can validate own token165 self.do_request('show_token', resp_token=self.own_token)166 # user can validate other system user's token167 self.do_request('show_token', resp_token=self.system_token)168 # user can validate domain user's token169 self.do_request('show_token', resp_token=self.domain_token)170 # user can validate project user's token171 self.do_request('show_token', resp_token=self.project_token)172 def test_identity_revoke_token(self):173 # user can revoke own token174 self.do_request('delete_token', expected_status=204,175 resp_token=self.own_token)176 # user can revoke other system user's token177 self.do_request('delete_token', expected_status=204,178 resp_token=self.system_token)179 # user can revoke domain user's token180 self.do_request('delete_token', expected_status=204,181 resp_token=self.domain_token)182 # user can revoke project user's token183 self.do_request('delete_token', expected_status=204,184 resp_token=self.project_token)185class SystemMemberTests(SystemAdminTests):186 credentials = ['system_member', 'system_admin']187 def test_identity_revoke_token(self):188 # user can revoke own token189 self.do_request('delete_token', expected_status=204,190 resp_token=self.own_token)191 # user cannot revoke other system user's token192 self.do_request('delete_token', expected_status=exceptions.Forbidden,193 resp_token=self.system_token)194 # user cannot revoke domain user's token195 self.do_request('delete_token', expected_status=exceptions.Forbidden,196 resp_token=self.domain_token)197 # user cannot revoke project user's token198 self.do_request('delete_token', expected_status=exceptions.Forbidden,199 resp_token=self.project_token)200class SystemReaderTests(SystemMemberTests):201 credentials = ['system_reader', 'system_admin']202class DomainAdminTests(SystemReaderTests, base.BaseIdentityTest):203 credentials = ['domain_admin', 'system_admin']204 def setUp(self):205 self.own_keystone_creds = {206 'user_id': self.persona.credentials.user_id,207 'password': self.persona.credentials.password,208 'domain_id': self.persona.credentials.domain_id209 }210 # call base setUp directly to ensure we don't use system creds211 super(SystemAdminTests, self).setUp()212 def test_identity_check_token(self):213 # user can check own token214 self.do_request('check_token_existence', resp_token=self.own_token)215 # user cannot check other system user's token216 self.do_request('check_token_existence',217 expected_status=exceptions.Forbidden,218 resp_token=self.system_token)219 # user cannot check domain user's token220 self.do_request('check_token_existence',221 expected_status=exceptions.Forbidden,222 resp_token=self.domain_token)223 # user cannot check project user's token224 self.do_request('check_token_existence',225 expected_status=exceptions.Forbidden,226 resp_token=self.project_token)227 def test_identity_validate_token(self):228 # user can validate own token229 self.do_request('show_token', resp_token=self.own_token)230 # user cannot validate other system user's token231 self.do_request('show_token',232 expected_status=exceptions.Forbidden,233 resp_token=self.system_token)234 # user cannot validate domain user's token235 self.do_request('show_token',236 expected_status=exceptions.Forbidden,237 resp_token=self.domain_token)238 # user cannot validate project user's token239 self.do_request('show_token',240 expected_status=exceptions.Forbidden,241 resp_token=self.project_token)242class DomainMemberTests(DomainAdminTests):243 credentials = ['domain_member', 'system_admin']244class DomainReaderTests(DomainAdminTests):245 credentials = ['domain_reader', 'system_admin']246class ProjectAdminTests(DomainAdminTests, base.BaseIdentityTest):247 credentials = ['project_admin', 'system_admin']248 def setUp(self):249 self.own_keystone_creds = {250 'user_id': self.persona.credentials.user_id,251 'password': self.persona.credentials.password,252 'project_id': self.persona.credentials.project_id253 }254 # call base setUp directly to ensure we don't use system creds255 super(SystemAdminTests, self).setUp()256class ProjectMemberTests(ProjectAdminTests):257 credentials = ['project_member', 'system_admin']258class ProjectReaderTests(ProjectAdminTests):...

Full Screen

Full Screen

write_to_chat.py

Source:write_to_chat.py Github

copy

Full Screen

...22 parser.add('message', help='Choose username for registration.')23 parser.add('--host', help='Host for connection.', default=SENDING_HOST, env_var='SENDING_HOST')24 parser.add('--port', help='Port for connection.', default=SENDING_PORT, env_var='SENDING_PORT')25 auth_args = parser.add_mutually_exclusive_group()26 auth_args.add('--minechat_token', help='Authorization token.', default=check_token_existence(), env_var='MINECHAT_TOKEN')27 auth_args.add('--username', help='Choose username for registration.')28 return parser.parse_args()29if __name__ == '__main__':30 logging.basicConfig(level=logging.DEBUG)31 options = get_application_options()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful