fix: 拒绝过短密钥,并把对外端口只留在本机

This commit is contained in:
2026-11-16 02:41:13 +08:00
parent 42f2b457a0
commit ec41af9489
11 changed files with 85 additions and 12 deletions
+12
View File
@@ -14,6 +14,18 @@ from euniv.encrypt import (
)
def test_short_secret_is_rejected(monkeypatch) -> None:
from euniv.crypto import require_secret
monkeypatch.setenv("EUNIV_SECRET_KEY", "too-short")
try:
require_secret()
except RuntimeError as exc:
assert "32" in str(exc)
else:
raise AssertionError("过短的密钥应当被拒绝")
def test_encrypt_payload_wraps_progress_json_as_string() -> None:
body = '{"knowledgeId":"abc","end":false}'
assert encrypt_payload(body) == b'{"body":"{\\"knowledgeId\\":\\"abc\\",\\"end\\":false}"}'