github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/request_body_test.go (about) 1 package checkpoints 2 3 import ( 4 "bytes" 5 "github.com/TeaOSLab/EdgeNode/internal/waf/requests" 6 "github.com/iwind/TeaGo/types" 7 "io" 8 "net/http" 9 "strings" 10 "testing" 11 ) 12 13 func TestRequestBodyCheckpoint_RequestValue(t *testing.T) { 14 rawReq, err := http.NewRequest(http.MethodPost, "http://teaos.cn", bytes.NewBuffer([]byte("123456"))) 15 if err != nil { 16 t.Fatal(err) 17 } 18 var req = requests.NewTestRequest(rawReq) 19 checkpoint := new(RequestBodyCheckpoint) 20 t.Log(checkpoint.RequestValue(req, "", nil, 1)) 21 22 body, err := io.ReadAll(rawReq.Body) 23 if err != nil { 24 t.Fatal(err) 25 } 26 t.Log(string(body)) 27 t.Log(string(req.WAFGetCacheBody())) 28 } 29 30 func TestRequestBodyCheckpoint_RequestValue_Max(t *testing.T) { 31 req, err := http.NewRequest(http.MethodPost, "http://teaos.cn", bytes.NewBuffer([]byte(strings.Repeat("123456", 10240000)))) 32 if err != nil { 33 t.Fatal(err) 34 } 35 36 checkpoint := new(RequestBodyCheckpoint) 37 value, _, err, _ := checkpoint.RequestValue(requests.NewTestRequest(req), "", nil, 1) 38 if err != nil { 39 t.Fatal(err) 40 } 41 t.Log("value bytes:", len(types.String(value))) 42 43 body, err := io.ReadAll(req.Body) 44 if err != nil { 45 t.Fatal(err) 46 } 47 t.Log("raw bytes:", len(body)) 48 }