Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OKTA-641384: clear token from cache on call to oauth.clear_access_token() #380

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Okta Python SDK Changelog

## 2.9.5
* Clear access token from cache on call to OAuth.clear_access_token()

## 2.9.4
* Add optional parameter to api_response.next() to include response object as a third tuple value.

Expand Down
2 changes: 1 addition & 1 deletion okta/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.9.4'
__version__ = '2.9.5'
2 changes: 2 additions & 0 deletions okta/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ def clear_access_token(self):
Clear currently used OAuth access token, probably expired
"""
self._access_token = None
self._request_executor._cache.delete("OKTA_ACCESS_TOKEN")
self._request_executor._default_headers.pop("Authorization", None)
32 changes: 32 additions & 0 deletions tests/unit/test_oauth_clear_access_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from okta.oauth import OAuth

"""
Testing OAuth.clear_access_token
"""
class WasCalled:
def __init__(self):
self.value = False

cache_delete_was_called = WasCalled
headers_pop_was_called = WasCalled

class mockCache:
def delete(token):
cache_delete_was_called.value = True

class mockHeaders:
def pop(header, ignored):
headers_pop_was_called.value = True

class mockRequestExecutor:
def __init__(self, cache):
self._cache = cache
self._default_headers = mockHeaders

def test_oauth_clear_access_token():
_mockRequestExecutor = mockRequestExecutor(mockCache)
oauth = OAuth(_mockRequestExecutor, {})
oauth.clear_access_token()
assert cache_delete_was_called.value
assert headers_pop_was_called.value

Loading