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

45 lines
1.1 KiB
Go
Raw Permalink Normal View History

2020-10-08 15:06:42 +08:00
package checkpoints
import (
"net/http"
"testing"
2024-07-27 15:42:50 +08:00
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
"github.com/iwind/TeaGo/maps"
2020-10-08 15:06:42 +08:00
)
func TestCCCheckpoint_RequestValue(t *testing.T) {
raw, err := http.NewRequest(http.MethodGet, "http://teaos.cn/", nil)
if err != nil {
t.Fatal(err)
}
2021-07-18 15:51:49 +08:00
req := requests.NewTestRequest(raw)
req.WAFRaw().RemoteAddr = "127.0.0.1"
2020-10-08 15:06:42 +08:00
checkpoint := new(CCCheckpoint)
checkpoint.Init()
checkpoint.Start()
2021-07-18 15:51:49 +08:00
options := maps.Map{
2020-10-08 15:06:42 +08:00
"period": "5",
}
t.Log(checkpoint.RequestValue(req, "requests", options, 1))
t.Log(checkpoint.RequestValue(req, "requests", options, 1))
2020-10-08 15:06:42 +08:00
2021-07-18 15:51:49 +08:00
req.WAFRaw().RemoteAddr = "127.0.0.2"
t.Log(checkpoint.RequestValue(req, "requests", options, 1))
2020-10-08 15:06:42 +08:00
2021-07-18 15:51:49 +08:00
req.WAFRaw().RemoteAddr = "127.0.0.1"
t.Log(checkpoint.RequestValue(req, "requests", options, 1))
2020-10-08 15:06:42 +08:00
2021-07-18 15:51:49 +08:00
req.WAFRaw().RemoteAddr = "127.0.0.2"
t.Log(checkpoint.RequestValue(req, "requests", options, 1))
2020-10-08 15:06:42 +08:00
2021-07-18 15:51:49 +08:00
req.WAFRaw().RemoteAddr = "127.0.0.2"
t.Log(checkpoint.RequestValue(req, "requests", options, 1))
2020-10-08 15:06:42 +08:00
2021-07-18 15:51:49 +08:00
req.WAFRaw().RemoteAddr = "127.0.0.2"
t.Log(checkpoint.RequestValue(req, "requests", options, 1))
2020-10-08 15:06:42 +08:00
}