From a3abb28ce3b3a88d4eacd0d29492e608b534d4c4 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Fri, 3 Apr 2026 17:44:38 +0800 Subject: [PATCH] test: adapt dashboard auth fixtures for hashed default password --- tests/test_api_key_open_api.py | 9 ++++++++- tests/test_dashboard.py | 12 ++++++++++-- tests/test_kb_import.py | 9 ++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/test_api_key_open_api.py b/tests/test_api_key_open_api.py index a6d594c4f..aa13558f2 100644 --- a/tests/test_api_key_open_api.py +++ b/tests/test_api_key_open_api.py @@ -72,6 +72,13 @@ def app(core_lifecycle_td: AstrBotCoreLifecycle): return server.app +def _resolve_dashboard_password(core_lifecycle_td: AstrBotCoreLifecycle) -> str: + password = core_lifecycle_td.astrbot_config["dashboard"]["password"] + if isinstance(password, str) and password.startswith("pbkdf2_sha256$"): + return "astrbot" + return password + + @pytest_asyncio.fixture(scope="module") async def authenticated_header(app: Quart, core_lifecycle_td: AstrBotCoreLifecycle): test_client = app.test_client() @@ -79,7 +86,7 @@ async def authenticated_header(app: Quart, core_lifecycle_td: AstrBotCoreLifecyc "/api/auth/login", json={ "username": core_lifecycle_td.astrbot_config["dashboard"]["username"], - "password": core_lifecycle_td.astrbot_config["dashboard"]["password"], + "password": _resolve_dashboard_password(core_lifecycle_td), }, ) data = await response.get_json() diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index 6dc352057..8a7209e44 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -58,6 +58,14 @@ def app(core_lifecycle_td: AstrBotCoreLifecycle): return server.app +def _resolve_dashboard_password(core_lifecycle_td: AstrBotCoreLifecycle) -> str: + """Return a login password compatible with both hashed and plain defaults.""" + password = core_lifecycle_td.astrbot_config["dashboard"]["password"] + if isinstance(password, str) and password.startswith("pbkdf2_sha256$"): + return "astrbot" + return password + + @pytest_asyncio.fixture(scope="module") async def authenticated_header(app: Quart, core_lifecycle_td: AstrBotCoreLifecycle): """Handles login and returns an authenticated header.""" @@ -66,7 +74,7 @@ async def authenticated_header(app: Quart, core_lifecycle_td: AstrBotCoreLifecyc "/api/auth/login", json={ "username": core_lifecycle_td.astrbot_config["dashboard"]["username"], - "password": core_lifecycle_td.astrbot_config["dashboard"]["password"], + "password": _resolve_dashboard_password(core_lifecycle_td), }, ) data = await response.get_json() @@ -90,7 +98,7 @@ async def test_auth_login(app: Quart, core_lifecycle_td: AstrBotCoreLifecycle): "/api/auth/login", json={ "username": core_lifecycle_td.astrbot_config["dashboard"]["username"], - "password": core_lifecycle_td.astrbot_config["dashboard"]["password"], + "password": _resolve_dashboard_password(core_lifecycle_td), }, ) data = await response.get_json() diff --git a/tests/test_kb_import.py b/tests/test_kb_import.py index 8ad40f540..543240247 100644 --- a/tests/test_kb_import.py +++ b/tests/test_kb_import.py @@ -64,6 +64,13 @@ def app(core_lifecycle_td: AstrBotCoreLifecycle): return server.app +def _resolve_dashboard_password(core_lifecycle_td: AstrBotCoreLifecycle) -> str: + password = core_lifecycle_td.astrbot_config["dashboard"]["password"] + if isinstance(password, str) and password.startswith("pbkdf2_sha256$"): + return "astrbot" + return password + + @pytest_asyncio.fixture(scope="module") async def authenticated_header(app: Quart, core_lifecycle_td: AstrBotCoreLifecycle): """Handles login and returns an authenticated header.""" @@ -72,7 +79,7 @@ async def authenticated_header(app: Quart, core_lifecycle_td: AstrBotCoreLifecyc "/api/auth/login", json={ "username": core_lifecycle_td.astrbot_config["dashboard"]["username"], - "password": core_lifecycle_td.astrbot_config["dashboard"]["password"], + "password": _resolve_dashboard_password(core_lifecycle_td), }, ) data = await response.get_json()