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