fix: 清掉清单里剩下的死代码、重复样式和评论解析

This commit is contained in:
2026-11-16 15:36:28 +08:00
parent 33640f7da8
commit 1cd7c7f818
12 changed files with 57 additions and 109 deletions
+25 -18
View File
@@ -1,17 +1,20 @@
import asyncio
import inspect
import httpx
from euniv import autostudy as autostudy_mod
from euniv import client as client_mod
from euniv.encrypt import (
encrypt_path_from_js,
encrypt_payload,
fetch_encryption,
note_play_html,
parse_encrypt_response,
reset_encrypt_config,
)
from euniv import encrypt as encrypt_mod
from euniv.encrypt import encrypt_path_from_js, encrypt_payload, fetch_encryption_async, note_play_html, parse_encrypt_response
def _reset_encrypt() -> None:
with encrypt_mod._lock:
encrypt_mod._config["path"] = encrypt_mod.DEFAULT_ENCRYPT_PATH
encrypt_mod._config["js_url"] = encrypt_mod.DEFAULT_JS_URL
encrypt_mod._config["loaded_at"] = 0.0
encrypt_mod._config["retry_at"] = 0.0
def test_short_secret_is_rejected(monkeypatch) -> None:
@@ -54,7 +57,7 @@ def test_parse_encrypt_response_accepts_wcf_shapes() -> None:
def test_note_play_html_and_js_path() -> None:
reset_encrypt_config()
_reset_encrypt()
html = (
'<script src="https://staticbdc1.yunxuetang.cn/SystemFiles/Js/'
'kng_studytrack_rw.js?v=10.11.45"></script>'
@@ -68,7 +71,7 @@ def test_note_play_html_and_js_path() -> None:
def test_fetch_encryption_posts_player_body() -> None:
reset_encrypt_config()
_reset_encrypt()
seen: dict[str, bytes] = {}
def handler(request: httpx.Request) -> httpx.Response:
@@ -81,14 +84,18 @@ def test_fetch_encryption_posts_player_body() -> None:
seen["body"] = request.content
return httpx.Response(200, json={"Status": "OK", "Data": "b" * 32})
with httpx.Client(transport=httpx.MockTransport(handler)) as client:
digest = fetch_encryption(
client,
'{"knowledgeId":"k1"}',
origin="https://euniv.zte.com.cn",
user_agent="UA",
)
assert digest == "b" * 32
async def main() -> None:
transport = httpx.MockTransport(handler)
async with httpx.AsyncClient(transport=transport) as client:
digest = await fetch_encryption_async(
client,
'{"knowledgeId":"k1"}',
origin="https://euniv.zte.com.cn",
user_agent="UA",
)
assert digest == "b" * 32
asyncio.run(main())
assert seen["content_type"] == b"text/json"
assert seen["body"] == b'{"body":"{\\"knowledgeId\\":\\"k1\\"}"}'