package objectgateway_test import ( "context" "crypto/ed25519" "crypto/rand" "encoding/json" g "knowledge-governance/internal/objectgateway" "os" "path/filepath" "testing" "time" ) func TestGatewayAuditCannotBeConfigurationBoolean(t *testing.T) { pub, priv, e := ed25519.GenerateKey(rand.Reader) if e != nil { t.Fatal(e) } dir := t.TempDir() path := filepath.Join(dir, "audit.json") verifier := g.AuditVerifier{Path: path, PublicKey: pub, Scope: "target", GatewayID: "gateway"} if verifier.Verify(context.Background()) == nil { t.Fatal("missing audit accepted") } if os.WriteFile(path, []byte(`{"isolated":true,"ready":true}`), 0600) != nil { t.Fatal("fixture") } if verifier.Verify(context.Background()) == nil { t.Fatal("boolean accepted as isolation proof") } a := g.Attestation{Protocol: g.Protocol, Scope: "target", GatewayID: "gateway", IssuedAt: time.Now().Add(-time.Minute), ExpiresAt: time.Now().Add(30 * time.Minute), WriterInventory: g.Digest([]byte("inventory")), PolicyEvidence: g.Digest([]byte("policy")), DenialEvidence: g.Digest([]byte("denials")), DrainEvidence: g.Digest([]byte("drain"))} write := func(v g.Attestation) { t.Helper() raw, _ := json.Marshal(v) signed, _ := json.Marshal(g.SignedAttestation{Payload: raw, Signature: ed25519.Sign(priv, raw)}) if os.WriteFile(path, signed, 0600) != nil { t.Fatal("fixture") } } write(a) if verifier.Verify(context.Background()) != nil { t.Fatal("valid test auditor signature rejected") } for _, mutate := range []func(*g.Attestation){func(v *g.Attestation) { v.Scope = "other" }, func(v *g.Attestation) { v.GatewayID = "other" }, func(v *g.Attestation) { v.ExpiresAt = time.Now().Add(-time.Second) }, func(v *g.Attestation) { v.DenialEvidence = "" }, func(v *g.Attestation) { v.IssuedAt = time.Now().Add(time.Hour) }, func(v *g.Attestation) { v.ExpiresAt = time.Now().Add(24 * time.Hour) }} { bad := a mutate(&bad) write(bad) if verifier.Verify(context.Background()) == nil { t.Fatal("invalid isolation audit accepted") } } write(a) other, _, _ := ed25519.GenerateKey(rand.Reader) verifier.PublicKey = other if verifier.Verify(context.Background()) == nil { t.Fatal("untrusted signer accepted") } }