Skip to content

Commit

Permalink
OKTA-641384: clear token from cache on call to oauth.clear_access_tok…
Browse files Browse the repository at this point in the history
…en() (#380)

fix oauth.clear_access_token()
 update changelog and version

---------

Co-authored-by: haggrip <[email protected]>
  • Loading branch information
bryanapellanes-okta and haggrip authored Dec 15, 2023
1 parent 700c5f1 commit d896f65
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
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

0 comments on commit d896f65

Please sign in to comment.