From ea1f54cb820c1a8c2004cc923a3b86710e6e677f Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Fri, 28 May 2021 12:41:23 +0200 Subject: [PATCH] [tests] JWTmw - flags check et user_id --- tests/test_jwt_middleware.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_jwt_middleware.py b/tests/test_jwt_middleware.py index 1d7896a..08bf44d 100644 --- a/tests/test_jwt_middleware.py +++ b/tests/test_jwt_middleware.py @@ -167,3 +167,36 @@ async def test_JWTAuthenticationBackend_DebugTrue(token_debug_true_builder): await backend.authenticate(req) except Exception as exc: assert type(exc) == AuthenticationError + +@pytest.mark.asyncio +async def test_JWTAuthenticationBackend_Check(token_debug_false_builder): + backend = JWTAuthenticationBackend() + assert backend.secret_key == SECRET + + req = Request( + params={ + 'check':True, + }) + + credentials, user = await backend.authenticate(req) + assert isinstance(user, UnauthenticatedUser) + assert isinstance(credentials, AuthCredentials) + + +@pytest.mark.asyncio +async def test_JWTAuthenticationBackend_CheckUserId(token_debug_false_builder): + backend = JWTAuthenticationBackend() + assert backend.secret_key == SECRET + + tmp_user_id = str(uuid4()) + + req = Request( + params={ + 'check': True, + 'user_id': tmp_user_id + }) + + credentials, user = await backend.authenticate(req) + assert isinstance(user, JWTUser) + assert user.__id == tmp_user_id + assert isinstance(credentials, AuthCredentials)