From 6fca8d1306a79ee08dbeb962aaebd53b09bc1ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Voron?= Date: Wed, 15 Sep 2021 14:45:28 +0200 Subject: [PATCH] Add a test for JWT helpers --- setup.cfg | 3 ++- tests/test_jwt.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/test_jwt.py diff --git a/setup.cfg b/setup.cfg index 907257ca..9b5c1596 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,9 +26,10 @@ ignore_missing_imports = True [tool:pytest] addopts = --ignore=test_build.py -markers = +markers = authentication db fastapi_users + jwt oauth router diff --git a/tests/test_jwt.py b/tests/test_jwt.py new file mode 100644 index 00000000..3658cef7 --- /dev/null +++ b/tests/test_jwt.py @@ -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