Refine scoped API key capabilities

This commit is contained in:
wizardchen
2026-07-07 11:09:10 +08:00
committed by lyingbug
parent b5cc7d2a28
commit 2c6f082062
38 changed files with 1718 additions and 655 deletions
+4 -4
View File
@@ -20,14 +20,14 @@ func TestAssertAPIKeyPoliciesMatchRoutes_TrailingSlash(t *testing.T) {
// Register through the apiKey helpers using both "" and "/" rel plus a
// nested path, mirroring real route declarations.
empty := g.apiKeyGroup(v1.Group("/knowledge-bases"), apiKeyViewer())
empty := g.apiKeyGroup(v1.Group("/knowledge-bases"), apiKeyAny())
empty.GET("", noop)
slash := g.apiKeyGroup(v1.Group("/evaluation"), apiKeyOwner())
slash := g.apiKeyGroup(v1.Group("/evaluation"), apiKeyFullAccess())
slash.POST("/", noop)
slash.GET("/", noop)
g.apiKeyRoute(v1, http.MethodGet, "/tenants", apiKeyOwner(), noop)
g.apiKeyRoute(v1, http.MethodGet, "/tenants", apiKeyFullAccess(), noop)
// Must not panic: every declared policy resolves to a real route despite
// the trailing-slash difference on /evaluation.
@@ -42,7 +42,7 @@ func TestAssertAPIKeyPoliciesMatchRoutes_Missing(t *testing.T) {
g := &rbacGuards{}
// Declare a policy for a path that is never registered on the engine.
g.ensureAPIKeyAuthorizer().Register(http.MethodPost, "/api/v1/does-not-exist", apiKeyOwner())
g.ensureAPIKeyAuthorizer().Register(http.MethodPost, "/api/v1/does-not-exist", apiKeyFullAccess())
defer func() {
if recover() == nil {