Reject empty environment/project, disable FAV consumers at register time, and keep historical classification/repair/replay as audited application use cases with no raw SQL entrypoint. Co-authored-by: Cursor <cursoragent@cursor.com>
75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
package events
|
|
|
|
import "testing"
|
|
|
|
func TestClassifyQuarantinesMissingScope(t *testing.T) {
|
|
row := ClassifyEnvelope(Envelope{EventID: "e1", EventName: EventApproved, SchemaVersion: EnvelopeSchema}, ConsumerNotify)
|
|
if row.Classification != ClassificationQuarantine || row.Reason != "missing_scope" {
|
|
t.Fatalf("%+v", row)
|
|
}
|
|
}
|
|
|
|
func TestClassifyQuarantinesUnknownEvent(t *testing.T) {
|
|
env := Envelope{EventID: "e2", EventName: "document.nope", SchemaVersion: 1, Environment: "dev", ProjectID: 9, PayloadDigest: Digest(nil)}
|
|
row := ClassifyEnvelope(env, ConsumerNotify)
|
|
if row.Classification != ClassificationQuarantine {
|
|
t.Fatalf("%+v", row)
|
|
}
|
|
}
|
|
|
|
func TestClassifySafeKnownContract(t *testing.T) {
|
|
body := []byte(`{"doc_id":"d"}`)
|
|
env := Envelope{
|
|
EventID: "e3", EventName: EventApproved, SchemaVersion: EnvelopeSchema,
|
|
Environment: "dev", ProjectID: 9, PayloadDigest: Digest(body), Payload: body,
|
|
}
|
|
row := ClassifyEnvelope(env, ConsumerNotify)
|
|
if row.Classification != ClassificationSafe {
|
|
t.Fatalf("%+v", row)
|
|
}
|
|
}
|
|
|
|
func TestSanitizeSummaryDropsPayload(t *testing.T) {
|
|
got := SanitizeSummary(map[string]string{"code": "SCOPE", "payload": "SECRET", "path": "/x"}, []string{"code"})
|
|
if got != `{"code":"SCOPE"}` {
|
|
t.Fatalf("%s", got)
|
|
}
|
|
}
|
|
|
|
func TestFixtureInventoryThirtyPerType(t *testing.T) {
|
|
names := []string{EventCandidateReady, EventVersionCommitted, EventDownstreamImpact, EventApproved, EventChangeReportDegraded}
|
|
var rows []InventoryRow
|
|
for _, name := range names {
|
|
for i := 0; i < 30; i++ {
|
|
body := []byte(`{"doc_id":"fixture"}`)
|
|
env := Envelope{
|
|
EventID: name + "-fix-" + string(rune('a'+i%26)) + string(rune('0'+i/26)),
|
|
EventName: name, SchemaVersion: EnvelopeSchema, Environment: "dev", ProjectID: 9,
|
|
PayloadDigest: Digest(body), Payload: body,
|
|
}
|
|
rows = append(rows, ClassifyEnvelope(env, LiveConsumers(name)[0]))
|
|
}
|
|
}
|
|
if len(rows) != 150 {
|
|
t.Fatalf("rows=%d", len(rows))
|
|
}
|
|
for _, r := range rows {
|
|
if r.Classification != ClassificationSafe {
|
|
t.Fatalf("%+v", r)
|
|
}
|
|
}
|
|
b, err := InventoryJSON(rows)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(b) == 0 {
|
|
t.Fatal("empty inventory")
|
|
}
|
|
}
|
|
|
|
func TestValidateRepairRequiresAudit(t *testing.T) {
|
|
if err := ValidateRepair(RepairRecord{EventID: "e", FieldName: "environment"}); err == nil {
|
|
t.Fatal("expected failure")
|
|
}
|
|
}
|