From 8fb7054f4f90edc1b17fc255fbf365bfa80e8b14 Mon Sep 17 00:00:00 2001 From: "z.zhang" Date: Fri, 23 Oct 2026 00:45:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(license):=20=E4=BF=AE=E5=A4=8D=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E5=8F=91=E6=94=BE=E6=8E=88=E6=9D=83=E7=A0=81=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=BF=80=E6=B4=BB=EF=BC=88=E6=97=A0=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=97=B6=E7=9B=AE=E5=BD=95=E6=BC=8F=E5=90=88?= =?UTF-8?q?=E5=B9=B6=20DB=20=E7=A0=81=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/auth/licenses.py | 2 ++ tests/golden/test_web_license_codes_auth.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/server/auth/licenses.py b/server/auth/licenses.py index 62a6594..28c025e 100644 --- a/server/auth/licenses.py +++ b/server/auth/licenses.py @@ -359,6 +359,8 @@ class CodeLicenseProvider(LicenseProvider): } configured = (os.environ.get("APS_LICENSE_CODES") or "").strip() if not configured: + # 无环境变量发码时也必须合并面板发放的 DB 授权码,否则新码无法激活 + catalog.update(self._db_codes()) return catalog try: data = json.loads(configured) diff --git a/tests/golden/test_web_license_codes_auth.py b/tests/golden/test_web_license_codes_auth.py index 06a1bca..0df00f8 100644 --- a/tests/golden/test_web_license_codes_auth.py +++ b/tests/golden/test_web_license_codes_auth.py @@ -270,6 +270,22 @@ def test_admin_issues_code_and_user_activates_with_name(codes_app): assert entry["activation"]["status"] == "active" +def test_panel_issued_code_activates_without_env_codes(codes_app, monkeypatch): + """回归:未配置 APS_LICENSE_CODES 时,面板发放的 DB 授权码也必须可激活。""" + monkeypatch.delenv("APS_LICENSE_CODES", raising=False) + admin = _admin_client(codes_app) + created = admin.post("/api/admin/license/codes", json={ + "name": "无环境配置", "licenseType": "year", + }) + assert created.status_code == 200 + issued = created.json()["code"] + + user = TestClient(codes_app) + response = user.post("/api/auth/license/activate", json={"code": issued["code"]}) + assert response.status_code == 200 + assert response.json()["user"]["fullname"] == "无环境配置" + + def test_non_admin_cannot_manage_codes(codes_app): user = TestClient(codes_app) assert user.post("/api/auth/license/activate", json={"code": "USER-CODE-ALPHA"}).status_code == 200