Skip to content

Commit

Permalink
Merge pull request #84 from intezer/fix/refresh-token-when-machine-no…
Browse files Browse the repository at this point in the history
…t-run-on-utc

fix: treat expire_at as utc timestamp
  • Loading branch information
davidt99 authored Mar 5, 2023
2 parents ce46142 + a95e119 commit d5ddbb4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.16.3
____
- Parse the token expiration as utc timestamp

1.16.2
____
- Family info returns also tags related to family
Expand Down
2 changes: 1 addition & 1 deletion intezer_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.16.2'
__version__ = '1.16.3'
2 changes: 1 addition & 1 deletion intezer_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _request(self,

def _refresh_token_if_needed(self):
if self._token_expiration:
token_expire = datetime.datetime.fromtimestamp(self._token_expiration)
token_expire = datetime.datetime.utcfromtimestamp(self._token_expiration)
now = datetime.datetime.utcnow()
if (token_expire - now).total_seconds() < self._renew_token_window:
self._set_access_token()
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ def setUp(self) -> None:

def test_renew_token(self):
with responses.RequestsMock(assert_all_requests_are_fired=True) as mock:
token_expiration = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(seconds=20.2)
mock.add('POST',
url=f'{self.full_url}/get-access-token',
status=HTTPStatus.OK,
json={'result': 'access-token','expire_at': (datetime.datetime.utcnow() + datetime.timedelta(seconds=20.2)).timestamp()})
json={'result': 'access-token','expire_at': token_expiration.timestamp()})
api = set_global_api()
api.authenticate()
mock.reset()
Expand Down

0 comments on commit d5ddbb4

Please sign in to comment.