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

+35 -2
View File
@@ -139,11 +139,11 @@ def test_license_install_route_accepts_code(monkeypatch):
message = "授权有效"
payload = {"customer": "demo"}
def fake_install(text):
def fake_install(text, **_kwargs):
calls["text"] = text
return _Status()
monkeypatch.setattr(routes, "install_license_text", fake_install)
monkeypatch.setattr(routes, "install_license_or_activate", fake_install)
status, obj = _post("/api/license", {"license_text": "DYGJ-demo"}, monkeypatch)
@@ -153,6 +153,39 @@ def test_license_install_route_accepts_code(monkeypatch):
assert calls["text"] == "DYGJ-demo"
def test_license_install_route_uses_activation_url(monkeypatch):
calls = {}
class _Status:
ok = True
reason = "ok"
message = "授权有效"
payload = {}
def fake_install(text, *, activation_url="", timeout_seconds=10):
calls["text"] = text
calls["activation_url"] = activation_url
calls["timeout_seconds"] = timeout_seconds
return _Status()
monkeypatch.setattr(
routes,
"read_config",
lambda: {"license": {"activation_url": "https://license.example/api/v1/activate", "timeout_seconds": 7}},
)
monkeypatch.setattr(routes, "install_license_or_activate", fake_install)
status, obj = _post("/api/license", {"license_text": "DG-DEMO"}, monkeypatch)
assert status == 200
assert obj["ok"] is True
assert calls == {
"text": "DG-DEMO",
"activation_url": "https://license.example/api/v1/activate",
"timeout_seconds": 7,
}
def test_license_install_route_rejects_empty_code(monkeypatch):
status, obj = _post("/api/license", {"license_text": " "}, monkeypatch)