mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
test: adapt dashboard auth fixtures for hashed default password
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user