Files
EdgeNode/internal/waf/checkpoints/request_form_arg_test.go

34 lines
889 B
Go
Raw Normal View History

2020-10-08 15:06:42 +08:00
package checkpoints
import (
"bytes"
2022-08-04 11:34:06 +08:00
"io"
2020-10-08 15:06:42 +08:00
"net/http"
"net/url"
"testing"
2024-07-27 15:42:50 +08:00
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
2020-10-08 15:06:42 +08:00
)
func TestRequestFormArgCheckpoint_RequestValue(t *testing.T) {
rawReq, err := http.NewRequest(http.MethodPost, "http://teaos.cn", bytes.NewBuffer([]byte("name=lu&age=20&encoded="+url.QueryEscape("<strong>ENCODED STRING</strong>"))))
if err != nil {
t.Fatal(err)
}
2021-07-18 15:51:49 +08:00
req := requests.NewTestRequest(rawReq)
req.WAFRaw().Header.Set("Content-Type", "application/x-www-form-urlencoded")
2020-10-08 15:06:42 +08:00
checkpoint := new(RequestFormArgCheckpoint)
t.Log(checkpoint.RequestValue(req, "name", nil, 1))
t.Log(checkpoint.RequestValue(req, "age", nil, 1))
t.Log(checkpoint.RequestValue(req, "Hello", nil, 1))
t.Log(checkpoint.RequestValue(req, "encoded", nil, 1))
2020-10-08 15:06:42 +08:00
2022-08-04 11:34:06 +08:00
body, err := io.ReadAll(req.WAFRaw().Body)
2020-10-08 15:06:42 +08:00
if err != nil {
t.Fatal(err)
}
t.Log(string(body))
}