def test_token_body(self): request = mock.Mock(method='POST', content_type='application/json', params={}, headers={}, json_body={'access': { 'token': 'test_token' }}) self.assertEqual(get_access_token(request=request), 'test_token')
def validate_credentials_generate(request): try: token = get_access_token(request) except ValueError: raise_operation_error(request, 'No access token was provided.') try: response = TendersClient( request.registry.api_token, host_url=request.registry.api_server, api_version=request.registry.api_version, ).extract_credentials(request.validated['monitoring'].tender_id) except ResourceNotFound: raise_operation_error( request, 'Tender {} not found'.format( request.validated['monitoring'].tender_id)) else: if sha512(token).hexdigest() != response['data']['tender_token']: raise forbidden(request)
def test_token_headers(self): self.assertEqual( get_access_token(request=mock.Mock( params={}, headers={'X-Access-Token': 'test_token'})), 'test_token')
def test_token_query_param(self): self.assertEqual( get_access_token(request=mock.Mock( params={'acc_token': 'test_token'})), 'test_token')