From 90dbd1ddf762568a43faf22ba925ef51b6f696e8 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Fri, 30 Oct 2026 11:27:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=87=AA=E6=9C=89=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8B=E4=BB=8D=E5=8F=AF=E5=90=91=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E6=B1=A0=E6=B7=BB=E5=8A=A0=E5=B9=B3=E5=8F=B0=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/http.py | 4 ++-- backend/tests/test_core.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/backend/app/api/http.py b/backend/app/api/http.py index 514cab2..77a5eed 100644 --- a/backend/app/api/http.py +++ b/backend/app/api/http.py @@ -113,7 +113,7 @@ async def nqi_start(body: dict) -> dict: if not username: raise _bad("请输入账号") with session_scope() as session: - if _setting(session).login_mode != "nqi": + if purpose != "pool" and _setting(session).login_mode != "nqi": raise _bad("当前使用自有账号登录") account = session.scalar(select(NqiAccount).where(NqiAccount.login_id == username)) resume_cookies = list(account.cookies or []) if account is not None and account.session_open and account.credential_valid else [] @@ -202,7 +202,7 @@ async def nqi_finish(body: dict) -> dict: await client.aclose() drop(session_id) with session_scope() as session: - if _setting(session).login_mode != "nqi": + if purpose != "pool" and _setting(session).login_mode != "nqi": raise _bad("当前使用自有账号登录") account = _save_pool(session, user, cookies) login_id = account.login_id diff --git a/backend/tests/test_core.py b/backend/tests/test_core.py index 1dad09c..63506a3 100644 --- a/backend/tests/test_core.py +++ b/backend/tests/test_core.py @@ -110,6 +110,21 @@ def test_local_login_task_and_admin(client: TestClient): assert "小区" in downloaded.content.decode("utf-8-sig") +def test_pool_add_is_allowed_when_login_is_local(client: TestClient, monkeypatch): + from app.nqi.client import NqiError + + async def fail_open(self): + raise NqiError("未连接平台") + + monkeypatch.setattr("app.api.http.NqiClient.open_login", fail_open) + blocked = client.post("/api/auth/nqi/start", json={"username": "someone"}) + assert blocked.status_code == 400 + assert blocked.json()["detail"] == "当前使用自有账号登录" + pool = client.post("/api/auth/nqi/start", json={"username": "someone", "purpose": "pool"}) + assert pool.status_code == 400 + assert pool.json()["detail"] == "未连接平台" + + def test_concurrency_bounds(): assert check_concurrency(1) == 1 assert check_concurrency(32) == 32