feat: add server managed auto updates

This commit is contained in:
Your Name committed 2026-06-23 03:06:55 +08:00
1 parent ba2e159cad
commit 5c7d341d9b
6 files changed
+466 -6

No files matched your search

+58
View File
@@ -121,6 +121,64 @@ def test_admin_page_can_create_and_revoke_card(tmp_path):
assert service.activate(card, machine_fingerprint="machine-a").reason == "revoked"
def test_update_manifest_defaults_to_no_update_with_signature(tmp_path):
from fastapi.testclient import TestClient
from license_server import api
from license_server.core import LicenseService
from tests.license_test_keys import TEST_PRIVATE_KEY_PEM
service = LicenseService(db_path=tmp_path / "license.db", private_key_pem=TEST_PRIVATE_KEY_PEM)
client = TestClient(api.create_app(service=service, admin_token="secret"))
resp = client.get("/api/v1/update/manifest")
assert resp.status_code == 200
body = resp.json()
assert body["enabled"] is False
assert body["version"] == "0.0.0"
assert isinstance(body["signature"], str)
def test_admin_can_publish_update_and_download_installer(tmp_path):
from fastapi.testclient import TestClient
from license_server import api
from license_server.core import LicenseService
from tests.license_test_keys import TEST_PRIVATE_KEY_PEM
service = LicenseService(db_path=tmp_path / "license.db", private_key_pem=TEST_PRIVATE_KEY_PEM)
client = TestClient(api.create_app(service=service, admin_token="secret"))
client.post("/admin/login", data={"admin_token": "secret"}, follow_redirects=False)
payload = b"installer bytes"
published = client.post(
"/admin/update/publish",
cookies={api.ADMIN_CSRF_COOKIE: "csrf-token"},
data={
"csrf_token": "csrf-token",
"version": "3.3.4",
"notes": "smoke",
"force": "1",
},
files={"installer": ("DouyinGuaji-3.3.4-Setup.exe", payload, "application/octet-stream")},
)
manifest = client.get("/api/v1/update/manifest")
body = manifest.json()
download = client.get("/api/v1/update/download/DouyinGuaji-3.3.4-Setup.exe")
assert published.status_code == 200
assert "已发布更新 V3.3.4" in published.text
assert manifest.status_code == 200
assert body["enabled"] is True
assert body["version"] == "3.3.4"
assert body["sha256"]
assert body["url"].endswith("/api/v1/update/download/DouyinGuaji-3.3.4-Setup.exe")
assert isinstance(body["signature"], str)
assert download.status_code == 200
assert download.content == payload
def test_admin_page_shows_stats_cards_and_audit_logs(tmp_path):
from fastapi.testclient import TestClient