Skip to content

Commit

Permalink
Fix formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lannuttia committed Aug 26, 2023
1 parent b3410d4 commit 300630f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
14 changes: 12 additions & 2 deletions starlette_authlib/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"] = {}
Expand Down
16 changes: 6 additions & 10 deletions tests/test_session.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"),
(
Expand Down Expand Up @@ -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"),
(
Expand Down

0 comments on commit 300630f

Please sign in to comment.