TestUpdateAgentProtectionValidation rejects invalid postures with a clean error.
(t *testing.T)
| 129 | |
| 130 | // TestUpdateAgentProtectionValidation rejects invalid postures with a clean error. |
| 131 | func 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). |
nothing calls this directly
no test coverage detected