github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/cc_test.go (about)

     1  package checkpoints
     2  
     3  import (
     4  	"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
     5  	"github.com/iwind/TeaGo/maps"
     6  	"net/http"
     7  	"testing"
     8  )
     9  
    10  func TestCCCheckpoint_RequestValue(t *testing.T) {
    11  	raw, err := http.NewRequest(http.MethodGet, "http://teaos.cn/", nil)
    12  	if err != nil {
    13  		t.Fatal(err)
    14  	}
    15  
    16  	req := requests.NewTestRequest(raw)
    17  	req.WAFRaw().RemoteAddr = "127.0.0.1"
    18  
    19  	checkpoint := new(CCCheckpoint)
    20  	checkpoint.Init()
    21  	checkpoint.Start()
    22  
    23  	options := maps.Map{
    24  		"period": "5",
    25  	}
    26  	t.Log(checkpoint.RequestValue(req, "requests", options, 1))
    27  	t.Log(checkpoint.RequestValue(req, "requests", options, 1))
    28  
    29  	req.WAFRaw().RemoteAddr = "127.0.0.2"
    30  	t.Log(checkpoint.RequestValue(req, "requests", options, 1))
    31  
    32  	req.WAFRaw().RemoteAddr = "127.0.0.1"
    33  	t.Log(checkpoint.RequestValue(req, "requests", options, 1))
    34  
    35  	req.WAFRaw().RemoteAddr = "127.0.0.2"
    36  	t.Log(checkpoint.RequestValue(req, "requests", options, 1))
    37  
    38  	req.WAFRaw().RemoteAddr = "127.0.0.2"
    39  	t.Log(checkpoint.RequestValue(req, "requests", options, 1))
    40  
    41  	req.WAFRaw().RemoteAddr = "127.0.0.2"
    42  	t.Log(checkpoint.RequestValue(req, "requests", options, 1))
    43  }