- authz/catalog.py: 42 named permissions in groups and tiers (person, admin, host); authz/roles.py: built-in Operator (the owner), Admin (assignable with team mode), Member, Guest, Viewer + custom clones, in roles.json - a person = role + allow/deny overrides (authz/policy.py); users.json's old switches (cli, mcp, createProjects, scratchBash, codeMode, computers.enabled) migrate once to exactly what they allowed, backup kept - authz/scopes.py: what a credential acting for someone keeps (cli, worker.read|run, bot, phone) — a scope only narrows - authz/routes.py: (method, path) -> permission for all 310 /api routes; the gate asks Caller.allows() for every caller kind, replacing GUEST_ROUTES, CLI_ROUTES and the worker READ/RUN_ROUTES regex lists - golden route x caller matrix (authz/matrix.golden.txt, test_authz_matrix) - the claude bot reads the admin app minus people/security/the machine; the phone key reads its unread notifications only - loopback without the host token is logged (loopback_tokenless), refusals are perm_denied lines; the hub's own MCP calls send the token - /api/roles CRUD, /api/me and /api/users carry role/allow/deny/perms - worker-bound scheduled items and conversation-meta respect the binding Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
"""The route × caller matrix (authz/matrix.py) against the checked-in
|
||
``authz/matrix.golden.txt``: who reaches what changes only in a reviewed diff.
|
||
|
||
After a deliberate change: ``UPDATE_GOLDEN=1 python -m unittest test_authz_matrix``
|
||
rewrites the file. Imports ``main`` against throwaway paths."""
|
||
|
||
import os
|
||
import pathlib
|
||
import tempfile
|
||
import unittest
|
||
|
||
TMP = pathlib.Path(tempfile.mkdtemp())
|
||
for k, v in {"DB_PATH": TMP / "x.db", "TRANSCRIPTS_DIR": TMP / "t",
|
||
"WORKSPACE": TMP, "REPO_DIR": TMP, "ARCHIVE_DIR": TMP / "arch",
|
||
"META_PATH": TMP / "meta.json", "USERS_PATH": TMP / "users.json",
|
||
"AUTH_PATH": TMP / "auth.json", "ROLES_PATH": TMP / "roles.json",
|
||
"SIDECAR_TOKEN": "", "PI_TRANSCRIPTS_DIR": ""}.items():
|
||
os.environ.setdefault(k, str(v))
|
||
|
||
import main # noqa: E402
|
||
from authz import matrix # noqa: E402
|
||
from authz.routes import TABLE, iter_routes, matcher # noqa: E402
|
||
|
||
GOLDEN = pathlib.Path(__file__).parent / "authz" / "matrix.golden.txt"
|
||
|
||
|
||
class Matrix(unittest.TestCase):
|
||
def test_every_route_is_in_the_table_and_nothing_else(self):
|
||
self.assertEqual(matcher(main.app).unmapped, [])
|
||
live = {(m, p) for p, r in iter_routes(main.app.routes) if p.startswith("/api/")
|
||
for m in r.methods}
|
||
self.assertEqual(set(TABLE) - live, set(), "table entries no route has")
|
||
|
||
def test_the_matrix_is_the_golden_one(self):
|
||
got = matrix.render(main.app)
|
||
if os.environ.get("UPDATE_GOLDEN"):
|
||
GOLDEN.write_text(got)
|
||
self.assertEqual(got, GOLDEN.read_text(),
|
||
"who reaches which route changed — review it, then "
|
||
"UPDATE_GOLDEN=1 python -m unittest test_authz_matrix")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|