def test_base_client_empty_hooks_with_pkce_auth(pkce_auth_manager): pkce_auth_manager.authenticate() context = Context(host=os.environ.get('SPLUNK_HOST'), api_host=os.environ.get('SPLUNK_HOST'), debug=os.environ.get('SPLUNK_DEBUG', 'false').lower().strip() == 'true') base_client = BaseClient(context=context, auth_manager=pkce_auth_manager, requests_hooks=[]) IdentityAndAccessControl(base_client).validate_token() assert True
def test_auth_error_properties(pkce_auth_manager): save_passwd = pkce_auth_manager._password pkce_auth_manager._password = '******' try: pkce_auth_manager.authenticate() except AuthnError as err: assert (err.status != "") assert (err.status is not None) assert (err.server_error_description != "") assert (err.server_error_description is not None) assert (err.request_id != "") assert (err.request_id is not None) finally: pkce_auth_manager._password = save_passwd
def test_base_client_hooks_with_pkce_auth(pkce_auth_manager): responses = [] def test_hook(response, **kwargs): responses.append(response) pkce_auth_manager.authenticate() context = Context(host=os.environ.get('SPLUNK_HOST'), api_host=os.environ.get('SPLUNK_HOST'), debug=os.environ.get('SPLUNK_DEBUG', 'false').lower().strip() == 'true') base_client = BaseClient(context=context, auth_manager=pkce_auth_manager, requests_hooks=[test_hook]) IdentityAndAccessControl(base_client).validate_token() assert len(responses) == 1 assert responses[0].status_code == 200
def test_token_authenticate(pkce_auth_manager): auth_context = pkce_auth_manager.authenticate() _assert_pkce_auth_context(auth_context) # use existing token from auth_context token_mgr = TokenAuthManager(access_token=auth_context.access_token, token_type=auth_context.token_type, expires_in=auth_context.expires_in, scope=auth_context.scope, id_token=auth_context.id_token, refresh_token=auth_context.refresh_token) new_auth_context = token_mgr.authenticate() assert (auth_context.access_token == new_auth_context.access_token) assert (auth_context.token_type == new_auth_context.token_type) assert (auth_context.expires_in == new_auth_context.expires_in) assert (auth_context.scope == new_auth_context.scope) assert (auth_context.id_token == new_auth_context.id_token) assert (auth_context.refresh_token == new_auth_context.refresh_token)
def test_pkce_authenticate(pkce_auth_manager): auth_context = pkce_auth_manager.authenticate() _assert_pkce_auth_context(auth_context)