diff --git a/tests/unit/test_auth_handlers.py b/tests/unit/test_auth_handlers.py index 0a31fd0a1..e486bbebf 100755 --- a/tests/unit/test_auth_handlers.py +++ b/tests/unit/test_auth_handlers.py @@ -9,6 +9,7 @@ JWT + Password 委托层单元测试(第二十一波) from unittest.mock import patch import pytest +from jwt.exceptions import InvalidTokenError from packages.application.auth.jwt_handler import ( JWTHandler, @@ -76,7 +77,7 @@ class TestJWTHandler: def test_verify_invalid_token_raises(self): """无效 token 验证失败""" handler = JWTHandler(secret_key=SECRET_KEY) - with pytest.raises(Exception): + with pytest.raises(InvalidTokenError): handler.verify_access_token("invalid-token") def test_verify_wrong_secret(self): @@ -85,7 +86,7 @@ class TestJWTHandler: handler2 = JWTHandler(secret_key="key-b") token = handler1.create_access_token(user_id="user-1") - with pytest.raises(Exception): + with pytest.raises(InvalidTokenError): handler2.verify_access_token(token) def test_custom_algorithm(self):