fix(cacher): store a jwt with no exp claim without an expiration

This commit is contained in:
imSp4rky
2026-11-26 13:40:05 -07:00
parent d0e7a70f94
commit ed3b772793
2 changed files with 9 additions and 1 deletions
+8
View File
@@ -78,6 +78,14 @@ def test_expired_jwt_is_stored_as_expired(cache: Cacher) -> None:
assert entry.expired
def test_jwt_without_exp_is_stored_with_no_expiration(cache: Cacher) -> None:
token = jwt.encode({"sub": "user"}, "k" * 32, algorithm="HS256")
cache.get("key").set(token)
stored = cache.get("key")
assert stored.data == token
assert stored.expiration is None
def test_expiration_survives_a_change_of_time_zone(cache: Cacher, zone) -> None: # type: ignore[no-untyped-def]
zone("UTC")
cache.get("key").set({"a": 1}, expiration=300)
+1 -1
View File
@@ -99,7 +99,7 @@ class Cacher:
if expiration is None:
try:
expiration = jwt.decode(self.data, options={"verify_signature": False})["exp"]
expiration = jwt.decode(self.data, options={"verify_signature": False}).get("exp")
except jwt.DecodeError:
pass