How to use _generate_oauth_header method in tempest

Best Python code snippet using tempest_python

oauth_token_client.py

Source:oauth_token_client.py Github

copy

Full Screen

...82 signature = hmac.new(key_utf8, text_utf8, hashlib.sha1)83 sig = binascii.b2a_base64(signature.digest())[:-1].decode('utf-8')84 oauth_params.append(('oauth_signature', sig))85 return oauth_params86 def _generate_oauth_header(self, oauth_params):87 authorization_header = {}88 authorization_header_parameters_parts = []89 for oauth_parameter_name, value in oauth_params:90 escaped_name = self._escape(oauth_parameter_name)91 escaped_value = self._escape(value)92 part = '{0}="{1}"'.format(escaped_name, escaped_value)93 authorization_header_parameters_parts.append(part)94 authorization_header_parameters = ', '.join(95 authorization_header_parameters_parts)96 oauth_string = 'OAuth %s' % authorization_header_parameters97 authorization_header['Authorization'] = oauth_string98 return authorization_header99 def create_request_token(self, consumer_key, consumer_secret, project_id):100 """Create request token.101 For more information, please refer to the official API reference:102 https://docs.openstack.org/api-ref/identity/v3-ext/#create-request-token103 """104 endpoint = 'OS-OAUTH1/request_token'105 headers = {'Requested-Project-Id': project_id}106 oauth_params = self._generate_params_with_signature(107 consumer_key,108 self.base_url + '/' + endpoint,109 client_secret=consumer_secret,110 callback_uri='oob',111 http_method='POST')112 oauth_header = self._generate_oauth_header(oauth_params)113 headers.update(oauth_header)114 resp, body = self.post(endpoint,115 body=None,116 headers=headers)117 self.expected_success(201, resp.status)118 if not isinstance(body, str):119 body = body.decode('utf-8')120 body = dict(item.split("=") for item in body.split("&"))121 return rest_client.ResponseBody(resp, body)122 def authorize_request_token(self, request_token_id, role_ids):123 """Authorize request token.124 For more information, please refer to the official API reference:125 https://docs.openstack.org/api-ref/identity/v3-ext/#authorize-request-token126 """127 roles = [{'id': role_id} for role_id in role_ids]128 body = {'roles': roles}129 post_body = json.dumps(body)130 resp, body = self.put("OS-OAUTH1/authorize/%s" % request_token_id,131 post_body)132 self.expected_success(200, resp.status)133 body = json.loads(body)134 return rest_client.ResponseBody(resp, body)135 def create_access_token(self, consumer_key, consumer_secret, request_key,136 request_secret, oauth_verifier):137 """Create access token.138 For more information, please refer to the official API reference:139 https://docs.openstack.org/api-ref/identity/v3-ext/#create-access-token140 """141 endpoint = 'OS-OAUTH1/access_token'142 oauth_params = self._generate_params_with_signature(143 consumer_key,144 self.base_url + '/' + endpoint,145 client_secret=consumer_secret,146 resource_owner_key=request_key,147 resource_owner_secret=request_secret,148 verifier=oauth_verifier,149 http_method='POST')150 headers = self._generate_oauth_header(oauth_params)151 resp, body = self.post(endpoint, body=None, headers=headers)152 self.expected_success(201, resp.status)153 if not isinstance(body, str):154 body = body.decode('utf-8')155 body = dict(item.split("=") for item in body.split("&"))156 return rest_client.ResponseBody(resp, body)157 def get_access_token(self, user_id, access_token_id):158 """Get access token.159 For more information, please refer to the official API reference:160 https://docs.openstack.org/api-ref/identity/v3-ext/#get-access-token161 """162 resp, body = self.get("users/%s/OS-OAUTH1/access_tokens/%s"163 % (user_id, access_token_id))164 self.expected_success(200, resp.status)...

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