Files
tenant-registry/internal/server/authz_test.go
Sharang ParnerkarandClaude Opus 5.5 c5a6c0d20e
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 6m39s
ci / image (pull_request) Skipped
fix(feedback): let the CLIs' user tokens reach /v1/feedback
The deployed AUTHZ_RULES give werkpilot-cli and firmwerk-cli only
licences and usage, so the new feedback group answered FORBIDDEN_CLIENT.
A user token from a client holding licences now passes for feedback too;
other clients still need the feedback group, and service tokens are
refused by the handler.

Refs platform/werkpilot#86

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

48 lines
2.3 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; werkpilot-cli:licences,usage,feedback; firmwerk-cli:licences,usage; 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},
// Feedback (werkpilot#86): its own group. User tokens from clients
// with licences also pass (requireAuthz, feedback_test.go).
{"werkpilot-cli", "POST", "/v1/feedback", true},
{"firmwerk-cli", "POST", "/v1/feedback", false},
{"portal-svc", "POST", "/v1/feedback", 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")
}
}