From 40dccdb0b2c37dec1eaa82cead7ed681fe69020b Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Thu, 23 Jul 2026 07:02:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(bandit):=20B017=20-=20=E7=94=A8InvalidToken?= =?UTF-8?q?Error=E6=9B=BF=E6=8D=A2=E5=AE=BD=E6=B3=9BException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/unit/test_auth_handlers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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):