MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / testTemplate20001

Function testTemplate20001

internal/waf/template_test.go:402–437  ·  view source on GitHub ↗
(a *assert.Assertion, t *testing.T, template *waf.WAF)

Source from the content-addressed store, hash-verified

400}
401
402func testTemplate20001(a *assert.Assertion, t *testing.T, template *waf.WAF) {
403 // enable bot rule set
404 for _, g := range template.Inbound {
405 if g.Code == "bot" {
406 g.IsOn = true
407 break
408 }
409 }
410
411 for _, bot := range []string{
412 "Googlebot",
413 "AdsBot-Google",
414 "bingbot",
415 "BingPreview",
416 "facebookexternalhit",
417 "Slurp",
418 "Sogou",
419 "Baiduspider http://baidu.com",
420 } {
421 req, err := http.NewRequest(http.MethodPost, "http://example.com/", nil)
422 if err != nil {
423 t.Fatal(err)
424 }
425 req.Header.Set("User-Agent", bot)
426 result, err := template.MatchRequest(requests.NewTestRequest(req), nil, firewallconfigs.ServerCaptchaTypeNone)
427 if err != nil {
428 t.Fatal(err)
429 }
430 a.IsNotNil(result.Set)
431 if result.Set != nil {
432 a.IsTrue(lists.ContainsAny([]string{"20001"}, result.Set.Code))
433 } else {
434 t.Log("break:", bot)
435 }
436 }
437}
438
439func BenchmarkTemplatePathTraversal(b *testing.B) {
440 runtime.GOMAXPROCS(4)

Callers 1

Test_TemplateFunction · 0.85

Calls 4

NewTestRequestFunction · 0.92
LogMethod · 0.80
SetMethod · 0.45
MatchRequestMethod · 0.45

Tested by

no test coverage detected