22import tests .mocks as mocks
33import os
44import pytest
5+ from unittest .mock import AsyncMock , MagicMock
6+ from okta .oauth import OAuth
57
68"""
79Testing Private Key Inputs
@@ -39,3 +41,54 @@ def test_private_key_PEM_JWK_explicit_string():
3941def test_invalid_private_key_PEM_JWK (private_key ):
4042 with pytest .raises (ValueError ):
4143 generated_pem , generated_jwk = JWT .get_PEM_JWK (private_key )
44+
45+
46+ @pytest .mark .asyncio
47+ async def test_get_access_token ():
48+ mock_request_executor = MagicMock ()
49+ mock_request_executor .create_request = AsyncMock (return_value = ({"mock_request" : "data" }, None ))
50+ mock_response_details = MagicMock ()
51+ mock_response_details .content_type = "application/json"
52+ mock_response_details .status = 200
53+ mock_request_executor .fire_request = AsyncMock (
54+ return_value = (None , mock_response_details , '{"access_token": "mock_token", "expires_in": 3600}' , None ))
55+
56+ config = {
57+ "client" : {
58+ "orgUrl" : "https://example.okta.com" ,
59+ "clientId" : "valid-client-id" ,
60+ "privateKey" : mocks .SAMPLE_RSA ,
61+ "scopes" : ["scope1" , "scope2" ],
62+ "oauthTokenRenewalOffset" : 5
63+ }
64+ }
65+ oauth = OAuth (mock_request_executor , config )
66+ token , error = await oauth .get_access_token ()
67+
68+ assert token == "mock_token"
69+ assert error is None
70+
71+
72+ @pytest .mark .asyncio
73+ async def test_clear_access_token ():
74+ mock_request_executor = MagicMock ()
75+ mock_request_executor ._cache = MagicMock ()
76+ mock_request_executor ._default_headers = {}
77+
78+ config = {
79+ "client" : {
80+ "orgUrl" : "https://example.okta.com" ,
81+ "clientId" : "valid-client-id" ,
82+ "privateKey" : "valid-private-key" ,
83+ "scopes" : ["scope1" , "scope2" ],
84+ "oauthTokenRenewalOffset" : 5
85+ }
86+ }
87+ oauth = OAuth (mock_request_executor , config )
88+ oauth ._access_token = "mock_token"
89+ oauth ._access_token_expiry_time = 1234567890
90+
91+ oauth .clear_access_token ()
92+
93+ assert oauth ._access_token is None
94+ assert oauth ._access_token_expiry_time is None
0 commit comments