How to use get_access_token_role method in tempest

Best Python code snippet using tempest_python

test_oauth_tokens_rbac.py

Source:test_oauth_tokens_rbac.py Github

copy

Full Screen

...82 access_token)83 @rbac_rule_validation.action(service="keystone",84 rules=["identity:get_access_token_role"])85 @decorators.idempotent_id('0f148510-63bf-11e6-4522-080044d0d980')86 def test_get_access_token_role(self):87 access_token = self._create_access_token()88 with self.override_role():89 self.oauth_token_client.get_access_token_role(90 self.user_id, access_token, self.role_ids[0])91 @rbac_rule_validation.action(service="keystone",92 rules=["identity:list_access_tokens"])93 @decorators.idempotent_id('0f148510-63bf-11e6-4522-080044d0d979')94 def test_list_access_tokens(self):95 with self.override_role():96 self.oauth_token_client.list_access_tokens(self.user_id)97 @rbac_rule_validation.action(service="keystone",98 rules=["identity:list_access_token_roles"])99 @decorators.idempotent_id('0f148510-63bf-11e6-4522-080044d0d978')100 def test_list_access_token_roles(self):101 access_token = self._create_access_token()102 with self.override_role():103 self.oauth_token_client.list_access_token_roles(...

Full Screen

Full Screen

access_tokens.py

Source:access_tokens.py Github

copy

Full Screen

...27 if is_valid_token(token):28 payload = jwt.decode(token.encode(), ACCESS_TOKEN_SECRET, algorithms='HS256')29 return payload.get('provider')30 return None31def get_access_token_role(token):32 if is_valid_token(token):33 payload = jwt.decode(token.encode(), ACCESS_TOKEN_SECRET, algorithms='HS256')34 return 'admin' if payload.get('email') in ADMIN_EMAILS else 'user'35 return None36def access_token_scopes(token):37 # The scope is computed based on the token's role, so that tokens stay38 # valid if the role -> scope map changes.39 scope = []40 if is_valid_token(token):41 payload = jwt.decode(token.encode(), ACCESS_TOKEN_SECRET, algorithms='HS256')42 app = None43 if 'client_id' in payload:44 app = db.App.objects(client_id=payload['client_id']).first()45 if not app and OAUTH_REQUIRES_CLIENT_ID:46 pass # return scope47 role = get_access_token_role(token)48 if app and 'admin:*' not in app.scopes:49 pass # role == 'user'50 scope = ADMIN_USER_CLAIMS if role == 'admin' else AUTHENTICATED_USER_CLAIMS51 return scope52def is_valid_token(token):53 if not token:54 return False55 try:56 jwt.decode(token.encode(), ACCESS_TOKEN_SECRET, algorithms='HS256') # for effect57 except Exception:58 return False...

Full Screen

Full Screen

user_resources.py

Source:user_resources.py Github

copy

Full Screen

...40 return {41 'authenticated': bool(access_token),42 'inside_intranet': request_is_from_inside_intranet(request),43 'provider': get_access_token_provider(access_token),44 'role': get_access_token_role(access_token),45 'scope': access_token_scopes(access_token),46 }...

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