CI / contracts (push) Canceled after 0s
Website / deploy (push) Canceled after 0s
CI / test (macos-latest) (push) Canceled after 0s
CI / test (ubuntu-24.04) (push) Canceled after 0s
CI / test (ubuntu-24.04-arm) (push) Canceled after 0s
CI / test (windows-latest) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / operation-readiness (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
46 lines
1.7 KiB
Go
46 lines
1.7 KiB
Go
package schemas
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/s41r4j/cybot/pkg/schema"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func TestAllEmbeddedSchemasAreValidJSON(t *testing.T) {
|
|
names := Names()
|
|
if len(names) < 9 {
|
|
t.Fatalf("schema catalog too small: %v", names)
|
|
}
|
|
for _, name := range names {
|
|
b, err := Get(name)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !json.Valid(b) {
|
|
t.Errorf("%s is invalid JSON", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCanonicalSchemasValidateRuntimeValues(t *testing.T) {
|
|
request := schema.RunRequest{Capability: "web.content.discover", Target: "https://example.com", Input: json.RawMessage(`{}`), Approved: true}
|
|
if err := Validate("run-request", request); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
now := time.Now().UTC()
|
|
result := schema.Result{RunID: uuid.NewString(), Capability: "web.content.discover", Target: "https://example.com", Status: "completed", Summary: "empty fixture", Confidence: 1, Assets: []schema.Asset{}, Services: []schema.Service{}, Endpoints: []schema.Endpoint{}, Findings: []schema.Finding{}, Evidence: []schema.Evidence{}, Errors: []schema.RunError{}, Decisions: []schema.Decision{}, Assumptions: []string{}, VerificationRecommended: []string{}, NextCapabilities: []string{}, RelatedWorkflows: []string{}, PossibleFalsePositives: []string{}, StartedAt: now, FinishedAt: now}
|
|
if err := Validate("result", result); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestRuntimeValidationRejectsUnknownFields(t *testing.T) {
|
|
value := map[string]any{"capability": "asset.discover", "input": map[string]any{}, "approved": true, "unexpected": true}
|
|
if err := Validate("run-request", value); err == nil {
|
|
t.Fatal("accepted unknown request field")
|
|
}
|
|
}
|