feat(api-keys): add platform-scoped API keys for control-plane automation
Introduce platform API keys with capability-based access to tenant management, system settings, runtime queues, and audit logs, plus admin UI for key lifecycle and system audit log viewing.
This commit is contained in:
@@ -47,6 +47,72 @@ func TestConversationRoutesDeclareChatCapability(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlatformControlPlaneRoutesDeclarePlatformCapabilities(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
g := &rbacGuards{}
|
||||
v1 := gin.New().Group("/api/v1")
|
||||
RegisterSystemAdminRoutes(v1, &handler.SystemHandler{}, nil, g)
|
||||
|
||||
cases := []struct {
|
||||
method string
|
||||
path string
|
||||
capability types.APIKeyCapability
|
||||
}{
|
||||
{http.MethodGet, "/api/v1/system/admin/settings", types.APIKeyCapabilitySystemSettingsRead},
|
||||
{http.MethodPut, "/api/v1/system/admin/settings/:key", types.APIKeyCapabilitySystemSettingsManage},
|
||||
{http.MethodGet, "/api/v1/system/admin/runtime/queues", types.APIKeyCapabilitySystemRuntimeRead},
|
||||
{http.MethodPost, "/api/v1/system/admin/runtime/queues/:queue/tasks/:task_id/actions/:action", types.APIKeyCapabilitySystemRuntimeManage},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
policy := mustLookupAPIKeyPolicy(t, g, tc.method, tc.path)
|
||||
if !policy.PlatformOnly {
|
||||
t.Fatalf("%s %s must be platform-only", tc.method, tc.path)
|
||||
}
|
||||
if !policyHasCapability(policy, tc.capability) {
|
||||
t.Fatalf("%s %s capabilities = %#v, want %s", tc.method, tc.path, policy.Capabilities, tc.capability)
|
||||
}
|
||||
}
|
||||
if _, ok := g.apiKeyAuthorizer.Lookup(http.MethodPost, "/api/v1/system/admin/api-keys"); ok {
|
||||
t.Fatal("platform API keys must not create other platform API keys")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlatformTenantLifecycleRoutesDeclarePlatformCapabilities(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
g := &rbacGuards{}
|
||||
v1 := gin.New().Group("/api/v1")
|
||||
RegisterTenantRoutes(
|
||||
v1,
|
||||
&handler.TenantHandler{},
|
||||
&handler.TenantMemberHandler{},
|
||||
&handler.TenantInvitationHandler{},
|
||||
nil,
|
||||
g,
|
||||
)
|
||||
|
||||
cases := []struct {
|
||||
method string
|
||||
path string
|
||||
capability types.APIKeyCapability
|
||||
}{
|
||||
{http.MethodGet, "/api/v1/tenants/all", types.APIKeyCapabilitySystemTenantsRead},
|
||||
{http.MethodGet, "/api/v1/tenants/search", types.APIKeyCapabilitySystemTenantsRead},
|
||||
{http.MethodPost, "/api/v1/tenants", types.APIKeyCapabilitySystemTenantsManage},
|
||||
{http.MethodGet, "/api/v1/tenants/:id", types.APIKeyCapabilitySystemTenantsRead},
|
||||
{http.MethodPut, "/api/v1/tenants/:id", types.APIKeyCapabilitySystemTenantsManage},
|
||||
{http.MethodDelete, "/api/v1/tenants/:id", types.APIKeyCapabilitySystemTenantsManage},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
policy := mustLookupAPIKeyPolicy(t, g, tc.method, tc.path)
|
||||
if !policy.PlatformOnly {
|
||||
t.Fatalf("%s %s must be platform-only", tc.method, tc.path)
|
||||
}
|
||||
if !policyHasCapability(policy, tc.capability) {
|
||||
t.Fatalf("%s %s capabilities = %#v, want %s", tc.method, tc.path, policy.Capabilities, tc.capability)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageHistoryRoutesDeclareMessageHistoryCapability(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
g := &rbacGuards{}
|
||||
|
||||
Reference in New Issue
Block a user