fix(backend): licensing off when no CLOUD_URL is configured (pre-KI-006 parity)

Before KI-006 an install without CLOUD_URL (dev, demos, test stacks) was
simply licensed; after it, a SITE_ID without a cloud counted as
'unverified' and blocked everything. Real sites always have both set, and
blanking CLOUD_URL is no stronger than blanking SITE_ID (already possible).
verify_token() now reads the built-in public key at call time so the e2e
suite can swap it in-process for a throwaway key (never via configuration).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-28 23:33:16 +03:00
co-authored by Claude Opus 5.5
parent 12fdea0914
commit d80f53a31e
2 changed files with 7 additions and 4 deletions
+2 -2
View File
@@ -74,8 +74,8 @@ def _latest_activity(db) -> datetime | None:
def apply_license(now: datetime | None = None) -> None: def apply_license(now: datetime | None = None) -> None:
"""Re-evaluate the license from the stored signed token (no network).""" """Re-evaluate the license from the stored signed token (no network)."""
if not settings.SITE_ID: if not settings.SITE_ID or not settings.CLOUD_URL:
return # dev / unregistered install: licensing off, as before return # dev / unregistered / no cloud configured: licensing off, as before KI-006
from database import SessionLocal from database import SessionLocal
from models.business_day import BusinessDay from models.business_day import BusinessDay
+5 -2
View File
@@ -58,8 +58,11 @@ def parse_dt(value) -> datetime | None:
return dt if dt.tzinfo else dt.replace(tzinfo=timezone.utc) return dt if dt.tzinfo else dt.replace(tzinfo=timezone.utc)
def verify_token(token: str | None, site_id: str, public_key_b64: str = LICENSE_PUBLIC_KEY) -> dict | None: def verify_token(token: str | None, site_id: str, public_key_b64: str | None = None) -> dict | None:
"""Payload of a genuine token for this site, else None.""" """Payload of a genuine token for this site, else None. The key defaults to
the built-in LICENSE_PUBLIC_KEY (read at call time, so the e2e suite can
swap it in-process for a throwaway test key — never via configuration)."""
public_key_b64 = public_key_b64 or LICENSE_PUBLIC_KEY
if not token or "." not in token: if not token or "." not in token:
return None return None
body, _, sig = token.partition(".") body, _, sig = token.partition(".")