From a95e119d59dc464fbb900567891584a4ef82dcdb Mon Sep 17 00:00:00 2001 From: davidt99 Date: Sun, 5 Mar 2023 15:03:16 +0200 Subject: [PATCH] fix: treat expire_at as utc timestamp --- CHANGES | 4 ++++ intezer_sdk/__init__.py | 2 +- intezer_sdk/api.py | 2 +- tests/unit/base_test.py | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index bbf50ea..3a7b101 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/intezer_sdk/__init__.py b/intezer_sdk/__init__.py index e4a8b8f..572cd74 100644 --- a/intezer_sdk/__init__.py +++ b/intezer_sdk/__init__.py @@ -1 +1 @@ -__version__ = '1.16.2' +__version__ = '1.16.3' diff --git a/intezer_sdk/api.py b/intezer_sdk/api.py index 7b110b3..9057ada 100644 --- a/intezer_sdk/api.py +++ b/intezer_sdk/api.py @@ -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() diff --git a/tests/unit/base_test.py b/tests/unit/base_test.py index 3b131b3..aa5eadc 100644 --- a/tests/unit/base_test.py +++ b/tests/unit/base_test.py @@ -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()