frp/test/e2e/basic/client_server.go

112 lines
3.0 KiB
Go
Raw Normal View History

2020-09-07 14:57:23 +08:00
package basic
import (
"fmt"
2020-09-07 15:45:44 +08:00
"strings"
2020-09-07 14:57:23 +08:00
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
2021-03-31 16:57:39 +08:00
"github.com/fatedier/frp/test/e2e/pkg/port"
2020-09-07 14:57:23 +08:00
. "github.com/onsi/ginkgo"
)
type generalTestConfigures struct {
server string
client string
expectError bool
}
2021-03-31 16:57:39 +08:00
// defineClientServerTest test a normal tcp and udp proxy with specified TestConfigures.
2020-09-07 14:57:23 +08:00
func defineClientServerTest(desc string, f *framework.Framework, configures *generalTestConfigures) {
It(desc, func() {
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
serverConf += fmt.Sprintf(`
%s
`, configures.server)
2021-03-31 16:57:39 +08:00
tcpPortName := port.GenName("TCP")
udpPortName := port.GenName("UDP")
2020-09-07 14:57:23 +08:00
clientConf += fmt.Sprintf(`
%s
[tcp]
type = tcp
local_port = {{ .%s }}
remote_port = {{ .%s }}
[udp]
type = udp
local_port = {{ .%s }}
remote_port = {{ .%s }}
`, configures.client,
2021-03-31 16:57:39 +08:00
framework.TCPEchoServerPort, tcpPortName,
framework.UDPEchoServerPort, udpPortName,
2020-09-07 14:57:23 +08:00
)
f.RunProcesses([]string{serverConf}, []string{clientConf})
2021-03-31 16:57:39 +08:00
framework.NewRequestExpect(f).PortName(tcpPortName).ExpectError(configures.expectError).Explain("tcp proxy").Ensure()
framework.NewRequestExpect(f).RequestModify(framework.SetRequestProtocol("udp")).
2021-03-31 16:57:39 +08:00
PortName(udpPortName).ExpectError(configures.expectError).Explain("udp proxy").Ensure()
2020-09-07 14:57:23 +08:00
})
}
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() {
2020-09-07 15:45:44 +08:00
defineClientServerTest("Token Correct", f, &generalTestConfigures{
server: "token = 123456",
client: "token = 123456",
})
2020-09-07 14:57:23 +08:00
2020-09-07 15:45:44 +08:00
defineClientServerTest("Token Incorrect", f, &generalTestConfigures{
server: "token = 123456",
client: "token = invalid",
expectError: true,
})
})
Describe("TLS", func() {
supportProtocols := []string{"tcp", "kcp", "websocket"}
for _, protocol := range supportProtocols {
tmp := protocol
defineClientServerTest("TLS over "+strings.ToUpper(tmp), f, &generalTestConfigures{
server: fmt.Sprintf(`
kcp_bind_port = {{ .%s }}
protocol = %s
`, consts.PortServerName, protocol),
client: fmt.Sprintf(`tls_enable = true
protocol = %s
`, protocol),
})
}
defineClientServerTest("enable tls_only, client with TLS", f, &generalTestConfigures{
server: "tls_only = true",
client: "tls_enable = true",
})
defineClientServerTest("enable tls_only, client without TLS", f, &generalTestConfigures{
server: "tls_only = true",
expectError: true,
})
2020-09-07 14:57:23 +08:00
})
})