Files
tenant-registry/internal/server/authz_test.go
Sharang ParnerkarandClaude Opus 5.5 361e748f06
ci / shared (pull_request) Successful in 11s
ci / test (pull_request) Successful in 6m39s
ci / image (pull_request) Skipped
feat(updates): per-tenant self-update policy for Werkpilot
A workspace can leave Werkpilot's self-update on ("auto", the default),
turn it off, or pin a release version.

- GET/PUT /v1/tenants/{id}/products/{product}/updates with
  {"policy": "auto" | "off" | "<semver>"}: the "updates" key of the
  product's settings document (0025, no migration); IT_ADMIN/OWNER or
  services; audited as product_settings.changed; werkpilot only
- "updates" in licence grants (POST /v1/licences, /v1/licences/ci,
  heartbeat renewals) and at the top of the heartbeat answer, read fresh
  each time, "auto" when unset

Refs platform/werkpilot#89

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRayW7ztyk1uAtwMJPR
2026-11-23 16:38:36 +01:00

47 lines
2.2 KiB
Go

package server
import "testing"
func TestAuthzRules(t *testing.T) {
a := ParseAuthzRules(" portal-svc:tenants,catalog,api-keys,audit,users ; pruefwerk-svc:entitlements,tenants.read,api-keys.verify,audit.write,connections.read; werkpilot-svc:tenants.read; root:* ;broken")
cases := []struct {
azp, method, path string
want bool
}{
{"portal-svc", "POST", "/v1/tenants", true},
{"portal-svc", "GET", "/v1/tenants/by-slug/acme", true},
{"portal-svc", "POST", "/v1/internal/entitlements/check", false},
{"pruefwerk-svc", "POST", "/v1/internal/entitlements/check", true},
{"pruefwerk-svc", "GET", "/v1/tenants", true},
{"pruefwerk-svc", "POST", "/v1/tenants", false},
{"pruefwerk-svc", "POST", "/v1/internal/api-keys/verify", true},
{"pruefwerk-svc", "POST", "/v1/api-keys", false},
{"pruefwerk-svc", "POST", "/v1/audit", true},
{"pruefwerk-svc", "GET", "/v1/audit", false},
{"root", "DELETE", "/v1/api-keys/x", true},
{"unknown", "GET", "/v1/catalog", false},
{"portal-svc", "GET", "/v1/authz/catalogue", false},
{"root", "GET", "/v1/authz/catalogue", true},
// Connections (#138): products read the internal pair with their own
// group; tenants.read alone does not reach it.
{"pruefwerk-svc", "GET", "/v1/internal/tenants/t1/connections", true},
{"pruefwerk-svc", "GET", "/v1/internal/connections/c1", true},
{"werkpilot-svc", "GET", "/v1/internal/tenants/t1/connections", false},
{"portal-svc", "GET", "/v1/internal/connections/c1", false},
{"portal-svc", "POST", "/v1/tenants/t1/connections", true},
{"pruefwerk-svc", "POST", "/v1/tenants/t1/connection-invites", false},
// Update policy (werkpilot#89): the tenants groups.
{"portal-svc", "PUT", "/v1/tenants/t1/products/werkpilot/updates", true},
{"pruefwerk-svc", "GET", "/v1/tenants/t1/products/werkpilot/updates", true},
{"pruefwerk-svc", "PUT", "/v1/tenants/t1/products/werkpilot/updates", false},
}
for _, c := range cases {
if got := a.Allowed(c.azp, routeGroup(c.method, c.path)); got != c.want {
t.Errorf("%s %s %s: got %v want %v", c.azp, c.method, c.path, got, c.want)
}
}
if ParseAuthzRules("") != nil || !(*Authz)(nil).Allowed("anyone", "tenants.write") {
t.Errorf("empty rules must allow everything")
}
}