Skip to content

Commit

Permalink
Adjust token refresh offset to prevent immediate renewal (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkilic committed Sep 4, 2024
1 parent 81d90c2 commit 9c56159
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bluepyemodel/access_point/forge_access_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def __init__(
self._available_ttypes = None
self._atlas_release = None

def refresh_token(self, offset=300):
def refresh_token(self, offset=30):
"""refresh token if token is expired or will be soon. Returns new expiring time.
Args:
Expand Down
12 changes: 6 additions & 6 deletions tests/unit_tests/test_nexus_forge_access_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def mock_forge_access_point():
"name": "Test User",
"email": "test_user@example.com",
"sub": "test_sub",
"exp": (datetime.now(timezone.utc) + timedelta(hours=1)).timestamp(),
"exp": (datetime.now(timezone.utc) + timedelta(seconds=300)).timestamp(),
}
with patch(
"bluepyemodel.access_point.forge_access_point.NexusForgeAccessPoint.refresh_token"
) as mock_refresh_token:
mock_refresh_token.return_value = (
datetime.now(timezone.utc) + timedelta(hours=1)
datetime.now(timezone.utc) + timedelta(seconds=300)
).timestamp()
with patch(
"bluepyemodel.access_point.forge_access_point.KnowledgeGraphForge"
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_refresh_token_not_expired(mock_forge_access_point):
"""
Test refresh_token method when the token is not expired.
"""
future_exp = (datetime.now(timezone.utc) + timedelta(hours=1)).timestamp()
future_exp = (datetime.now(timezone.utc) + timedelta(seconds=300)).timestamp()
with patch("jwt.decode") as mock_jwt_decode:
mock_jwt_decode.return_value = {
"preferred_username": "test_user",
Expand All @@ -88,8 +88,8 @@ def test_refresh_token_expired_offset(mock_forge_access_point, caplog):
"""
Test refresh_token method when the token is about to expire.
"""
future_exp = (datetime.now(timezone.utc) + timedelta(seconds=299)).timestamp()
new_future_exp = (datetime.now(timezone.utc) + timedelta(hours=1)).timestamp()
future_exp = (datetime.now(timezone.utc) + timedelta(seconds=29)).timestamp()
new_future_exp = (datetime.now(timezone.utc) + timedelta(seconds=300)).timestamp()
with patch("jwt.decode") as mock_jwt_decode:
mock_jwt_decode.side_effect = [
{
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_refresh_token_expired(mock_forge_access_point, caplog):
Test refresh_token method when the token has expired.
"""
past_exp = (datetime.now(timezone.utc) - timedelta(seconds=1)).timestamp()
new_future_exp = (datetime.now(timezone.utc) + timedelta(hours=1)).timestamp()
new_future_exp = (datetime.now(timezone.utc) + timedelta(seconds=300)).timestamp()
with patch("jwt.decode") as mock_jwt_decode:
mock_jwt_decode.side_effect = [
{
Expand Down

0 comments on commit 9c56159

Please sign in to comment.