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

Function TestAppsecEventToContext

pkg/alertcontext/alertcontext_test.go:241–399  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

239}
240
241func TestAppsecEventToContext(t *testing.T) {
242 tests := []struct {
243 name string
244 contextToSend map[string][]string
245 match pipeline.AppsecEvent
246 req *http.Request
247 expectedResult models.Meta
248 expectedErrLen int
249 }{
250 {
251 name: "basic test on match",
252 contextToSend: map[string][]string{
253 "id": {"match.id"},
254 },
255 match: pipeline.AppsecEvent{
256 MatchedRules: pipeline.MatchedRules{
257 {
258 "id": "test",
259 },
260 },
261 },
262 req: &http.Request{},
263 expectedResult: []*models.MetaItems0{
264 {
265 Key: "id",
266 Value: "[\"test\"]",
267 },
268 },
269 expectedErrLen: 0,
270 },
271 {
272 name: "basic test on req",
273 contextToSend: map[string][]string{
274 "ua": {"req.UserAgent()"},
275 },
276 match: pipeline.AppsecEvent{
277 MatchedRules: pipeline.MatchedRules{
278 {
279 "id": "test",
280 },
281 },
282 },
283 req: &http.Request{
284 Header: map[string][]string{
285 "User-Agent": {"test"},
286 },
287 },
288 expectedResult: []*models.MetaItems0{
289 {
290 Key: "ua",
291 Value: "[\"test\"]",
292 },
293 },
294 expectedErrLen: 0,
295 },
296 {
297 name: "test on req -> []string",
298 contextToSend: map[string][]string{

Callers

nothing calls this directly

Calls 3

NewAlertContextFunction · 0.85
AppsecEventToContextFunction · 0.85
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…