ci: introduce ZitPlane P05 verification foundation
This commit is contained in:
1 parent
7ecf531697
commit
42b79362c1
32 files changed
+1731
-471
No files matched your search
@@ -0,0 +1,75 @@
|
||||
"""P05 structural contract checks — CI only, not a build or live auth test."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
ACCOUNT = ROOT / "users/ui"
|
||||
LOGIN = ROOT / "auth/ui/v2"
|
||||
|
||||
def fail(message: str) -> None:
|
||||
raise AssertionError(message)
|
||||
|
||||
def check_account_lock() -> None:
|
||||
manifest = json.loads((ACCOUNT / "package.json").read_text(encoding="utf-8"))
|
||||
lock = json.loads((ACCOUNT / "package-lock.json").read_text(encoding="utf-8"))
|
||||
root = lock["packages"][""]
|
||||
for group in ("dependencies", "devDependencies"):
|
||||
if root.get(group) != manifest.get(group):
|
||||
fail(f"Account {group} diverge from lockfile")
|
||||
if lock.get("lockfileVersion") != 3:
|
||||
fail("Expected npm lockfile v3")
|
||||
if manifest["name"] != lock["name"]:
|
||||
fail("Account lock name mismatch")
|
||||
print("ZITPLANE_ACCOUNT_LOCK_CONTRACT_PASS")
|
||||
|
||||
def check_login_importers() -> None:
|
||||
work = (LOGIN / "pnpm-workspace.yaml").read_text(encoding="utf-8")
|
||||
lock = (LOGIN / "pnpm-lock.yaml").read_text(encoding="utf-8")
|
||||
expected = {".", "apps/login", "packages/zitadel-client", "packages/zitadel-proto"}
|
||||
m = re.search(r"(?m)^importers:\s*$", lock)
|
||||
if not m:
|
||||
fail("Missing pnpm importers")
|
||||
n = re.search(r"(?m)^packages:\s*$", lock[m.end():])
|
||||
if not n:
|
||||
fail("Missing pnpm package snapshots")
|
||||
section = lock[m.end():m.end()+n.start()]
|
||||
importers = set(re.findall(r"(?m)^ ([^\s].*?):\s*$", section))
|
||||
if importers != expected:
|
||||
fail(f"Unexpected lock importers: {sorted(importers)}")
|
||||
for name in sorted(expected - {"."}):
|
||||
if not (LOGIN / name / "package.json").is_file():
|
||||
fail(f"Missing actual workspace package {name}")
|
||||
if f" - {name}\n" not in work:
|
||||
fail(f"Missing workspace member {name}")
|
||||
if " - apps/*" in work or " - console" in work:
|
||||
fail("Unused upstream workspace globs retained")
|
||||
print("ZITPLANE_LOGIN_WORKSPACE_CONTRACT_PASS")
|
||||
|
||||
def check_security_boundaries() -> None:
|
||||
src = (ACCOUNT / "src/auth.ts").read_text(encoding="utf-8")
|
||||
endpoint = (ACCOUNT / "src/app/api/account/me/route.ts").read_text(encoding="utf-8")
|
||||
identity = (ACCOUNT / "src/lib/identity.ts").read_text(encoding="utf-8")
|
||||
for flag in ('checks: ["pkce", "state", "nonce"]', 'zitadelTokenExpiresAt', 'token.zitadelSubject'):
|
||||
if flag not in src:
|
||||
fail(f"Missing reviewed OIDC source contract: {flag}")
|
||||
if "session?.user?.id" not in endpoint or "session?.user?.id" not in identity:
|
||||
fail("Protected source must gate on valid user id")
|
||||
print("ZITPLANE_SOURCE_GUARD_CONTRACT_PASS")
|
||||
|
||||
def main() -> int:
|
||||
check_account_lock()
|
||||
check_login_importers()
|
||||
check_security_boundaries()
|
||||
print("ZITPLANE_SOURCE_CONTRACTS_PASS")
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
sys.exit(main())
|
||||
except (AssertionError, ValueError, KeyError, FileNotFoundError) as exc:
|
||||
print(f"ZITPLANE_SOURCE_CONTRACTS_FAIL: {exc}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
Reference in new issue
Block a user