MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestUpdateAgentProtectionValidation

Function TestUpdateAgentProtectionValidation

internal/identity/protection_test.go:131–159  ·  view source on GitHub ↗

TestUpdateAgentProtectionValidation rejects invalid postures with a clean error.

(t *testing.T)

Source from the content-addressed store, hash-verified

129
130// TestUpdateAgentProtectionValidation rejects invalid postures with a clean error.
131func TestUpdateAgentProtectionValidation(t *testing.T) {
132 store, ctx, agentID, userID := newProtectionAgent(t, "prot-val")
133
134 base := identity.ProtectionConfig{
135 InboundGatePolicy: "open", InboundGateAction: "flag", InboundScanSensitivity: "off",
136 OutboundGatePolicy: "open", OutboundGateAction: "flag", OutboundScanSensitivity: "off",
137 HITLTTLSeconds: 604800, HITLExpirationAction: "reject",
138 }
139 mut := func(f func(*identity.ProtectionConfig)) identity.ProtectionConfig {
140 c := base
141 f(&c)
142 return c
143 }
144 cases := map[string]identity.ProtectionConfig{
145 "verified_only not a gate value": mut(func(c *identity.ProtectionConfig) { c.InboundGatePolicy = "verified_only" }),
146 "bad inbound gate policy": mut(func(c *identity.ProtectionConfig) { c.InboundGatePolicy = "nope" }),
147 "bad outbound gate policy": mut(func(c *identity.ProtectionConfig) { c.OutboundGatePolicy = "verified_only" }),
148 "bad gate action": mut(func(c *identity.ProtectionConfig) { c.OutboundGateAction = "drop" }),
149 "bad sensitivity": mut(func(c *identity.ProtectionConfig) { c.InboundScanSensitivity = "extreme" }),
150 "negative ttl": mut(func(c *identity.ProtectionConfig) { c.HITLTTLSeconds = -1 }),
151 "bad on_expiry": mut(func(c *identity.ProtectionConfig) { c.HITLExpirationAction = "defer" }),
152 "allowlist over cap": mut(func(c *identity.ProtectionConfig) { c.InboundAllowlist = makeAllowlist(1001) }),
153 }
154 for name, c := range cases {
155 if err := store.UpdateAgentProtection(ctx, agentID, userID, c); err == nil {
156 t.Errorf("%s: expected validation error, got nil", name)
157 }
158 }
159}
160
161// TestUpdateAgentProtectionWrongOwner: a config write keyed to a non-owner is a
162// no-op that errors (tenant isolation at the store layer).

Callers

nothing calls this directly

Calls 3

newProtectionAgentFunction · 0.85
makeAllowlistFunction · 0.85
UpdateAgentProtectionMethod · 0.80

Tested by

no test coverage detected