53 lines
2.6 KiB
Go
53 lines
2.6 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,branding.read,branding.ack; 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},
|
|
// Branding (#155): products read the logo and acknowledge with their
|
|
// own groups; the portal's writes stay tenants.write.
|
|
{"pruefwerk-svc", "GET", "/v1/tenants/t1/branding/logo", true},
|
|
{"pruefwerk-svc", "POST", "/v1/tenants/t1/branding/ack", true},
|
|
{"pruefwerk-svc", "PUT", "/v1/tenants/t1/branding", false},
|
|
{"werkpilot-svc", "GET", "/v1/tenants/t1/branding/logo", false},
|
|
{"portal-svc", "PUT", "/v1/tenants/t1/branding", true},
|
|
{"portal-svc", "GET", "/v1/tenants/t1/branding", true},
|
|
{"portal-svc", "GET", "/v1/tenants/t1/branding/logo", false},
|
|
{"portal-svc", "POST", "/v1/tenants/t1/branding/ack", 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")
|
|
}
|
|
}
|