From 08f77e9a2ace57c04432d6bb921e60a11de0596b Mon Sep 17 00:00:00 2001 From: Anthony Mahanna Date: Tue, 7 Nov 2023 11:06:39 -0500 Subject: [PATCH] update `test_auth_jwt_expiry` --- tests/test_auth.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/test_auth.py b/tests/test_auth.py index 91c7b870..8b68fd36 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -9,6 +9,7 @@ ServerTLSError, ServerTLSReloadError, ServerVersionError, + ServerConnectionError, ) from tests.helpers import assert_raises, generate_jwt, generate_string @@ -125,22 +126,32 @@ def test_auth_superuser_token(client, db_name, root_password, secret): def test_auth_jwt_expiry(client, db_name, root_password, secret): # Test automatic token refresh on expired token. db = client.db("_system", "root", root_password, auth_method="jwt") + valid_token = generate_jwt(secret) expired_token = generate_jwt(secret, exp=-1000) db.conn._token = expired_token db.conn._auth_header = f"bearer {expired_token}" assert isinstance(db.version(), str) - # Test correct error on token expiry (superuser). + # Test expiry error on db instantiation (superuser) + with assert_raises(ServerConnectionError) as err: + client.db("_system", superuser_token=expired_token, verify=True) + + # Test expiry error on db version (superuser) db = client.db("_system", superuser_token=expired_token) with assert_raises(ServerVersionError) as err: db.version() assert err.value.error_code == FORBIDDEN - # Test correct error on token expiry (user). + # Test expiry error on set_token (superuser). + db = client.db("_system", superuser_token=valid_token) + with assert_raises(JWTExpiredError) as err: + db.conn.set_token(expired_token) + + # Test expiry error on db instantiation (user) with assert_raises(JWTExpiredError) as err: db = client.db("_system", user_token=expired_token) - # Test set_token() with expired token. - db = client.db("_system", user_token=generate_jwt(secret)) + # Test expiry error on set_token (user). + db = client.db("_system", user_token=valid_token) with assert_raises(JWTExpiredError) as err: db.conn.set_token(expired_token)