Skip to content

Commit

Permalink
Merge pull request #126 from uclahs-cds/aholmes-replaceassert-statements
Browse files Browse the repository at this point in the history
Replace `assert` statements with `AssertionError`.
  • Loading branch information
aholmes authored Sep 26, 2024
2 parents 229d129 + aad0c7a commit 329261e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/web/Ligare/web/encryption/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def decrypt_flask_cookie(secret_key: str, cookie_str: str) -> Dict[str, Any]:

serializer = _get_serializer(secret_key)
data: Any = serializer.loads(cookie_str)
assert type(data) is dict

if type(data) is not dict:
raise AssertionError(
f"Deserialized session data is not a dictionary. It is a `{type(data)}`."
)

return data # pyright: ignore[reportUnknownVariableType]


Expand All @@ -56,5 +61,10 @@ def encrypt_flask_cookie(secret_key: str, data: Dict[str, Any] | SessionMixin) -

serializer = _get_serializer(secret_key)
cookie_str = serializer.dumps(data)
assert type(cookie_str) is str

if type(cookie_str) is not str:
raise AssertionError(
f"Serialized cookie data is not a str. It is a `{type(cookie_str)}`."
)

return cookie_str

0 comments on commit 329261e

Please sign in to comment.