MCPcopy
hub / github.com/crowdsecurity/crowdsec / createDecision

Function createDecision

pkg/database/allowlists_test.go:173–193  ·  view source on GitHub ↗

createDecision is a test helper that creates a decision directly via ent, bypassing the full alert pipeline.

(t *testing.T, ctx context.Context, client *ent.Client, value string, until time.Time)

Source from the content-addressed store, hash-verified

171// createDecision is a test helper that creates a decision directly via ent,
172// bypassing the full alert pipeline.
173func createDecision(t *testing.T, ctx context.Context, client *ent.Client, value string, until time.Time) {
174 t.Helper()
175
176 rng, err := csnet.NewRange(value)
177 require.NoError(t, err)
178
179 _, err = client.Decision.Create().
180 SetUntil(until).
181 SetScenario("test").
182 SetType("ban").
183 SetScope("Ip").
184 SetValue(value).
185 SetOrigin("test").
186 SetIPSize(int64(rng.Size())).
187 SetStartIP(rng.Start.Addr).
188 SetStartSuffix(rng.Start.Sfx).
189 SetEndIP(rng.End.Addr).
190 SetEndSuffix(rng.End.Sfx).
191 Save(ctx)
192 require.NoError(t, err)
193}
194
195func TestApplyAllowlistsToExistingDecisions(t *testing.T) {
196 future := time.Now().UTC().Add(24 * time.Hour)

Calls 15

SizeMethod · 0.95
NewRangeFunction · 0.92
SaveMethod · 0.45
SetEndSuffixMethod · 0.45
SetEndIPMethod · 0.45
SetStartSuffixMethod · 0.45
SetStartIPMethod · 0.45
SetIPSizeMethod · 0.45
SetOriginMethod · 0.45
SetValueMethod · 0.45
SetScopeMethod · 0.45
SetTypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…