-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/store-token-validation' into 'master'
data service: add JWT expiration validation See merge request caimira/caimira!470
- Loading branch information
Showing
4 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import time | ||
import unittest | ||
from unittest.mock import Mock, patch | ||
|
||
import jwt | ||
|
||
from caimira.store.data_service import DataService | ||
|
||
|
||
|
@@ -10,6 +13,24 @@ def setUp(self): | |
self.credentials = {"email": "[email protected]", "password": "password123"} | ||
self.data_service = DataService(self.credentials) | ||
|
||
def test_jwt_expiration(self): | ||
is_valid = self.data_service._is_valid(None) | ||
self.assertFalse(is_valid) | ||
|
||
now = time.time() | ||
|
||
encoded = jwt.encode({"exp": now - 10}, "very secret", algorithm="HS256") | ||
is_valid = self.data_service._is_valid(encoded) | ||
self.assertFalse(is_valid) | ||
|
||
encoded = jwt.encode({"exp": now}, "very secret", algorithm="HS256") | ||
is_valid = self.data_service._is_valid(encoded) | ||
self.assertFalse(is_valid) | ||
|
||
encoded = jwt.encode({"exp": now + 10}, "very secret", algorithm="HS256") | ||
is_valid = self.data_service._is_valid(encoded) | ||
self.assertTrue(is_valid) | ||
|
||
@patch("requests.post") | ||
def test_login_successful(self, mock_post): | ||
# Mock successful login response | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
'numpy', | ||
'pandas', | ||
'psutil', | ||
'pyjwt', | ||
'python-dateutil', | ||
'retry', | ||
'scipy', | ||
|