feat: add simple license activation server

This commit is contained in:
Your Name committed 2026-06-18 17:39:56 +08:00
1 parent b2db5ed499
commit 05be83d289
17 files changed
+1053 -6

No files matched your search

+38
View File
@@ -168,6 +168,44 @@ def test_install_license_rejects_invalid_text(tmp_path):
assert not target_path.exists()
def test_activate_license_code_installs_server_license(tmp_path, monkeypatch):
from douyin.license import license_manager
from tools.license_dev import create_dev_license
monkeypatch.setattr(license_manager, "get_machine_fingerprint", lambda: "machine-a")
source_path = tmp_path / "server_license.dat"
target_path = tmp_path / "license.dat"
create_dev_license(
output_path=source_path,
machine_fingerprint="machine-a",
expires_at=datetime.now(timezone.utc) + timedelta(days=30),
customer="online-user",
)
server_doc = json.loads(source_path.read_text(encoding="utf-8"))
calls = {}
def fake_post(url, payload, timeout_seconds=10):
calls["url"] = url
calls["payload"] = payload
calls["timeout_seconds"] = timeout_seconds
return {"ok": True, "license": server_doc, "reason": "ok", "message": "授权有效"}
result = license_manager.install_license_or_activate(
"DG-AAAA-BBBB-CCCC",
target_path,
activation_url="https://license.example.test/api/v1/activate",
http_post=fake_post,
)
assert result.ok is True
assert target_path.exists()
assert calls["payload"] == {
"card_key": "DG-AAAA-BBBB-CCCC",
"machine_fingerprint": "machine-a",
}
assert license_manager.check_license(target_path).payload["customer"] == "online-user"
def test_license_status_public_payload_hides_signature(tmp_path, monkeypatch):
from douyin.license import license_manager
from tools.license_dev import create_dev_license