lint by golangci-lint (#3080)

This commit is contained in:
fatedier
2022-08-29 01:02:53 +08:00
committed by GitHub
parent f4e4fbea62
commit 9d077b02cf
122 changed files with 947 additions and 1331 deletions

View File

@@ -5,6 +5,8 @@ import (
"fmt"
"strings"
"github.com/onsi/ginkgo"
"github.com/fatedier/frp/pkg/transport"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
@@ -12,18 +14,16 @@ import (
"github.com/fatedier/frp/test/e2e/mock/server/streamserver"
"github.com/fatedier/frp/test/e2e/pkg/port"
"github.com/fatedier/frp/test/e2e/pkg/request"
. "github.com/onsi/ginkgo"
)
var _ = Describe("[Feature: Basic]", func() {
var _ = ginkgo.Describe("[Feature: Basic]", func() {
f := framework.NewDefaultFramework()
Describe("TCP && UDP", func() {
ginkgo.Describe("TCP && UDP", func() {
types := []string{"tcp", "udp"}
for _, t := range types {
proxyType := t
It(fmt.Sprintf("Expose a %s echo server", strings.ToUpper(proxyType)), func() {
ginkgo.It(fmt.Sprintf("Expose a %s echo server", strings.ToUpper(proxyType)), func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
@@ -93,8 +93,8 @@ var _ = Describe("[Feature: Basic]", func() {
}
})
Describe("HTTP", func() {
It("proxy to HTTP server", func() {
ginkgo.Describe("HTTP", func() {
ginkgo.It("proxy to HTTP server", func() {
serverConf := consts.DefaultServerConfig
vhostHTTPPort := f.AllocPort()
serverConf += fmt.Sprintf(`
@@ -175,8 +175,8 @@ var _ = Describe("[Feature: Basic]", func() {
})
})
Describe("HTTPS", func() {
It("proxy to HTTPS server", func() {
ginkgo.Describe("HTTPS", func() {
ginkgo.It("proxy to HTTPS server", func() {
serverConf := consts.DefaultServerConfig
vhostHTTPSPort := f.AllocPort()
serverConf += fmt.Sprintf(`
@@ -237,7 +237,7 @@ var _ = Describe("[Feature: Basic]", func() {
framework.ExpectNoError(err)
localServer := httpserver.New(
httpserver.WithBindPort(localPort),
httpserver.WithTlsConfig(tlsConfig),
httpserver.WithTLSConfig(tlsConfig),
httpserver.WithResponse([]byte("test")),
)
f.RunServer("", localServer)
@@ -275,11 +275,11 @@ var _ = Describe("[Feature: Basic]", func() {
})
})
Describe("STCP && SUDP", func() {
ginkgo.Describe("STCP && SUDP", func() {
types := []string{"stcp", "sudp"}
for _, t := range types {
proxyType := t
It(fmt.Sprintf("Expose echo server with %s", strings.ToUpper(proxyType)), func() {
ginkgo.It(fmt.Sprintf("Expose echo server with %s", strings.ToUpper(proxyType)), func() {
serverConf := consts.DefaultServerConfig
clientServerConf := consts.DefaultClientConfig
clientVisitorConf := consts.DefaultClientConfig
@@ -381,8 +381,8 @@ var _ = Describe("[Feature: Basic]", func() {
}
})
Describe("TCPMUX", func() {
It("Type tcpmux", func() {
ginkgo.Describe("TCPMUX", func() {
ginkgo.It("Type tcpmux", func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig

View File

@@ -6,18 +6,18 @@ import (
"strings"
"time"
"github.com/onsi/ginkgo"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
"github.com/fatedier/frp/test/e2e/pkg/request"
clientsdk "github.com/fatedier/frp/test/e2e/pkg/sdk/client"
. "github.com/onsi/ginkgo"
)
var _ = Describe("[Feature: ClientManage]", func() {
var _ = ginkgo.Describe("[Feature: ClientManage]", func() {
f := framework.NewDefaultFramework()
It("Update && Reload API", func() {
ginkgo.It("Update && Reload API", func() {
serverConf := consts.DefaultServerConfig
adminPort := f.AllocPort()
@@ -62,7 +62,9 @@ var _ = Describe("[Feature: ClientManage]", func() {
// change p2 port and remove p3 proxy
newClientConf := strings.ReplaceAll(conf, strconv.Itoa(p2Port), strconv.Itoa(newP2Port))
p3Index := strings.Index(newClientConf, "[p3]")
newClientConf = newClientConf[:p3Index]
if p3Index >= 0 {
newClientConf = newClientConf[:p3Index]
}
err = client.UpdateConfig(newClientConf)
framework.ExpectNoError(err)
@@ -77,7 +79,7 @@ var _ = Describe("[Feature: ClientManage]", func() {
framework.NewRequestExpect(f).Port(p3Port).Explain("p3 port").ExpectError(true).Ensure()
})
It("healthz", func() {
ginkgo.It("healthz", func() {
serverConf := consts.DefaultServerConfig
dashboardPort := f.AllocPort()
@@ -99,5 +101,4 @@ var _ = Describe("[Feature: ClientManage]", func() {
}).Port(dashboardPort).
Ensure(framework.ExpectResponseCode(401))
})
})

View File

@@ -4,12 +4,12 @@ import (
"fmt"
"strings"
"github.com/onsi/ginkgo"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
"github.com/fatedier/frp/test/e2e/pkg/cert"
"github.com/fatedier/frp/test/e2e/pkg/port"
. "github.com/onsi/ginkgo"
)
type generalTestConfigures struct {
@@ -54,15 +54,15 @@ func runClientServerTest(f *framework.Framework, configures *generalTestConfigur
// defineClientServerTest test a normal tcp and udp proxy with specified TestConfigures.
func defineClientServerTest(desc string, f *framework.Framework, configures *generalTestConfigures) {
It(desc, func() {
ginkgo.It(desc, func() {
runClientServerTest(f, configures)
})
}
var _ = Describe("[Feature: Client-Server]", func() {
var _ = ginkgo.Describe("[Feature: Client-Server]", func() {
f := framework.NewDefaultFramework()
Describe("Protocol", func() {
ginkgo.Describe("Protocol", func() {
supportProtocols := []string{"tcp", "kcp", "websocket"}
for _, protocol := range supportProtocols {
configures := &generalTestConfigures{
@@ -76,7 +76,7 @@ var _ = Describe("[Feature: Client-Server]", func() {
}
})
Describe("Authentication", func() {
ginkgo.Describe("Authentication", func() {
defineClientServerTest("Token Correct", f, &generalTestConfigures{
server: "token = 123456",
client: "token = 123456",
@@ -89,7 +89,7 @@ var _ = Describe("[Feature: Client-Server]", func() {
})
})
Describe("TLS", func() {
ginkgo.Describe("TLS", func() {
supportProtocols := []string{"tcp", "kcp", "websocket"}
for _, protocol := range supportProtocols {
tmp := protocol
@@ -114,7 +114,7 @@ var _ = Describe("[Feature: Client-Server]", func() {
})
})
Describe("TLS with custom certificate", func() {
ginkgo.Describe("TLS with custom certificate", func() {
supportProtocols := []string{"tcp", "kcp", "websocket"}
var (
@@ -122,7 +122,7 @@ var _ = Describe("[Feature: Client-Server]", func() {
serverCrtPath, serverKeyPath string
clientCrtPath, clientKeyPath string
)
JustBeforeEach(func() {
ginkgo.JustBeforeEach(func() {
generator := &cert.SelfSignedCertGenerator{}
artifacts, err := generator.Generate("0.0.0.0")
framework.ExpectNoError(err)
@@ -131,7 +131,8 @@ var _ = Describe("[Feature: Client-Server]", func() {
serverCrtPath = f.WriteTempFile("server.crt", string(artifacts.Cert))
serverKeyPath = f.WriteTempFile("server.key", string(artifacts.Key))
generator.SetCA(artifacts.CACert, artifacts.CAKey)
generator.Generate("0.0.0.0")
_, err = generator.Generate("0.0.0.0")
framework.ExpectNoError(err)
clientCrtPath = f.WriteTempFile("client.crt", string(artifacts.Cert))
clientKeyPath = f.WriteTempFile("client.key", string(artifacts.Key))
})
@@ -139,7 +140,7 @@ var _ = Describe("[Feature: Client-Server]", func() {
for _, protocol := range supportProtocols {
tmp := protocol
It("one-way authentication: "+tmp, func() {
ginkgo.It("one-way authentication: "+tmp, func() {
runClientServerTest(f, &generalTestConfigures{
server: fmt.Sprintf(`
protocol = %s
@@ -155,7 +156,7 @@ var _ = Describe("[Feature: Client-Server]", func() {
})
})
It("mutual authentication: "+tmp, func() {
ginkgo.It("mutual authentication: "+tmp, func() {
runClientServerTest(f, &generalTestConfigures{
server: fmt.Sprintf(`
protocol = %s
@@ -176,13 +177,13 @@ var _ = Describe("[Feature: Client-Server]", func() {
}
})
Describe("TLS with custom certificate and specified server name", func() {
ginkgo.Describe("TLS with custom certificate and specified server name", func() {
var (
caCrtPath string
serverCrtPath, serverKeyPath string
clientCrtPath, clientKeyPath string
)
JustBeforeEach(func() {
ginkgo.JustBeforeEach(func() {
generator := &cert.SelfSignedCertGenerator{}
artifacts, err := generator.Generate("example.com")
framework.ExpectNoError(err)
@@ -191,12 +192,13 @@ var _ = Describe("[Feature: Client-Server]", func() {
serverCrtPath = f.WriteTempFile("server.crt", string(artifacts.Cert))
serverKeyPath = f.WriteTempFile("server.key", string(artifacts.Key))
generator.SetCA(artifacts.CACert, artifacts.CAKey)
generator.Generate("example.com")
_, err = generator.Generate("example.com")
framework.ExpectNoError(err)
clientCrtPath = f.WriteTempFile("client.crt", string(artifacts.Cert))
clientKeyPath = f.WriteTempFile("client.key", string(artifacts.Key))
})
It("mutual authentication", func() {
ginkgo.It("mutual authentication", func() {
runClientServerTest(f, &generalTestConfigures{
server: fmt.Sprintf(`
tls_cert_file = %s
@@ -213,7 +215,7 @@ var _ = Describe("[Feature: Client-Server]", func() {
})
})
It("mutual authentication with incorrect server name", func() {
ginkgo.It("mutual authentication with incorrect server name", func() {
runClientServerTest(f, &generalTestConfigures{
server: fmt.Sprintf(`
tls_cert_file = %s
@@ -232,7 +234,7 @@ var _ = Describe("[Feature: Client-Server]", func() {
})
})
Describe("TLS with disable_custom_tls_first_byte", func() {
ginkgo.Describe("TLS with disable_custom_tls_first_byte", func() {
supportProtocols := []string{"tcp", "kcp", "websocket"}
for _, protocol := range supportProtocols {
tmp := protocol
@@ -250,7 +252,7 @@ var _ = Describe("[Feature: Client-Server]", func() {
}
})
Describe("IPv6 bind address", func() {
ginkgo.Describe("IPv6 bind address", func() {
supportProtocols := []string{"tcp", "kcp", "websocket"}
for _, protocol := range supportProtocols {
tmp := protocol

View File

@@ -5,21 +5,21 @@ import (
"strconv"
"strings"
"github.com/onsi/ginkgo"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/pkg/request"
. "github.com/onsi/ginkgo"
)
const (
ConfigValidStr = "syntax is ok"
)
var _ = Describe("[Feature: Cmd]", func() {
var _ = ginkgo.Describe("[Feature: Cmd]", func() {
f := framework.NewDefaultFramework()
Describe("Verify", func() {
It("frps valid", func() {
ginkgo.Describe("Verify", func() {
ginkgo.It("frps valid", func() {
path := f.GenerateConfigFile(`
[common]
bind_addr = 0.0.0.0
@@ -29,7 +29,7 @@ var _ = Describe("[Feature: Cmd]", func() {
framework.ExpectNoError(err)
framework.ExpectTrue(strings.Contains(output, ConfigValidStr), "output: %s", output)
})
It("frps invalid", func() {
ginkgo.It("frps invalid", func() {
path := f.GenerateConfigFile(`
[common]
bind_addr = 0.0.0.0
@@ -39,7 +39,7 @@ var _ = Describe("[Feature: Cmd]", func() {
framework.ExpectNoError(err)
framework.ExpectTrue(!strings.Contains(output, ConfigValidStr), "output: %s", output)
})
It("frpc valid", func() {
ginkgo.It("frpc valid", func() {
path := f.GenerateConfigFile(`
[common]
server_addr = 0.0.0.0
@@ -49,7 +49,7 @@ var _ = Describe("[Feature: Cmd]", func() {
framework.ExpectNoError(err)
framework.ExpectTrue(strings.Contains(output, ConfigValidStr), "output: %s", output)
})
It("frpc invalid", func() {
ginkgo.It("frpc invalid", func() {
path := f.GenerateConfigFile(`
[common]
server_addr = 0.0.0.0
@@ -62,8 +62,8 @@ var _ = Describe("[Feature: Cmd]", func() {
})
})
Describe("Single proxy", func() {
It("TCP", func() {
ginkgo.Describe("Single proxy", func() {
ginkgo.It("TCP", func() {
serverPort := f.AllocPort()
_, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort))
framework.ExpectNoError(err)
@@ -77,7 +77,7 @@ var _ = Describe("[Feature: Cmd]", func() {
framework.NewRequestExpect(f).Port(remotePort).Ensure()
})
It("UDP", func() {
ginkgo.It("UDP", func() {
serverPort := f.AllocPort()
_, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort))
framework.ExpectNoError(err)
@@ -92,7 +92,7 @@ var _ = Describe("[Feature: Cmd]", func() {
Port(remotePort).Ensure()
})
It("HTTP", func() {
ginkgo.It("HTTP", func() {
serverPort := f.AllocPort()
vhostHTTPPort := f.AllocPort()
_, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort), "--vhost_http_port", strconv.Itoa(vhostHTTPPort))

View File

@@ -3,18 +3,18 @@ package basic
import (
"fmt"
"github.com/onsi/ginkgo"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
"github.com/fatedier/frp/test/e2e/pkg/port"
. "github.com/onsi/ginkgo"
)
var _ = Describe("[Feature: Config]", func() {
var _ = ginkgo.Describe("[Feature: Config]", func() {
f := framework.NewDefaultFramework()
Describe("Template", func() {
It("render by env", func() {
ginkgo.Describe("Template", func() {
ginkgo.It("render by env", func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
@@ -39,8 +39,8 @@ var _ = Describe("[Feature: Config]", func() {
})
})
Describe("Includes", func() {
It("split tcp proxies into different files", func() {
ginkgo.Describe("Includes", func() {
ginkgo.It("split tcp proxies into different files", func() {
serverPort := f.AllocPort()
serverConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
[common]

View File

@@ -6,16 +6,16 @@ import (
"net/url"
"strconv"
"github.com/gorilla/websocket"
"github.com/onsi/ginkgo"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
"github.com/fatedier/frp/test/e2e/mock/server/httpserver"
"github.com/fatedier/frp/test/e2e/pkg/request"
"github.com/gorilla/websocket"
. "github.com/onsi/ginkgo"
)
var _ = Describe("[Feature: HTTP]", func() {
var _ = ginkgo.Describe("[Feature: HTTP]", func() {
f := framework.NewDefaultFramework()
getDefaultServerConf := func(vhostHTTPPort int) string {
@@ -31,7 +31,7 @@ var _ = Describe("[Feature: HTTP]", func() {
)
}
It("HTTP route by locations", func() {
ginkgo.It("HTTP route by locations", func() {
vhostHTTPPort := f.AllocPort()
serverConf := getDefaultServerConf(vhostHTTPPort)
@@ -78,7 +78,7 @@ var _ = Describe("[Feature: HTTP]", func() {
}
})
It("HTTP route by HTTP user", func() {
ginkgo.It("HTTP route by HTTP user", func() {
vhostHTTPPort := f.AllocPort()
serverConf := getDefaultServerConf(vhostHTTPPort)
@@ -138,7 +138,7 @@ var _ = Describe("[Feature: HTTP]", func() {
Ensure()
})
It("HTTP Basic Auth", func() {
ginkgo.It("HTTP Basic Auth", func() {
vhostHTTPPort := f.AllocPort()
serverConf := getDefaultServerConf(vhostHTTPPort)
@@ -176,7 +176,7 @@ var _ = Describe("[Feature: HTTP]", func() {
Ensure()
})
It("Wildcard domain", func() {
ginkgo.It("Wildcard domain", func() {
vhostHTTPPort := f.AllocPort()
serverConf := getDefaultServerConf(vhostHTTPPort)
@@ -212,7 +212,7 @@ var _ = Describe("[Feature: HTTP]", func() {
Ensure()
})
It("Subdomain", func() {
ginkgo.It("Subdomain", func() {
vhostHTTPPort := f.AllocPort()
serverConf := getDefaultServerConf(vhostHTTPPort)
serverConf += `
@@ -257,7 +257,7 @@ var _ = Describe("[Feature: HTTP]", func() {
Ensure()
})
It("Modify headers", func() {
ginkgo.It("Modify headers", func() {
vhostHTTPPort := f.AllocPort()
serverConf := getDefaultServerConf(vhostHTTPPort)
@@ -265,7 +265,7 @@ var _ = Describe("[Feature: HTTP]", func() {
localServer := httpserver.New(
httpserver.WithBindPort(localPort),
httpserver.WithHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(req.Header.Get("X-From-Where")))
_, _ = w.Write([]byte(req.Header.Get("X-From-Where")))
})),
)
f.RunServer("", localServer)
@@ -290,7 +290,7 @@ var _ = Describe("[Feature: HTTP]", func() {
Ensure()
})
It("Host Header Rewrite", func() {
ginkgo.It("Host Header Rewrite", func() {
vhostHTTPPort := f.AllocPort()
serverConf := getDefaultServerConf(vhostHTTPPort)
@@ -298,7 +298,7 @@ var _ = Describe("[Feature: HTTP]", func() {
localServer := httpserver.New(
httpserver.WithBindPort(localPort),
httpserver.WithHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(req.Host))
_, _ = w.Write([]byte(req.Host))
})),
)
f.RunServer("", localServer)
@@ -322,7 +322,7 @@ var _ = Describe("[Feature: HTTP]", func() {
Ensure()
})
It("Websocket protocol", func() {
ginkgo.It("Websocket protocol", func() {
vhostHTTPPort := f.AllocPort()
serverConf := getDefaultServerConf(vhostHTTPPort)

View File

@@ -5,19 +5,19 @@ import (
"net"
"strconv"
"github.com/onsi/ginkgo"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
"github.com/fatedier/frp/test/e2e/pkg/port"
"github.com/fatedier/frp/test/e2e/pkg/request"
clientsdk "github.com/fatedier/frp/test/e2e/pkg/sdk/client"
. "github.com/onsi/ginkgo"
)
var _ = Describe("[Feature: Server Manager]", func() {
var _ = ginkgo.Describe("[Feature: Server Manager]", func() {
f := framework.NewDefaultFramework()
It("Ports Whitelist", func() {
ginkgo.It("Ports Whitelist", func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
@@ -80,7 +80,7 @@ var _ = Describe("[Feature: Server Manager]", func() {
}).ExpectError(true).Ensure()
})
It("Alloc Random Port", func() {
ginkgo.It("Alloc Random Port", func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
@@ -124,7 +124,7 @@ var _ = Describe("[Feature: Server Manager]", func() {
framework.NewRequestExpect(f).Protocol("udp").Port(port).Ensure()
})
It("Port Reuse", func() {
ginkgo.It("Port Reuse", func() {
serverConf := consts.DefaultServerConfig
// Use same port as PortServer
serverConf += fmt.Sprintf(`
@@ -145,7 +145,7 @@ var _ = Describe("[Feature: Server Manager]", func() {
}).PortName(consts.PortServerName).Ensure()
})
It("healthz", func() {
ginkgo.It("healthz", func() {
serverConf := consts.DefaultServerConfig
dashboardPort := f.AllocPort()

View File

@@ -3,12 +3,12 @@ package e2e
import (
"testing"
"github.com/fatedier/frp/pkg/util/log"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
"github.com/onsi/gomega"
"github.com/fatedier/frp/pkg/util/log"
"github.com/fatedier/frp/test/e2e/framework"
)
var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {

View File

@@ -6,15 +6,14 @@ import (
"os"
"testing"
"github.com/fatedier/frp/pkg/util/log"
"github.com/fatedier/frp/test/e2e/framework"
_ "github.com/onsi/ginkgo"
"github.com/fatedier/frp/pkg/util/log"
// test source
_ "github.com/fatedier/frp/test/e2e/basic"
_ "github.com/fatedier/frp/test/e2e/features"
"github.com/fatedier/frp/test/e2e/framework"
_ "github.com/fatedier/frp/test/e2e/plugin"
_ "github.com/onsi/ginkgo"
)
// handleFlags sets up all flags and parses the command line.

View File

@@ -3,17 +3,17 @@ package e2e
import (
"fmt"
"github.com/onsi/ginkgo"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
. "github.com/onsi/ginkgo"
)
var _ = Describe("[Feature: Example]", func() {
var _ = ginkgo.Describe("[Feature: Example]", func() {
f := framework.NewDefaultFramework()
Describe("TCP", func() {
It("Expose a TCP echo server", func() {
ginkgo.Describe("TCP", func() {
ginkgo.It("Expose a TCP echo server", func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig

View File

@@ -5,18 +5,18 @@ import (
"strings"
"time"
"github.com/onsi/ginkgo"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
"github.com/fatedier/frp/test/e2e/mock/server/streamserver"
"github.com/fatedier/frp/test/e2e/pkg/request"
. "github.com/onsi/ginkgo"
)
var _ = Describe("[Feature: Bandwidth Limit]", func() {
var _ = ginkgo.Describe("[Feature: Bandwidth Limit]", func() {
f := framework.NewDefaultFramework()
It("Proxy Bandwidth Limit", func() {
ginkgo.It("Proxy Bandwidth Limit", func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
@@ -40,7 +40,7 @@ var _ = Describe("[Feature: Bandwidth Limit]", func() {
framework.NewRequestExpect(f).Port(remotePort).RequestModify(func(r *request.Request) {
r.Body([]byte(content)).Timeout(30 * time.Second)
}).ExpectResp([]byte(content)).Ensure()
duration := time.Now().Sub(start)
duration := time.Since(start)
framework.ExpectTrue(duration.Seconds() > 7, "100Kb with 10KB limit, want > 7 seconds, but got %d seconds", duration.Seconds())
})

View File

@@ -4,15 +4,15 @@ import (
"fmt"
"time"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo"
"github.com/fatedier/frp/test/e2e/framework"
)
var _ = Describe("[Feature: Chaos]", func() {
var _ = ginkgo.Describe("[Feature: Chaos]", func() {
f := framework.NewDefaultFramework()
It("reconnect after frps restart", func() {
ginkgo.It("reconnect after frps restart", func() {
serverPort := f.AllocPort()
serverConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
[common]
@@ -41,7 +41,7 @@ var _ = Describe("[Feature: Chaos]", func() {
framework.NewRequestExpect(f).Port(remotePort).Ensure()
// 2. stop frps, expect request failed
ps.Stop()
_ = ps.Stop()
time.Sleep(200 * time.Millisecond)
framework.NewRequestExpect(f).Port(remotePort).ExpectError(true).Ensure()
@@ -52,7 +52,7 @@ var _ = Describe("[Feature: Chaos]", func() {
framework.NewRequestExpect(f).Port(remotePort).Ensure()
// 4. stop frpc, expect request failed
pc.Stop()
_ = pc.Stop()
time.Sleep(200 * time.Millisecond)
framework.NewRequestExpect(f).Port(remotePort).ExpectError(true).Ensure()

View File

@@ -6,16 +6,16 @@ import (
"sync"
"time"
"github.com/onsi/ginkgo"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
"github.com/fatedier/frp/test/e2e/mock/server/httpserver"
"github.com/fatedier/frp/test/e2e/mock/server/streamserver"
"github.com/fatedier/frp/test/e2e/pkg/request"
. "github.com/onsi/ginkgo"
)
var _ = Describe("[Feature: Group]", func() {
var _ = ginkgo.Describe("[Feature: Group]", func() {
f := framework.NewDefaultFramework()
newHTTPServer := func(port int, respContent string) *httpserver.Server {
@@ -60,8 +60,8 @@ var _ = Describe("[Feature: Group]", func() {
return results
}
Describe("Load Balancing", func() {
It("TCP", func() {
ginkgo.Describe("Load Balancing", func() {
ginkgo.It("TCP", func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
@@ -112,8 +112,8 @@ var _ = Describe("[Feature: Group]", func() {
})
})
Describe("Health Check", func() {
It("TCP", func() {
ginkgo.Describe("Health Check", func() {
ginkgo.It("TCP", func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
@@ -178,7 +178,7 @@ var _ = Describe("[Feature: Group]", func() {
framework.ExpectContainElements(results, []string{"foo", "bar"})
})
It("HTTP", func() {
ginkgo.It("HTTP", func() {
vhostPort := f.AllocPort()
serverConf := consts.DefaultServerConfig + fmt.Sprintf(`
vhost_http_port = %d

View File

@@ -4,15 +4,15 @@ import (
"fmt"
"time"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo"
"github.com/fatedier/frp/test/e2e/framework"
)
var _ = Describe("[Feature: Heartbeat]", func() {
var _ = ginkgo.Describe("[Feature: Heartbeat]", func() {
f := framework.NewDefaultFramework()
It("disable application layer heartbeat", func() {
ginkgo.It("disable application layer heartbeat", func() {
serverPort := f.AllocPort()
serverConf := fmt.Sprintf(`
[common]

View File

@@ -5,18 +5,18 @@ import (
"strings"
"time"
"github.com/onsi/ginkgo"
"github.com/fatedier/frp/pkg/util/log"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
"github.com/fatedier/frp/test/e2e/pkg/request"
. "github.com/onsi/ginkgo"
)
var _ = Describe("[Feature: Monitor]", func() {
var _ = ginkgo.Describe("[Feature: Monitor]", func() {
f := framework.NewDefaultFramework()
It("Prometheus metrics", func() {
ginkgo.It("Prometheus metrics", func() {
dashboardPort := f.AllocPort()
serverConf := consts.DefaultServerConfig + fmt.Sprintf(`
enable_prometheus = true

View File

@@ -6,6 +6,9 @@ import (
"net"
"net/http"
"github.com/onsi/ginkgo"
pp "github.com/pires/go-proxyproto"
"github.com/fatedier/frp/pkg/util/log"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
@@ -13,15 +16,12 @@ import (
"github.com/fatedier/frp/test/e2e/mock/server/streamserver"
"github.com/fatedier/frp/test/e2e/pkg/request"
"github.com/fatedier/frp/test/e2e/pkg/rpc"
. "github.com/onsi/ginkgo"
pp "github.com/pires/go-proxyproto"
)
var _ = Describe("[Feature: Real IP]", func() {
var _ = ginkgo.Describe("[Feature: Real IP]", func() {
f := framework.NewDefaultFramework()
It("HTTP X-Forwarded-For", func() {
ginkgo.It("HTTP X-Forwarded-For", func() {
vhostHTTPPort := f.AllocPort()
serverConf := consts.DefaultServerConfig + fmt.Sprintf(`
vhost_http_port = %d
@@ -31,7 +31,7 @@ var _ = Describe("[Feature: Real IP]", func() {
localServer := httpserver.New(
httpserver.WithBindPort(localPort),
httpserver.WithHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(req.Header.Get("X-Forwarded-For")))
_, _ = w.Write([]byte(req.Header.Get("X-Forwarded-For")))
})),
)
f.RunServer("", localServer)
@@ -52,11 +52,10 @@ var _ = Describe("[Feature: Real IP]", func() {
}).
ExpectResp([]byte("127.0.0.1")).
Ensure()
})
Describe("Proxy Protocol", func() {
It("TCP", func() {
ginkgo.Describe("Proxy Protocol", func() {
ginkgo.It("TCP", func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
@@ -77,7 +76,7 @@ var _ = Describe("[Feature: Real IP]", func() {
}
buf := []byte(ppHeader.SourceAddr.String())
rpc.WriteBytes(c, buf)
_, _ = rpc.WriteBytes(c, buf)
}
}))
f.RunServer("", localServer)
@@ -106,7 +105,7 @@ var _ = Describe("[Feature: Real IP]", func() {
})
})
It("HTTP", func() {
ginkgo.It("HTTP", func() {
vhostHTTPPort := f.AllocPort()
serverConf := consts.DefaultServerConfig + fmt.Sprintf(`
vhost_http_port = %d

View File

@@ -6,13 +6,16 @@ import (
// CleanupActionHandle is an integer pointer type for handling cleanup action
type CleanupActionHandle *int
type cleanupFuncHandle struct {
actionHandle CleanupActionHandle
actionHook func()
}
var cleanupActionsLock sync.Mutex
var cleanupHookList = []cleanupFuncHandle{}
var (
cleanupActionsLock sync.Mutex
cleanupHookList = []cleanupFuncHandle{}
)
// AddCleanupAction installs a function that will be called in the event of the
// whole test being terminated. This allows arbitrary pieces of the overall

View File

@@ -9,12 +9,12 @@ import (
"strings"
"text/template"
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
"github.com/fatedier/frp/test/e2e/mock/server"
"github.com/fatedier/frp/test/e2e/pkg/port"
"github.com/fatedier/frp/test/e2e/pkg/process"
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
)
type Options struct {
@@ -102,7 +102,8 @@ func (f *Framework) BeforeEach() {
for k, v := range params {
switch t := v.(type) {
case int:
f.usedPorts[k] = int(t)
f.usedPorts[k] = t
default:
}
}
}
@@ -116,14 +117,14 @@ func (f *Framework) AfterEach() {
// stop processor
for _, p := range f.serverProcesses {
p.Stop()
_ = p.Stop()
if TestContext.Debug {
fmt.Println(p.ErrorOutput())
fmt.Println(p.StdOutput())
}
}
for _, p := range f.clientProcesses {
p.Stop()
_ = p.Stop()
if TestContext.Debug {
fmt.Println(p.ErrorOutput())
fmt.Println(p.StdOutput())
@@ -259,7 +260,7 @@ func (f *Framework) SetEnvs(envs []string) {
func (f *Framework) WriteTempFile(name string, content string) string {
filePath := filepath.Join(f.TempDirectory, name)
err := os.WriteFile(filePath, []byte(content), 0766)
err := os.WriteFile(filePath, []byte(content), 0o766)
ExpectNoError(err)
return filePath
}

View File

@@ -58,11 +58,12 @@ var codeFilterRE = regexp.MustCompile(`/github.com/onsi/ginkgo/`)
// From the remaining entries it automatically filters out useless ones like
// entries coming from Ginkgo.
//
// This is a modified copy of PruneStack in https://github.com/onsi/ginkgo/blob/f90f37d87fa6b1dd9625e2b1e83c23ffae3de228/internal/codelocation/code_location.go#L25:
// - simplified API and thus renamed (calls debug.Stack() instead of taking a parameter)
// - source code filtering updated to be specific to Kubernetes
// - optimized to use bytes and in-place slice filtering from
// https://github.com/golang/go/wiki/SliceTricks#filter-in-place
// This is a modified copy of PruneStack in
// https://github.com/onsi/ginkgo/blob/f90f37d87fa6b1dd9625e2b1e83c23ffae3de228/internal/codelocation/code_location.go#L25:
// - simplified API and thus renamed (calls debug.Stack() instead of taking a parameter)
// - source code filtering updated to be specific to Kubernetes
// - optimized to use bytes and in-place slice filtering from
// https://github.com/golang/go/wiki/SliceTricks#filter-in-place
func PrunedStack(skip int) []byte {
fullStackTrace := debug.Stack()
stack := bytes.Split(fullStackTrace, []byte("\n"))
@@ -82,7 +83,7 @@ func PrunedStack(skip int) []byte {
n := 0
for i := 0; i < len(stack)/2; i++ {
// We filter out based on the source code file name.
if !codeFilterRE.Match([]byte(stack[i*2+1])) {
if !codeFilterRE.Match(stack[i*2+1]) {
stack[n] = stack[i*2]
stack[n+1] = stack[i*2+1]
n += 2

View File

@@ -33,9 +33,11 @@ func NewMockServers(portAllocator *port.Allocator) *MockServers {
httpPort := portAllocator.Get()
s.tcpEchoServer = streamserver.New(streamserver.TCP, streamserver.WithBindPort(tcpPort))
s.udpEchoServer = streamserver.New(streamserver.UDP, streamserver.WithBindPort(udpPort))
s.httpSimpleServer = httpserver.New(httpserver.WithBindPort(httpPort), httpserver.WithHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(consts.TestString))
})))
s.httpSimpleServer = httpserver.New(httpserver.WithBindPort(httpPort),
httpserver.WithHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
_, _ = w.Write([]byte(consts.TestString))
})),
)
udsIndex := portAllocator.Get()
udsAddr := fmt.Sprintf("%s/frp_echo_server_%d.sock", os.TempDir(), udsIndex)

View File

@@ -14,12 +14,8 @@ import (
// The first template should always be frps.
func (f *Framework) RunProcesses(serverTemplates []string, clientTemplates []string) ([]*process.Process, []*process.Process) {
templates := make([]string, 0, len(serverTemplates)+len(clientTemplates))
for _, t := range serverTemplates {
templates = append(templates, t)
}
for _, t := range clientTemplates {
templates = append(templates, t)
}
templates = append(templates, serverTemplates...)
templates = append(templates, clientTemplates...)
outs, ports, err := f.RenderTemplates(templates)
ExpectNoError(err)
ExpectTrue(len(templates) > 0)
@@ -31,7 +27,7 @@ func (f *Framework) RunProcesses(serverTemplates []string, clientTemplates []str
currentServerProcesses := make([]*process.Process, 0, len(serverTemplates))
for i := range serverTemplates {
path := filepath.Join(f.TempDirectory, fmt.Sprintf("frp-e2e-server-%d", i))
err = os.WriteFile(path, []byte(outs[i]), 0666)
err = os.WriteFile(path, []byte(outs[i]), 0o666)
ExpectNoError(err)
flog.Trace("[%s] %s", path, outs[i])
@@ -48,7 +44,7 @@ func (f *Framework) RunProcesses(serverTemplates []string, clientTemplates []str
for i := range clientTemplates {
index := i + len(serverTemplates)
path := filepath.Join(f.TempDirectory, fmt.Sprintf("frp-e2e-client-%d", i))
err = os.WriteFile(path, []byte(outs[index]), 0666)
err = os.WriteFile(path, []byte(outs[index]), 0o666)
ExpectNoError(err)
flog.Trace("[%s] %s", path, outs[index])
@@ -91,7 +87,7 @@ func (f *Framework) RunFrpc(args ...string) (*process.Process, string, error) {
func (f *Framework) GenerateConfigFile(content string) string {
f.configFileIndex++
path := filepath.Join(f.TempDirectory, fmt.Sprintf("frp-e2e-config-%d", f.configFileIndex))
err := os.WriteFile(path, []byte(content), 0666)
err := os.WriteFile(path, []byte(content), 0o666)
ExpectNoError(err)
return path
}

View File

@@ -11,7 +11,7 @@ import (
func SpecifiedHTTPBodyHandler(body []byte) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
w.Write(body)
_, _ = w.Write(body)
}
}

View File

@@ -24,7 +24,6 @@ var TestContext TestContextType
// The other Register*Flags methods below can be used to add more
// test-specific flags. However, those settings then get added
// regardless whether the test is actually in the test suite.
//
func RegisterCommonFlags(flags *flag.FlagSet) {
// Turn on EmitSpecProgress to get spec progress (especially on interrupt)
config.GinkgoConfig.EmitSpecProgress = true

View File

@@ -5,6 +5,7 @@ import (
"net"
"net/http"
"strconv"
"time"
)
type Server struct {
@@ -44,7 +45,7 @@ func WithBindPort(port int) Option {
}
}
func WithTlsConfig(tlsConfig *tls.Config) Option {
func WithTLSConfig(tlsConfig *tls.Config) Option {
return func(s *Server) *Server {
s.tlsConfig = tlsConfig
return s
@@ -61,7 +62,7 @@ func WithHandler(h http.Handler) Option {
func WithResponse(resp []byte) Option {
return func(s *Server) *Server {
s.handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(resp)
_, _ = w.Write(resp)
})
return s
}
@@ -74,16 +75,21 @@ func (s *Server) Run() error {
addr := net.JoinHostPort(s.bindAddr, strconv.Itoa(s.bindPort))
hs := &http.Server{
Addr: addr,
Handler: s.handler,
TLSConfig: s.tlsConfig,
Addr: addr,
Handler: s.handler,
TLSConfig: s.tlsConfig,
ReadHeaderTimeout: time.Minute,
}
s.hs = hs
if s.tlsConfig == nil {
go hs.Serve(s.l)
go func() {
_ = hs.Serve(s.l)
}()
} else {
go hs.ServeTLS(s.l, "", "")
go func() {
_ = hs.ServeTLS(s.l, "", "")
}()
}
return nil
}

View File

@@ -127,7 +127,7 @@ func (s *Server) handle(c net.Conn) {
if len(s.respContent) > 0 {
buf = s.respContent
}
rpc.WriteBytes(c, buf)
_, _ = rpc.WriteBytes(c, buf)
}
}

View File

@@ -22,8 +22,8 @@ type Artifacts struct {
ResourceVersion string
}
// CertGenerator is an interface to provision the serving certificate.
type CertGenerator interface {
// Generator is an interface to provision the serving certificate.
type Generator interface {
// Generate returns a Artifacts struct.
Generate(CommonName string) (*Artifacts, error)
// SetCA sets the PEM-encoded CA private key and CA cert for signing the generated serving cert.

View File

@@ -23,7 +23,7 @@ type SelfSignedCertGenerator struct {
caCert []byte
}
var _ CertGenerator = &SelfSignedCertGenerator{}
var _ Generator = &SelfSignedCertGenerator{}
// SetCA sets the PEM-encoded CA private key and CA cert for signing the generated serving cert.
func (cp *SelfSignedCertGenerator) SetCA(caKey, caCert []byte) {

View File

@@ -26,16 +26,17 @@ func unmarshalFromName(name string) (*nameBuilder, error) {
builder.name = arrs[1]
case 4:
builder.name = arrs[1]
if fromPort, err := strconv.Atoi(arrs[2]); err != nil {
fromPort, err := strconv.Atoi(arrs[2])
if err != nil {
return nil, fmt.Errorf("error range port from")
} else {
builder.rangePortFrom = fromPort
}
if toPort, err := strconv.Atoi(arrs[3]); err != nil {
builder.rangePortFrom = fromPort
toPort, err := strconv.Atoi(arrs[3])
if err != nil {
return nil, fmt.Errorf("error range port to")
} else {
builder.rangePortTo = toPort
}
builder.rangePortTo = toPort
default:
return nil, fmt.Errorf("error port name format")
}

View File

@@ -12,9 +12,10 @@ import (
"strconv"
"time"
libdial "github.com/fatedier/golib/net/dial"
"github.com/fatedier/frp/test/e2e/pkg/rpc"
"github.com/fatedier/frp/test/e2e/pkg/utils"
libdial "github.com/fatedier/golib/net/dial"
)
type Request struct {
@@ -181,7 +182,7 @@ func (r *Request) Do() (*Response, error) {
defer conn.Close()
if r.timeout > 0 {
conn.SetDeadline(time.Now().Add(r.timeout))
_ = conn.SetDeadline(time.Now().Add(r.timeout))
}
buf, err := r.sendRequestByConn(conn, r.body)
if err != nil {
@@ -199,7 +200,6 @@ type Response struct {
func (r *Request) sendHTTPRequest(method, urlstr string, host string, headers map[string]string,
proxy string, body []byte, tlsConfig *tls.Config,
) (*Response, error) {
var inBody io.Reader
if len(body) != 0 {
inBody = bytes.NewReader(body)
@@ -240,6 +240,7 @@ func (r *Request) sendHTTPRequest(method, urlstr string, host string, headers ma
if err != nil {
return nil, err
}
defer resp.Body.Close()
ret := &Response{Code: resp.StatusCode, Header: resp.Header}
buf, err := io.ReadAll(resp.Body)

View File

@@ -9,7 +9,10 @@ import (
func WriteBytes(w io.Writer, buf []byte) (int, error) {
out := bytes.NewBuffer(nil)
binary.Write(out, binary.BigEndian, int64(len(buf)))
if err := binary.Write(out, binary.BigEndian, int64(len(buf))); err != nil {
return 0, err
}
out.Write(buf)
return w.Write(out.Bytes())
}

View File

@@ -5,6 +5,8 @@ import (
"fmt"
"strconv"
"github.com/onsi/ginkgo"
"github.com/fatedier/frp/pkg/transport"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
@@ -12,15 +14,13 @@ import (
"github.com/fatedier/frp/test/e2e/pkg/cert"
"github.com/fatedier/frp/test/e2e/pkg/port"
"github.com/fatedier/frp/test/e2e/pkg/request"
. "github.com/onsi/ginkgo"
)
var _ = Describe("[Feature: Client-Plugins]", func() {
var _ = ginkgo.Describe("[Feature: Client-Plugins]", func() {
f := framework.NewDefaultFramework()
Describe("UnixDomainSocket", func() {
It("Expose a unix domain socket echo server", func() {
ginkgo.Describe("UnixDomainSocket", func() {
ginkgo.It("Expose a unix domain socket echo server", func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
@@ -76,7 +76,7 @@ var _ = Describe("[Feature: Client-Plugins]", func() {
})
})
It("http_proxy", func() {
ginkgo.It("http_proxy", func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
@@ -108,7 +108,7 @@ var _ = Describe("[Feature: Client-Plugins]", func() {
})
})
It("socks5 proxy", func() {
ginkgo.It("socks5 proxy", func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
@@ -135,7 +135,7 @@ var _ = Describe("[Feature: Client-Plugins]", func() {
}).Ensure()
})
It("static_file", func() {
ginkgo.It("static_file", func() {
vhostPort := f.AllocPort()
serverConf := consts.DefaultServerConfig + fmt.Sprintf(`
vhost_http_port = %d
@@ -184,7 +184,7 @@ var _ = Describe("[Feature: Client-Plugins]", func() {
).ExpectResp([]byte("foo")).Ensure()
})
It("http2https", func() {
ginkgo.It("http2https", func() {
serverConf := consts.DefaultServerConfig
vhostHTTPPort := f.AllocPort()
serverConf += fmt.Sprintf(`
@@ -206,7 +206,7 @@ var _ = Describe("[Feature: Client-Plugins]", func() {
framework.ExpectNoError(err)
localServer := httpserver.New(
httpserver.WithBindPort(localPort),
httpserver.WithTlsConfig(tlsConfig),
httpserver.WithTLSConfig(tlsConfig),
httpserver.WithResponse([]byte("test")),
)
f.RunServer("", localServer)
@@ -220,7 +220,7 @@ var _ = Describe("[Feature: Client-Plugins]", func() {
Ensure()
})
It("https2http", func() {
ginkgo.It("https2http", func() {
generator := &cert.SelfSignedCertGenerator{}
artifacts, err := generator.Generate("example.com")
framework.ExpectNoError(err)
@@ -264,7 +264,7 @@ var _ = Describe("[Feature: Client-Plugins]", func() {
Ensure()
})
It("https2https", func() {
ginkgo.It("https2https", func() {
generator := &cert.SelfSignedCertGenerator{}
artifacts, err := generator.Generate("example.com")
framework.ExpectNoError(err)
@@ -295,7 +295,7 @@ var _ = Describe("[Feature: Client-Plugins]", func() {
localServer := httpserver.New(
httpserver.WithBindPort(localPort),
httpserver.WithResponse([]byte("test")),
httpserver.WithTlsConfig(tlsConfig),
httpserver.WithTLSConfig(tlsConfig),
)
f.RunServer("", localServer)

View File

@@ -4,25 +4,25 @@ import (
"fmt"
"time"
"github.com/onsi/ginkgo"
plugin "github.com/fatedier/frp/pkg/plugin/server"
"github.com/fatedier/frp/pkg/transport"
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
. "github.com/onsi/ginkgo"
)
var _ = Describe("[Feature: Server-Plugins]", func() {
var _ = ginkgo.Describe("[Feature: Server-Plugins]", func() {
f := framework.NewDefaultFramework()
Describe("Login", func() {
ginkgo.Describe("Login", func() {
newFunc := func() *plugin.Request {
var r plugin.Request
r.Content = &plugin.LoginContent{}
return &r
}
It("Auth for custom meta token", func() {
ginkgo.It("Auth for custom meta token", func() {
localPort := f.AllocPort()
clientAddressGot := false
@@ -79,14 +79,14 @@ var _ = Describe("[Feature: Server-Plugins]", func() {
})
})
Describe("NewProxy", func() {
ginkgo.Describe("NewProxy", func() {
newFunc := func() *plugin.Request {
var r plugin.Request
r.Content = &plugin.NewProxyContent{}
return &r
}
It("Validate Info", func() {
ginkgo.It("Validate Info", func() {
localPort := f.AllocPort()
handler := func(req *plugin.Request) *plugin.Response {
var ret plugin.Response
@@ -123,7 +123,7 @@ var _ = Describe("[Feature: Server-Plugins]", func() {
framework.NewRequestExpect(f).Port(remotePort).Ensure()
})
It("Mofify RemotePort", func() {
ginkgo.It("Mofify RemotePort", func() {
localPort := f.AllocPort()
remotePort := f.AllocPort()
handler := func(req *plugin.Request) *plugin.Response {
@@ -158,14 +158,14 @@ var _ = Describe("[Feature: Server-Plugins]", func() {
})
})
Describe("CloseProxy", func() {
ginkgo.Describe("CloseProxy", func() {
newFunc := func() *plugin.Request {
var r plugin.Request
r.Content = &plugin.CloseProxyContent{}
return &r
}
It("Validate Info", func() {
ginkgo.It("Validate Info", func() {
localPort := f.AllocPort()
var recordProxyName string
handler := func(req *plugin.Request) *plugin.Response {
@@ -199,7 +199,7 @@ var _ = Describe("[Feature: Server-Plugins]", func() {
framework.NewRequestExpect(f).Port(remotePort).Ensure()
for _, c := range clients {
c.Stop()
_ = c.Stop()
}
time.Sleep(1 * time.Second)
@@ -208,14 +208,14 @@ var _ = Describe("[Feature: Server-Plugins]", func() {
})
})
Describe("Ping", func() {
ginkgo.Describe("Ping", func() {
newFunc := func() *plugin.Request {
var r plugin.Request
r.Content = &plugin.PingContent{}
return &r
}
It("Validate Info", func() {
ginkgo.It("Validate Info", func() {
localPort := f.AllocPort()
var record string
@@ -258,14 +258,14 @@ var _ = Describe("[Feature: Server-Plugins]", func() {
})
})
Describe("NewWorkConn", func() {
ginkgo.Describe("NewWorkConn", func() {
newFunc := func() *plugin.Request {
var r plugin.Request
r.Content = &plugin.NewWorkConnContent{}
return &r
}
It("Validate Info", func() {
ginkgo.It("Validate Info", func() {
localPort := f.AllocPort()
var record string
@@ -304,13 +304,13 @@ var _ = Describe("[Feature: Server-Plugins]", func() {
})
})
Describe("NewUserConn", func() {
ginkgo.Describe("NewUserConn", func() {
newFunc := func() *plugin.Request {
var r plugin.Request
r.Content = &plugin.NewUserConnContent{}
return &r
}
It("Validate Info", func() {
ginkgo.It("Validate Info", func() {
localPort := f.AllocPort()
var record string
@@ -349,13 +349,13 @@ var _ = Describe("[Feature: Server-Plugins]", func() {
})
})
Describe("HTTPS Protocol", func() {
ginkgo.Describe("HTTPS Protocol", func() {
newFunc := func() *plugin.Request {
var r plugin.Request
r.Content = &plugin.NewUserConnContent{}
return &r
}
It("Validate Login Info, disable tls verify", func() {
ginkgo.It("Validate Login Info, disable tls verify", func() {
localPort := f.AllocPort()
var record string

View File

@@ -11,14 +11,14 @@ import (
"github.com/fatedier/frp/test/e2e/mock/server/httpserver"
)
type PluginHandler func(req *plugin.Request) *plugin.Response
type Handler func(req *plugin.Request) *plugin.Response
type NewPluginRequest func() *plugin.Request
func NewHTTPPluginServer(port int, newFunc NewPluginRequest, handler PluginHandler, tlsConfig *tls.Config) *httpserver.Server {
func NewHTTPPluginServer(port int, newFunc NewPluginRequest, handler Handler, tlsConfig *tls.Config) *httpserver.Server {
return httpserver.New(
httpserver.WithBindPort(port),
httpserver.WithTlsConfig(tlsConfig),
httpserver.WithTLSConfig(tlsConfig),
httpserver.WithHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
r := newFunc()
buf, err := io.ReadAll(req.Body)
@@ -35,7 +35,7 @@ func NewHTTPPluginServer(port int, newFunc NewPluginRequest, handler PluginHandl
resp := handler(r)
buf, _ = json.Marshal(resp)
log.Trace("plugin response: %s", string(buf))
w.Write(buf)
_, _ = w.Write(buf)
})),
)
}