github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/request_form_arg_test.go (about) 1 package checkpoints 2 3 import ( 4 "bytes" 5 "github.com/TeaOSLab/EdgeNode/internal/waf/requests" 6 "io" 7 "net/http" 8 "net/url" 9 "testing" 10 ) 11 12 func TestRequestFormArgCheckpoint_RequestValue(t *testing.T) { 13 rawReq, err := http.NewRequest(http.MethodPost, "http://teaos.cn", bytes.NewBuffer([]byte("name=lu&age=20&encoded="+url.QueryEscape("<strong>ENCODED STRING</strong>")))) 14 if err != nil { 15 t.Fatal(err) 16 } 17 18 req := requests.NewTestRequest(rawReq) 19 req.WAFRaw().Header.Set("Content-Type", "application/x-www-form-urlencoded") 20 21 checkpoint := new(RequestFormArgCheckpoint) 22 t.Log(checkpoint.RequestValue(req, "name", nil, 1)) 23 t.Log(checkpoint.RequestValue(req, "age", nil, 1)) 24 t.Log(checkpoint.RequestValue(req, "Hello", nil, 1)) 25 t.Log(checkpoint.RequestValue(req, "encoded", nil, 1)) 26 27 body, err := io.ReadAll(req.WAFRaw().Body) 28 if err != nil { 29 t.Fatal(err) 30 } 31 t.Log(string(body)) 32 }