2020-10-08 15:06:42 +08:00
|
|
|
package checkpoints
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
|
|
|
|
"github.com/iwind/TeaGo/types"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"net/http"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestRequestBodyCheckpoint_RequestValue(t *testing.T) {
|
2021-07-18 15:51:49 +08:00
|
|
|
rawReq, err := http.NewRequest(http.MethodPost, "http://teaos.cn", bytes.NewBuffer([]byte("123456")))
|
2020-10-08 15:06:42 +08:00
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2021-07-18 15:51:49 +08:00
|
|
|
var req = requests.NewTestRequest(rawReq)
|
2020-10-08 15:06:42 +08:00
|
|
|
checkpoint := new(RequestBodyCheckpoint)
|
2022-07-25 09:34:34 +08:00
|
|
|
t.Log(checkpoint.RequestValue(req, "", nil, 1))
|
2020-10-08 15:06:42 +08:00
|
|
|
|
2021-07-18 15:51:49 +08:00
|
|
|
body, err := ioutil.ReadAll(rawReq.Body)
|
2020-10-08 15:06:42 +08:00
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
t.Log(string(body))
|
2021-07-18 15:51:49 +08:00
|
|
|
t.Log(string(req.WAFGetCacheBody()))
|
2020-10-08 15:06:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRequestBodyCheckpoint_RequestValue_Max(t *testing.T) {
|
|
|
|
|
req, err := http.NewRequest(http.MethodPost, "http://teaos.cn", bytes.NewBuffer([]byte(strings.Repeat("123456", 10240000))))
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkpoint := new(RequestBodyCheckpoint)
|
2022-07-25 09:34:34 +08:00
|
|
|
value, _, err, _ := checkpoint.RequestValue(requests.NewTestRequest(req), "", nil, 1)
|
2020-10-08 15:06:42 +08:00
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
t.Log("value bytes:", len(types.String(value)))
|
|
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(req.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
t.Log("raw bytes:", len(body))
|
|
|
|
|
}
|