--- /dev/null
+package front
+
+import (
+ "context"
+ "net/http"
+ "testing"
+ "time"
+
+ "github.com/qydysky/front/filiter"
+ plog "github.com/qydysky/part/log"
+ reqf "github.com/qydysky/part/reqf"
+)
+
+var logger = plog.New(plog.Config{
+ Stdout: true,
+ Prefix_string: map[string]struct{}{
+ `T:`: plog.On,
+ `I:`: plog.On,
+ `W:`: plog.On,
+ `E:`: plog.On,
+ },
+})
+
+func Test_Uri(t *testing.T) {
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+
+ conf := &Config{
+ Addr: "127.0.0.1:19000",
+ Routes: []Route{
+ {
+ Path: []string{"/"},
+ PathAdd: true,
+ Setting: Setting{
+ Filiter: filiter.Filiter{
+ ReqUri: filiter.Uri{
+ AccessRule: "!{go}",
+ Items: map[string]string{
+ "go": "\\.go$",
+ },
+ },
+ },
+ },
+ Backs: []Back{
+ {
+ Name: "1",
+ To: "./",
+ Weight: 1,
+ },
+ },
+ },
+ },
+ }
+
+ go conf.Run(ctx, logger)
+
+ time.Sleep(time.Second)
+
+ r := reqf.New()
+ if e := r.Reqf(reqf.Rval{
+ Url: "http://127.0.0.1:19000/config_test.go",
+ }); e != nil {
+ if r.Response.StatusCode != http.StatusForbidden {
+ t.Fail()
+ }
+ } else {
+ t.Fail()
+ }
+
+ conf.Routes[0].Setting.Filiter.ReqUri.AccessRule = "{go}"
+
+ if e := r.Reqf(reqf.Rval{
+ Url: "http://127.0.0.1:19000/config_test.go",
+ }); e != nil {
+ t.Fail()
+ }
+}
+
+func Test_Back(t *testing.T) {
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+
+ conf := &Config{
+ Addr: "127.0.0.1:19000",
+ Routes: []Route{
+ {
+ Path: []string{"/"},
+ PathAdd: true,
+ Backs: []Back{},
+ },
+ },
+ }
+
+ go conf.Run(ctx, logger)
+
+ time.Sleep(time.Second)
+
+ r := reqf.New()
+ if e := r.Reqf(reqf.Rval{
+ Url: "http://127.0.0.1:19000/config_test.go",
+ }); e != nil {
+ if r.Response.StatusCode != http.StatusNotFound {
+ t.Fail()
+ }
+ } else {
+ t.Fail()
+ }
+
+ conf.Routes[0].Backs = append(conf.Routes[0].Backs,
+ Back{
+ Name: "1",
+ To: "./",
+ Weight: 1,
+ },
+ )
+ conf.SwapSign(ctx, logger)
+
+ if e := r.Reqf(reqf.Rval{
+ Url: "http://127.0.0.1:19000/config_test.go",
+ }); e != nil {
+ t.Fail()
+ }
+
+ conf.Routes[0].Backs = conf.Routes[0].Backs[:0]
+ conf.SwapSign(ctx, logger)
+
+ if e := r.Reqf(reqf.Rval{
+ Url: "http://127.0.0.1:19000/config_test.go",
+ }); e != nil {
+ if r.Response.StatusCode != http.StatusNotFound {
+ t.Fail()
+ }
+ } else {
+ t.Fail()
+ }
+}
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
+ github.com/qydysky/brotli v0.0.0-20240828134800-e9913a6e7ed9 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY=
github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE=
+github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
+github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=