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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user