(t *testing.T)
| 239 | } |
| 240 | |
| 241 | func 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{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…