Files
tenant-registry/internal/server/rights_pin_test.go
Sharang ParnerkarandClaude Opus 5.5 dc44eb22bb
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 6m6s
ci / image (pull_request) Skipped
feat(authz): the new bundles are assignable (RBAC step 4)
PSIRT, DEVELOPMENT, QUALITY, PRIVACY, PURCHASING, AUDITOR and EXTERNAL
can be given to a member (catalogue 2026-11-11.1). Invitations and role
changes accept exactly the catalogue's assignable bundles.

The registry's own checks read the catalogue instead of role lists:
notification recipients, managed services and Prüfwerk settings. For
today's six bundles nothing changes (pinned against the 2026-11-10
tables); AUDITOR now reads managed services, and the new bundles get
the mails their capabilities name. Individual capabilities still do not
count in the registry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-11 21:29:33 +01:00

88 lines
3.9 KiB
Go

package server
import (
"net/http/httptest"
"slices"
"strings"
"testing"
"git.breakpilot.com/platform/tenant-registry/internal/authn"
"git.breakpilot.com/platform/tenant-registry/internal/authz"
)
// The registry's role checks as they stood on 2026-11-10, before they read
// the catalogue. Today's six bundles must keep granting exactly this, so
// moving the checks onto capabilities (step 4) changed nobody's rights.
var registryChecks20261110 = map[string]map[string]bool{
"registry:members.manage": {"IT_ADMIN": true, "OWNER": true},
"registry:api-keys.manage": {"IT_ADMIN": true, "OWNER": true},
"registry:pruefwerk.settings": {"IT_ADMIN": true, "OWNER": true, "FINANCE": true},
"registry:services.read": {"IT_ADMIN": true, "OWNER": true, "CXO": true},
"registry:notify.documents": {"IT_ADMIN": true, "OWNER": true, "CXO": true, "FINANCE": true, "LEGAL": true},
"registry:notify.findings": {"IT_ADMIN": true, "OWNER": true, "CXO": true, "LEGAL": true},
"registry:intake.report": {"IT_ADMIN": true, "OWNER": true, "CXO": true, "FINANCE": true, "LEGAL": true, "USER": true},
}
func TestTodaysBundlesKeepTheRegistrysRoleChecks(t *testing.T) {
for _, role := range []string{"IT_ADMIN", "OWNER", "CXO", "FINANCE", "LEGAL", "USER"} {
for capability, holders := range registryChecks20261110 {
if got := authz.AnyGrants([]string{role}, capability); got != holders[role] {
t.Errorf("%s %s: catalogue %v, registry on 2026-11-10 %v", role, capability, got, holders[role])
}
}
// The last-admin guard and the tenant-admin check of a user token
// still agree with the catalogue.
if isAdminRole([]string{role}) != registryChecks20261110["registry:members.manage"][role] {
t.Errorf("%s: isAdminRole disagrees", role)
}
p := &authn.Principal{Subject: "u", TenantID: "t", OrgRoles: []string{role}}
if p.IsTenantAdmin() != authz.AnyGrants(p.OrgRoles, "registry:members.manage") {
t.Errorf("%s: IsTenantAdmin disagrees with the catalogue", role)
}
}
for _, c := range authz.Capabilities {
if _, ok := registryChecks20261110[c.Code]; c.Product == authz.Registry && !ok {
t.Errorf("%s: not pinned against a registry check", c.Code)
}
}
}
// The new bundles (§3a): what the registry now gives them, and that none of
// them administers the workspace.
func TestTheNewBundlesInTheRegistry(t *testing.T) {
want := map[string][]string{
"PSIRT": {"registry:notify.findings", "registry:intake.report"},
"DEVELOPMENT": {"registry:notify.findings", "registry:intake.report"},
"QUALITY": {"registry:notify.documents", "registry:intake.report"},
"PRIVACY": {"registry:notify.documents", "registry:intake.report"},
"PURCHASING": {"registry:notify.documents", "registry:intake.report"},
"AUDITOR": {"registry:services.read", "registry:notify.documents", "registry:intake.report"},
"EXTERNAL": {"registry:intake.report"},
}
for role, caps := range want {
if !authz.IsAssignable(role) {
t.Errorf("%s is not assignable", role)
}
for capability := range registryChecks20261110 {
if got := authz.AnyGrants([]string{role}, capability); got != slices.Contains(caps, capability) {
t.Errorf("%s %s: %v", role, capability, got)
}
}
if isAdminRole([]string{role}) {
t.Errorf("%s administers the workspace", role)
}
}
if authz.AnyGrants([]string{"psirt"}, "registry:notify.findings") != true || authz.AnyGrants([]string{"NOBODY"}, "registry:intake.report") {
t.Error("claims are matched case-insensitively and unknown bundles grant nothing")
}
}
// GET /v1/authz/catalogue serves the catalogue as it is in code.
func TestTheCatalogueIsServed(t *testing.T) {
rec := httptest.NewRecorder()
(&Server{}).getAuthzCatalogue(rec, nil)
if rec.Code != 200 || !strings.Contains(rec.Body.String(), `"version":"`+authz.Version+`"`) || !strings.Contains(rec.Body.String(), `"code":"PSIRT"`) {
t.Fatalf("%d %s", rec.Code, rec.Body.String())
}
}