TestUpdateAgentScanConfigValidation rejects invalid postures with a clean error instead of a raw CHECK violation.
(t *testing.T)
| 83 | // TestUpdateAgentScanConfigValidation rejects invalid postures with a clean error |
| 84 | // instead of a raw CHECK violation. |
| 85 | func TestUpdateAgentScanConfigValidation(t *testing.T) { |
| 86 | pool := testutil.TestDB(t) |
| 87 | store := identity.NewStore(pool) |
| 88 | ctx := context.Background() |
| 89 | |
| 90 | user, _ := store.CreateOrGetUser(ctx, "owner@scanv.example.com", "Owner", "google-scanv") |
| 91 | if _, err := store.ClaimOrCreateDomain(ctx, "scanv.example.com", user.ID); err != nil { |
| 92 | t.Fatalf("ClaimOrCreateDomain: %v", err) |
| 93 | } |
| 94 | agent, err := store.CreateAgent(ctx, "agent@scanv.example.com", "scanv.example.com", "", "", "", user.ID) |
| 95 | if err != nil { |
| 96 | t.Fatalf("CreateAgent: %v", err) |
| 97 | } |
| 98 | |
| 99 | base := identity.ScanConfig{ |
| 100 | InboundPolicyAction: "flag", OutboundPolicy: "open", OutboundPolicyAction: "flag", |
| 101 | InboundScan: "off", OutboundScan: "off", |
| 102 | InboundScanReviewThreshold: 0.5, InboundScanBlockThreshold: 0.9, |
| 103 | OutboundScanReviewThreshold: 0.5, OutboundScanBlockThreshold: 0.9, |
| 104 | } |
| 105 | mut := func(f func(*identity.ScanConfig)) identity.ScanConfig { |
| 106 | c := base |
| 107 | f(&c) |
| 108 | return c |
| 109 | } |
| 110 | cases := map[string]identity.ScanConfig{ |
| 111 | "invalid action": mut(func(c *identity.ScanConfig) { c.InboundPolicyAction = "nope" }), |
| 112 | "verified_only not outbound": mut(func(c *identity.ScanConfig) { c.OutboundPolicy = "verified_only" }), |
| 113 | "invalid scan toggle": mut(func(c *identity.ScanConfig) { c.InboundScan = "maybe" }), |
| 114 | "review > block": mut(func(c *identity.ScanConfig) { c.InboundScanReviewThreshold = 0.95; c.InboundScanBlockThreshold = 0.5 }), |
| 115 | "threshold out of range": mut(func(c *identity.ScanConfig) { c.OutboundScanBlockThreshold = 1.5 }), |
| 116 | } |
| 117 | for name, c := range cases { |
| 118 | if err := store.UpdateAgentScanConfig(ctx, agent.ID, user.ID, c); err == nil { |
| 119 | t.Errorf("%s: expected validation error, got nil", name) |
| 120 | } |
| 121 | } |
| 122 | } |
nothing calls this directly
no test coverage detected