|
4 | 4 |
|
5 | 5 | from splunk_sdk import Context |
6 | 6 | from splunk_sdk.auth import TokenAuthManager |
7 | | -from splunk_sdk.auth.auth_manager import AuthnError |
| 7 | +from splunk_sdk.auth.auth_manager import AuthnError, RefreshTokenAuthManager |
8 | 8 | from splunk_sdk.base_client import BaseClient |
9 | 9 | from splunk_sdk.identity import Identity as IdentityAndAccessControl |
10 | 10 | from splunk_sdk.auth import PKCEAuthManager, ClientAuthManager |
@@ -34,6 +34,31 @@ def test_auth_error_properties(pkce_auth_manager): |
34 | 34 | finally: |
35 | 35 | pkce_auth_manager._password = save_passwd |
36 | 36 |
|
| 37 | +@pytest.mark.usefixtures('pkce_auth_manager') # NOQA |
| 38 | +def test_refresh_token_authenticate(pkce_auth_manager): |
| 39 | + auth_context = pkce_auth_manager.authenticate() |
| 40 | + |
| 41 | + # use existing token from auth_context |
| 42 | + refresh_token_mgr = RefreshTokenAuthManager(client_id=os.environ.get('SPLUNK_APP_CLIENT_ID'), |
| 43 | + refresh_token=auth_context.refresh_token, |
| 44 | + host=os.environ.get('SPLUNK_AUTH_HOST')) |
| 45 | + |
| 46 | + new_auth_context = refresh_token_mgr.authenticate() |
| 47 | + |
| 48 | + assert (new_auth_context.refresh_token is not None) |
| 49 | + assert (new_auth_context.access_token is not None) |
| 50 | + assert (new_auth_context.id_token is not None) |
| 51 | + assert (new_auth_context.token_type is not None) |
| 52 | + assert (new_auth_context.expires_in is not None) |
| 53 | + assert (new_auth_context.scope is not None) |
| 54 | + |
| 55 | +def test_error_refresh_token_authenticate(): |
| 56 | + refresh_token_mgr = RefreshTokenAuthManager(client_id=os.environ.get('SPLUNK_APP_CLIENT_ID'), |
| 57 | + refresh_token="refresh", |
| 58 | + host=os.environ.get('SPLUNK_AUTH_HOST')) |
| 59 | + |
| 60 | + with pytest.raises(AuthnError): |
| 61 | + refresh_token_mgr.authenticate() |
37 | 62 |
|
38 | 63 | @pytest.mark.usefixtures('client_auth_manager') # NOQA |
39 | 64 | def test_client_credentials_authenticate(client_auth_manager): |
|
0 commit comments