MCPcopy Index your code
hub / github.com/crowdsecurity/crowdsec / TestLoadByPathMultiFileLoading

Function TestLoadByPathMultiFileLoading

pkg/appsec/appsec_config_test.go:159–195  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

157}
158
159func TestLoadByPathMultiFileLoading(t *testing.T) {
160 cfg := newTestConfig()
161
162 // First file: old format
163 f1 := writeTempYAML(t, `
164name: test-multi
165inband_rules:
166 - crowdsecurity/base-config
167on_match:
168 - filter: "IsInBand == true"
169 apply:
170 - SendAlert()
171`)
172
173 // Second file: new format
174 dir := t.TempDir()
175 f2 := filepath.Join(dir, "config2.yaml")
176 require.NoError(t, os.WriteFile(f2, []byte(`
177inband:
178 rules:
179 - crowdsecurity/vpatch-*
180 on_match:
181 - apply:
182 - SetReturnCode(413)
183`), 0o644))
184
185 require.NoError(t, cfg.LoadByPath(f1))
186 require.NoError(t, cfg.LoadByPath(f2))
187
188 // Rules merged from both files
189 assert.Equal(t, []string{"crowdsecurity/base-config", "crowdsecurity/vpatch-*"}, cfg.InBandRules)
190 // Shared hook from file 1
191 assert.Len(t, cfg.OnMatch, 1)
192 // Phase-scoped hook from file 2
193 require.NotNil(t, cfg.InBand)
194 assert.Len(t, cfg.InBand.OnMatch, 1)
195}
196
197func TestLoadByPathPhaseOptionsOverride(t *testing.T) {
198 cfg := newTestConfig()

Callers

nothing calls this directly

Calls 4

newTestConfigFunction · 0.85
writeTempYAMLFunction · 0.85
LoadByPathMethod · 0.80
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…