mirror of
https://github.com/fatedier/frp.git
synced 2026-03-16 23:09:16 +08:00
more e2e tests (#1845)
This commit is contained in:
95
test/e2e/basic/client_server.go
Normal file
95
test/e2e/basic/client_server.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/fatedier/frp/test/e2e/framework"
|
||||
"github.com/fatedier/frp/test/e2e/framework/consts"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
)
|
||||
|
||||
type generalTestConfigures struct {
|
||||
server string
|
||||
client string
|
||||
expectError bool
|
||||
}
|
||||
|
||||
func defineClientServerTest(desc string, f *framework.Framework, configures *generalTestConfigures) {
|
||||
It(desc, func() {
|
||||
serverConf := consts.DefaultServerConfig
|
||||
clientConf := consts.DefaultClientConfig
|
||||
|
||||
serverConf += fmt.Sprintf(`
|
||||
%s
|
||||
`, configures.server)
|
||||
|
||||
clientConf += fmt.Sprintf(`
|
||||
%s
|
||||
|
||||
[tcp]
|
||||
type = tcp
|
||||
local_port = {{ .%s }}
|
||||
remote_port = {{ .%s }}
|
||||
|
||||
[udp]
|
||||
type = udp
|
||||
local_port = {{ .%s }}
|
||||
remote_port = {{ .%s }}
|
||||
`, configures.client,
|
||||
framework.TCPEchoServerPort, framework.GenPortName("TCP"),
|
||||
framework.UDPEchoServerPort, framework.GenPortName("UDP"),
|
||||
)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
if !configures.expectError {
|
||||
framework.ExpectTCPRequest(f.UsedPorts[framework.GenPortName("TCP")],
|
||||
[]byte(consts.TestString), []byte(consts.TestString), connTimeout, "tcp proxy")
|
||||
framework.ExpectUDPRequest(f.UsedPorts[framework.GenPortName("UDP")],
|
||||
[]byte(consts.TestString), []byte(consts.TestString), connTimeout, "udp proxy")
|
||||
} else {
|
||||
framework.ExpectTCPRequestError(f.UsedPorts[framework.GenPortName("TCP")],
|
||||
[]byte(consts.TestString), connTimeout, "tcp proxy")
|
||||
framework.ExpectUDPRequestError(f.UsedPorts[framework.GenPortName("UDP")],
|
||||
[]byte(consts.TestString), connTimeout, "udp proxy")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var _ = Describe("[Feature: Client-Server]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
Describe("Protocol", func() {
|
||||
supportProtocols := []string{"tcp", "kcp", "websocket"}
|
||||
for _, protocol := range supportProtocols {
|
||||
configures := &generalTestConfigures{
|
||||
server: fmt.Sprintf(`
|
||||
kcp_bind_port = {{ .%s }}
|
||||
protocol = %s"
|
||||
`, consts.PortServerName, protocol),
|
||||
client: "protocol = " + protocol,
|
||||
}
|
||||
defineClientServerTest(protocol, f, configures)
|
||||
}
|
||||
})
|
||||
|
||||
Describe("Authentication", func() {
|
||||
func() {
|
||||
configures := &generalTestConfigures{
|
||||
server: "token = 123456",
|
||||
client: "token = 123456",
|
||||
}
|
||||
defineClientServerTest("Token Correct", f, configures)
|
||||
}()
|
||||
|
||||
func() {
|
||||
configures := &generalTestConfigures{
|
||||
server: "token = 123456",
|
||||
client: "token = invalid",
|
||||
expectError: true,
|
||||
}
|
||||
defineClientServerTest("Token Incorrect", f, configures)
|
||||
}()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user