mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	优化测试用例
This commit is contained in:
		@@ -13,6 +13,7 @@ import (
 | 
			
		||||
	"mime/multipart"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"net/url"
 | 
			
		||||
	"runtime"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"testing"
 | 
			
		||||
	"time"
 | 
			
		||||
@@ -66,6 +67,8 @@ func Test_Template2(t *testing.T) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func BenchmarkTemplate(b *testing.B) {
 | 
			
		||||
	runtime.GOMAXPROCS(4)
 | 
			
		||||
 | 
			
		||||
	wafInstance, err := waf.Template()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		b.Fatal(err)
 | 
			
		||||
@@ -73,8 +76,9 @@ func BenchmarkTemplate(b *testing.B) {
 | 
			
		||||
 | 
			
		||||
	b.ResetTimer()
 | 
			
		||||
 | 
			
		||||
	for i := 0; i < b.N; i++ {
 | 
			
		||||
		req, err := http.NewRequest(http.MethodGet, "https://example.com/index.php?id=123", nil)
 | 
			
		||||
	b.RunParallel(func(pb *testing.PB) {
 | 
			
		||||
		for pb.Next() {
 | 
			
		||||
			req, err := http.NewRequest(http.MethodGet, "https://example.com/index.php?id=123"+types.String(rand.Int()%10000), nil)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				b.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
@@ -82,6 +86,7 @@ func BenchmarkTemplate(b *testing.B) {
 | 
			
		||||
 | 
			
		||||
			_, _, _, _, _ = wafInstance.MatchRequest(requests.NewTestRequest(req), nil, firewallconfigs.ServerCaptchaTypeNone)
 | 
			
		||||
		}
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func testTemplate1010(a *assert.Assertion, t *testing.T, template *waf.WAF) {
 | 
			
		||||
@@ -430,3 +435,35 @@ func testTemplate20001(a *assert.Assertion, t *testing.T, template *waf.WAF) {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func BenchmarkTemplatePathTraversal(b *testing.B) {
 | 
			
		||||
	runtime.GOMAXPROCS(4)
 | 
			
		||||
 | 
			
		||||
	template, err := waf.Template()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		b.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	var group = template.FindRuleGroupWithCode("pathTraversal")
 | 
			
		||||
	if group == nil {
 | 
			
		||||
		b.Fatal("group not found")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	b.ResetTimer()
 | 
			
		||||
 | 
			
		||||
	b.RunParallel(func(pb *testing.PB) {
 | 
			
		||||
		for pb.Next() {
 | 
			
		||||
			req, err := http.NewRequest(http.MethodPost, "https://example.com/?id=1234"+types.String(rand.Int()%10000)+"&name=lily&time=12345678910", nil)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				b.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
			req.Header.Set("User-Agent", testUserAgent)
 | 
			
		||||
 | 
			
		||||
			_, _, result, err := group.MatchRequest(requests.NewTestRequest(req))
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				b.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
			_ = result
 | 
			
		||||
		}
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user