26 lines
810 B
Go
26 lines
810 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSchemaErrorsIdentifyFieldWithoutPrivateValue(t *testing.T) {
|
|
raw, err := os.ReadFile("../../contracts/schema/examples/config-read-providers.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var body map[string]any
|
|
json.Unmarshal(raw, &body)
|
|
provider := body["providers"].([]any)[0].(map[string]any)
|
|
provider["provider_code"] = "PRIVATE_VALUE_MUST_NOT_APPEAR"
|
|
provider["api_key"] = map[string]string{"secret": "PRIVATE_VALUE_MUST_NOT_APPEAR"}
|
|
raw, _ = json.Marshal(body)
|
|
err = validateResource(raw, "ai_providers", body["dispatcher_id"].(string))
|
|
if err == nil || !strings.Contains(err.Error(), "api_key") || strings.Contains(err.Error(), "PRIVATE_VALUE_MUST_NOT_APPEAR") {
|
|
t.Fatalf("unsafe or opaque diagnostic: %v", err)
|
|
}
|
|
}
|