fix: 保活按登录成功后的入口再走一遍

This commit is contained in:
2026-11-10 15:18:29 +08:00
parent 3acb29545c
commit 22d3c25a9b
3 changed files with 81 additions and 17 deletions
+36
View File
@@ -0,0 +1,36 @@
import asyncio
import httpx
from app.nqi.client import NqiClient
def test_keepalive_walks_the_post_login_pages():
seen: list[tuple[str, str]] = []
def handler(request: httpx.Request) -> httpx.Response:
seen.append((request.method, request.url.path))
if request.url.path.endswith("/getCasUser"):
return httpx.Response(200, json={"loginId": "a", "userName": "测试", "cityName": "江门", "orgName": ""})
return httpx.Response(200, text="<html>ok</html>")
async def run():
client = NqiClient()
await client.aclose()
client.client = httpx.AsyncClient(transport=httpx.MockTransport(handler))
client.import_cookies([{"name": "CASTGC", "value": "TGT-test", "domain": "nqi.gmcc.net", "path": "/"}])
try:
user = await client.replay_login_landing()
finally:
await client.aclose()
return user
user = asyncio.run(run())
paths = [path for _method, path in seen]
assert user["loginId"] == "a"
assert "/pro-portal/" in paths
assert "/pro-portal/pure/Home!getUserInfo.action" in paths
assert "/pro-portalv2/api/cas/getCasUser" in paths
assert "/pro-portal/pure/urlAction.action" in paths
assert "/pro-adhoc/index" in paths
assert any(item[0] == "POST" and item[1].endswith("/checkUserPasswordUpdated") for item in seen)