Align Multi-Tenant, Audit, and Webhook Help with tenant access policy

Update docs/MULTI_TENANT.md, docs/AUDIT_LOGGING.md, docs/WEBHOOKS.md, and
their shipped mirrors in frontend-modern/public/docs/ to match current
multi-organization tenant resolution and default-organization access control
in internal/api/middleware_tenant.go, internal/api/org_access_policy.go,
internal/api/org_handlers.go, and internal/api/router_routes_licensing.go:

- Replace the outdated claim that default-organization members cannot be
  managed with the shipped shared-process policy: default access requires
  instance administration or explicit default viewer membership, instance
  admins manage default members via POST /api/orgs/default/members and
  DELETE /api/orgs/default/members/{userId}, first startup runs the
  one-time RBAC viewer migration recorded in
  default-org-access-migration.json, and active WebSocket/SSE streams
  re-check organization access every 10 seconds.
- Document the actual tenant-context resolution order (X-Pulse-Org-ID,
  pulse_org_id browser cookie, single-organization-bound API token,
  signed-in user landing organization, then default), 403
  default_org_access_denied, and organization-neutral bootstrap routes.
- Add the five registered session-only invitation and incoming-share
  routes to the Multi-Tenant API reference table.
- Bind these Help statements and mirrors to live Go source in
  scripts/tests/test_admin_docs.py.

Contract-Neutral: Documentation and static doc-parity test alignment only with no runtime, API, schema, or subsystem contract delta.
Change-source: pulse-maintainer
This commit is contained in:
pulse-triage[bot]
2026-11-28 18:51:15 +00:00
parent f1d9e7a2a9
commit cf05cb42e8
7 changed files with 189 additions and 18 deletions

View File

@@ -519,6 +519,95 @@ class AdminDocsTest(unittest.TestCase):
auth_go = (ROOT / "internal/api/auth.go").read_text(encoding="utf-8")
self.assertIn("if mtm != nil && explicitTokenProvided {", auth_go)
def test_multi_tenant_audit_and_webhooks_help_match_tenant_context_and_default_org_policy(self):
org_doc = " ".join((DOCS / "MULTI_TENANT.md").read_text(encoding="utf-8").split())
audit_doc = " ".join((DOCS / "AUDIT_LOGGING.md").read_text(encoding="utf-8").split())
webhooks_doc = " ".join((DOCS / "WEBHOOKS.md").read_text(encoding="utf-8").split())
for phrase in (
"Default-organization membership:",
"POST /api/orgs/default/members",
"DELETE /api/orgs/default/members/{userId}",
"assigns only the `viewer` organization role",
"HTTP `400` (`invalid_role`)",
"`default-org-access-migration.json`",
"`migration:default-org-access`",
"Proxy-authenticated users have no stored RBAC assignment to migrate from",
"Active WebSocket and SSE streams re-check organization access every 10 seconds",
"`GET` | `/api/orgs/{id}/invitations`",
"`DELETE` | `/api/orgs/{id}/invitations/{userId}`",
"`GET` | `/api/org-invitations`",
"`DELETE` | `/api/org-invitations/{id}`",
"`DELETE` | `/api/orgs/{id}/shares/incoming/{shareId}`",
"`pulse_org_id` browser cookie",
"Single-organization-bound API token",
"Signed-in user's landing organization",
"`default_org_access_denied`",
"Organization-neutral bootstrap routes",
"`/api/security/status`, `/api/logout`, `/api/health`, `GET /api/orgs`, `/api/org-invitations`, `/api/org-invitations/*`",
"excluding `/ws`, `/simple-stats`, and `/debug`",
):
with self.subTest(doc="MULTI_TENANT.md", phrase=phrase):
self.assertIn(phrase, org_doc)
self.assertNotIn("Default-organization members cannot be managed here.", org_doc)
for phrase in (
"the `pulse_org_id` browser cookie",
"a single-organization-bound API token",
"a signed-in user's landing organization before falling back to `default`",
"Selection never overrides membership or a token's organization binding.",
):
with self.subTest(doc="AUDIT_LOGGING.md", phrase=phrase):
self.assertIn(phrase, audit_doc)
self.assertIn("`403 default_org_access_denied`", webhooks_doc)
for name in ("MULTI_TENANT.md", "AUDIT_LOGGING.md", "WEBHOOKS.md"):
with self.subTest(mirror=name):
self.assertEqual(
(DOCS / name).read_bytes(),
(ROOT / "frontend-modern/public/docs" / name).read_bytes(),
)
tenant_mw = (ROOT / "internal/api/middleware_tenant.go").read_text(encoding="utf-8")
for marker in (
'orgID = strings.TrimSpace(r.Header.Get("X-Pulse-Org-ID"))',
"if cookie, err := r.Cookie(CookieNameOrgID); err == nil {",
"else if len(t.OrgIDs) == 1 && strings.TrimSpace(t.OrgIDs[0]) != \"\" {",
"if landing := policy.LandingOrgID(r.Context(), userID); landing != \"\" {",
'code = "default_org_access_denied"',
"if !result.Allowed && policy != nil && orgID == \"default\" && token == nil && orgNeutralBootstrapRequest(r) {",
):
self.assertIn(marker, tenant_mw)
org_policy = (ROOT / "internal/api/org_access_policy.go").read_text(encoding="utf-8")
for marker in (
"var orgAccessRecheckInterval = 10 * time.Second",
'case "/api/security/status", "/api/logout", "/api/health":',
'case "/ws", "/simple-stats":',
'const defaultOrgAccessMigrationFile = "default-org-access-migration.json"',
'const defaultOrgAccessMigrationActor = "migration:default-org-access"',
):
self.assertIn(marker, org_policy)
org_handlers = (ROOT / "internal/api/org_handlers.go").read_text(encoding="utf-8")
for marker in (
"func (h *OrgHandlers) handleAddDefaultOrgMember(",
"func (h *OrgHandlers) handleRemoveDefaultOrgMember(",
'writeErrorResponse(w, http.StatusBadRequest, "invalid_role", "Default organization members are viewers; instance roles control what they can do", nil)',
):
self.assertIn(marker, org_handlers)
routes = (ROOT / "internal/api/router_routes_licensing.go").read_text(encoding="utf-8")
for marker in (
'r.mux.HandleFunc("GET /api/orgs/{id}/invitations"',
'r.mux.HandleFunc("DELETE /api/orgs/{id}/invitations/{userId}"',
'r.mux.HandleFunc("GET /api/org-invitations"',
'r.mux.HandleFunc("DELETE /api/org-invitations/{id}"',
'r.mux.HandleFunc("DELETE /api/orgs/{id}/shares/incoming/{shareId}"',
):
self.assertIn(marker, routes)
if __name__ == "__main__":
unittest.main()