mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-27 03:15:08 +00:00
fix(cacher): store a jwt with no exp claim without an expiration
This commit is contained in:
@@ -78,6 +78,14 @@ def test_expired_jwt_is_stored_as_expired(cache: Cacher) -> None:
|
|||||||
assert entry.expired
|
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]
|
def test_expiration_survives_a_change_of_time_zone(cache: Cacher, zone) -> None: # type: ignore[no-untyped-def]
|
||||||
zone("UTC")
|
zone("UTC")
|
||||||
cache.get("key").set({"a": 1}, expiration=300)
|
cache.get("key").set({"a": 1}, expiration=300)
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ class Cacher:
|
|||||||
|
|
||||||
if expiration is None:
|
if expiration is None:
|
||||||
try:
|
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:
|
except jwt.DecodeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user