test(api-keys): add unit tests for tenant API key validation
Introduce unit tests for the tenant API key validation logic, ensuring that scoped keys require capabilities, while full-access keys are validated without them. The tests cover various scenarios, reinforcing the expected behavior of the API key validation function.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateTenantAPIKeyRequestRequiresCapabilitiesForScopedKey(t *testing.T) {
|
||||
err := validateTenantAPIKeyRequest(context.Background(), nil, 1, tenantAPIKeyCreateRequest{
|
||||
Name: "integration",
|
||||
FullAccess: false,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected validation error for scoped key without capabilities")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateTenantAPIKeyRequestAllowsFullAccessWithoutCapabilities(t *testing.T) {
|
||||
if err := validateTenantAPIKeyRequest(context.Background(), nil, 1, tenantAPIKeyCreateRequest{
|
||||
Name: "owner",
|
||||
FullAccess: true,
|
||||
}); err != nil {
|
||||
t.Fatalf("full-access key validation error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateTenantAPIKeyRequestAcceptsScopedKeyWithCapability(t *testing.T) {
|
||||
if err := validateTenantAPIKeyRequest(context.Background(), nil, 1, tenantAPIKeyCreateRequest{
|
||||
Name: "chat",
|
||||
FullAccess: false,
|
||||
Capabilities: []string{"chat"},
|
||||
}); err != nil {
|
||||
t.Fatalf("scoped key validation error = %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user