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:
wizardchen
2026-07-07 11:40:47 +08:00
committed by lyingbug
parent 2c6f082062
commit d60614475e
12 changed files with 149 additions and 14 deletions
+12
View File
@@ -656,6 +656,10 @@ func validateTenantAPIKeyRequest(
if req.FullAccess {
return nil
}
caps := types.NormalizeAPIKeyCapabilities(types.StringArray(req.Capabilities))
if len(caps) == 0 {
return errors.NewValidationError("capabilities are required for scoped API keys")
}
for _, cap := range req.Capabilities {
if strings.TrimSpace(cap) == "" {
continue
@@ -1170,6 +1174,14 @@ func (h *TenantHandler) UpdateTenantKV(c *gin.Context) {
ctx := c.Request.Context()
key := secutils.SanitizeForLog(c.Param("key"))
switch key {
case "web-search-config", "parser-engine-config", "storage-engine-config":
if !dto.CanViewIntegrationSecrets(ctx) {
c.Error(errors.NewForbiddenError("integration configuration requires admin access"))
return
}
}
switch key {
case "web-search-config":
h.updateTenantWebSearchConfigInternal(c)