Add a test for JWT helpers

This commit is contained in:
François Voron
2021-09-15 14:45:28 +02:00
parent 79f1d1198a
commit 6fca8d1306
2 changed files with 17 additions and 1 deletions

View File

@@ -26,9 +26,10 @@ ignore_missing_imports = True
[tool:pytest]
addopts = --ignore=test_build.py
markers =
markers =
authentication
db
fastapi_users
jwt
oauth
router

15
tests/test_jwt.py Normal file
View File

@@ -0,0 +1,15 @@
import pytest
from fastapi_users.jwt import SecretType, generate_jwt, decode_jwt
@pytest.mark.jwt
def test_generate_decode_jwt(secret: SecretType):
audience = "TEST_AUDIENCE"
data = {"foo": "bar", "aud": audience}
jwt = generate_jwt(data, secret, 3600)
decoded = decode_jwt(jwt, secret, [audience])
assert decoded["foo"] == "bar"
assert decoded["aud"] == audience