Files
tenant-registry/internal/server/authz_test.go
Sharang ParnerkarandClaude Opus 5.5 849e79ada0
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 6m57s
ci / image (pull_request) Skipped
feat(telemetry): opt-in product telemetry relay and per-tenant switch
Werkpilot's content-free usage metrics go through the registry, so no
collector token sits on customer machines, and only for workspaces that
turned telemetry on.

- GET/PUT /v1/tenants/{id}/products/{product}/telemetry: the switch,
  default off, kept as the "telemetry" key of the product's settings
  document (0025, no migration); IT_ADMIN/OWNER or services; audited as
  product_settings.changed
- "telemetry" in licence grants (POST /v1/licences, /v1/licences/ci,
  heartbeat renewals) and at the top of the heartbeat answer
- POST /v1/telemetry: checks a batch against a fixed allowlist and
  forwards it to TELEMETRY_OTLP_URL as OTLP/HTTP JSON (delta sums and
  histograms, tenant resource attributes, never the person); 120 batches
  per person and hour; CLI user tokens pass with their licences grant

Refs platform/werkpilot#87

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

50 lines
2.4 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; 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},
// Telemetry (werkpilot#87): its own group; CLI user tokens pass
// through requireAuthz (telemetry_relay_test.go).
{"werkpilot-cli", "POST", "/v1/telemetry", false},
{"root", "POST", "/v1/telemetry", true},
{"portal-svc", "PUT", "/v1/tenants/t1/products/werkpilot/telemetry", true},
{"pruefwerk-svc", "GET", "/v1/tenants/t1/products/werkpilot/telemetry", true},
{"pruefwerk-svc", "PUT", "/v1/tenants/t1/products/werkpilot/telemetry", 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")
}
}