From 300630f6fbbbb85918052f949e073ee8aed14752 Mon Sep 17 00:00:00 2001 From: "Anthony T. Lannutti" Date: Sat, 26 Aug 2023 02:58:17 -0500 Subject: [PATCH] Fix formatting issues --- starlette_authlib/middleware.py | 14 ++++++++++++-- tests/test_session.py | 16 ++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/starlette_authlib/middleware.py b/starlette_authlib/middleware.py index 6106a9a..a6ab75a 100644 --- a/starlette_authlib/middleware.py +++ b/starlette_authlib/middleware.py @@ -9,7 +9,12 @@ from collections import namedtuple from authlib.jose import jwt -from authlib.jose.errors import BadSignatureError, DecodeError, ExpiredTokenError, InvalidTokenError +from authlib.jose.errors import ( + BadSignatureError, + DecodeError, + ExpiredTokenError, + InvalidTokenError, +) from starlette.config import Config from starlette.datastructures import MutableHeaders, Secret from starlette.requests import HTTPConnection @@ -89,7 +94,12 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: jwt_payload.validate_nbf(time.time(), 0) scope["session"] = jwt_payload initial_session_was_empty = False - except (BadSignatureError, ExpiredTokenError, DecodeError, InvalidTokenError): + except ( + BadSignatureError, + ExpiredTokenError, + DecodeError, + InvalidTokenError, + ): scope["session"] = {} else: scope["session"] = {} diff --git a/tests/test_session.py b/tests/test_session.py index 2253d9a..a06eb60 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -1,6 +1,6 @@ import os import re -from datetime import timedelta, datetime +from datetime import datetime, timedelta import pytest from starlette.applications import Starlette @@ -121,13 +121,11 @@ def test_session_expires(): ) assert response.json() == {"session": {}} + def test_session_futue_nbf(): now = datetime.now() nbf = datetime.timestamp(now + timedelta(days=1)) - claims = { - "nbf": nbf, - "some": "data" - } + claims = {"nbf": nbf, "some": "data"} for jwt_alg, secret_key in ( ("HS256", "example"), ( @@ -158,14 +156,12 @@ def test_session_futue_nbf(): response = secure_client.get("/view_session") assert response.json() == {"session": {}} - + + def test_session_past_nbf(): now = datetime.now() nbf = datetime.timestamp(now - timedelta(seconds=1)) - claims = { - "nbf": nbf, - "some": "data" - } + claims = {"nbf": nbf, "some": "data"} for jwt_alg, secret_key in ( ("HS256", "example"), (