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
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
"github.com/onsi/ginkgo"
|
|
|
|
|
2020-09-07 14:57:23 +08:00
|
|
|
"github.com/fatedier/frp/test/e2e/framework"
|
|
|
|
"github.com/fatedier/frp/test/e2e/framework/consts"
|
2021-08-02 13:07:28 +08:00
|
|
|
"github.com/fatedier/frp/test/e2e/pkg/cert"
|
2021-03-31 16:57:39 +08:00
|
|
|
"github.com/fatedier/frp/test/e2e/pkg/port"
|
2020-09-07 14:57:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type generalTestConfigures struct {
|
|
|
|
server string
|
|
|
|
client string
|
|
|
|
expectError bool
|
|
|
|
}
|
|
|
|
|
2021-08-02 13:07:28 +08:00
|
|
|
func runClientServerTest(f *framework.Framework, configures *generalTestConfigures) {
|
|
|
|
serverConf := consts.DefaultServerConfig
|
|
|
|
clientConf := consts.DefaultClientConfig
|
2020-09-07 14:57:23 +08:00
|
|
|
|
2021-08-02 13:07:28 +08:00
|
|
|
serverConf += fmt.Sprintf(`
|
2020-09-07 14:57:23 +08:00
|
|
|
%s
|
|
|
|
`, configures.server)
|
|
|
|
|
2021-08-02 13:07:28 +08:00
|
|
|
tcpPortName := port.GenName("TCP")
|
|
|
|
udpPortName := port.GenName("UDP")
|
|
|
|
clientConf += fmt.Sprintf(`
|
2020-09-07 14:57:23 +08:00
|
|
|
%s
|
|
|
|
|
|
|
|
[tcp]
|
|
|
|
type = tcp
|
|
|
|
local_port = {{ .%s }}
|
|
|
|
remote_port = {{ .%s }}
|
|
|
|
|
|
|
|
[udp]
|
|
|
|
type = udp
|
|
|
|
local_port = {{ .%s }}
|
|
|
|
remote_port = {{ .%s }}
|
|
|
|
`, configures.client,
|
2021-08-02 13:07:28 +08:00
|
|
|
framework.TCPEchoServerPort, tcpPortName,
|
|
|
|
framework.UDPEchoServerPort, udpPortName,
|
|
|
|
)
|
2020-09-07 14:57:23 +08:00
|
|
|
|
2021-08-02 13:07:28 +08:00
|
|
|
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
2020-09-07 14:57:23 +08:00
|
|
|
|
2021-08-02 13:07:28 +08:00
|
|
|
framework.NewRequestExpect(f).PortName(tcpPortName).ExpectError(configures.expectError).Explain("tcp proxy").Ensure()
|
|
|
|
framework.NewRequestExpect(f).Protocol("udp").
|
|
|
|
PortName(udpPortName).ExpectError(configures.expectError).Explain("udp proxy").Ensure()
|
|
|
|
}
|
|
|
|
|
|
|
|
// defineClientServerTest test a normal tcp and udp proxy with specified TestConfigures.
|
|
|
|
func defineClientServerTest(desc string, f *framework.Framework, configures *generalTestConfigures) {
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It(desc, func() {
|
2021-08-02 13:07:28 +08:00
|
|
|
runClientServerTest(f, configures)
|
2020-09-07 14:57:23 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
var _ = ginkgo.Describe("[Feature: Client-Server]", func() {
|
2020-09-07 14:57:23 +08:00
|
|
|
f := framework.NewDefaultFramework()
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.Describe("Protocol", func() {
|
2020-09-07 14:57:23 +08:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.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,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.Describe("TLS", func() {
|
2020-09-07 15:45:44 +08:00
|
|
|
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
|
|
|
})
|
2021-08-02 13:07:28 +08:00
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.Describe("TLS with custom certificate", func() {
|
2021-08-02 13:07:28 +08:00
|
|
|
supportProtocols := []string{"tcp", "kcp", "websocket"}
|
|
|
|
|
|
|
|
var (
|
|
|
|
caCrtPath string
|
|
|
|
serverCrtPath, serverKeyPath string
|
|
|
|
clientCrtPath, clientKeyPath string
|
|
|
|
)
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.JustBeforeEach(func() {
|
2021-08-02 13:07:28 +08:00
|
|
|
generator := &cert.SelfSignedCertGenerator{}
|
|
|
|
artifacts, err := generator.Generate("0.0.0.0")
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
|
|
|
caCrtPath = f.WriteTempFile("ca.crt", string(artifacts.CACert))
|
|
|
|
serverCrtPath = f.WriteTempFile("server.crt", string(artifacts.Cert))
|
|
|
|
serverKeyPath = f.WriteTempFile("server.key", string(artifacts.Key))
|
|
|
|
generator.SetCA(artifacts.CACert, artifacts.CAKey)
|
2022-08-29 01:02:53 +08:00
|
|
|
_, err = generator.Generate("0.0.0.0")
|
|
|
|
framework.ExpectNoError(err)
|
2021-08-02 13:07:28 +08:00
|
|
|
clientCrtPath = f.WriteTempFile("client.crt", string(artifacts.Cert))
|
|
|
|
clientKeyPath = f.WriteTempFile("client.key", string(artifacts.Key))
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, protocol := range supportProtocols {
|
|
|
|
tmp := protocol
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("one-way authentication: "+tmp, func() {
|
2021-08-02 13:07:28 +08:00
|
|
|
runClientServerTest(f, &generalTestConfigures{
|
|
|
|
server: fmt.Sprintf(`
|
|
|
|
protocol = %s
|
|
|
|
kcp_bind_port = {{ .%s }}
|
|
|
|
tls_trusted_ca_file = %s
|
|
|
|
`, tmp, consts.PortServerName, caCrtPath),
|
|
|
|
client: fmt.Sprintf(`
|
|
|
|
protocol = %s
|
|
|
|
tls_enable = true
|
|
|
|
tls_cert_file = %s
|
|
|
|
tls_key_file = %s
|
|
|
|
`, tmp, clientCrtPath, clientKeyPath),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("mutual authentication: "+tmp, func() {
|
2021-08-02 13:07:28 +08:00
|
|
|
runClientServerTest(f, &generalTestConfigures{
|
|
|
|
server: fmt.Sprintf(`
|
|
|
|
protocol = %s
|
|
|
|
kcp_bind_port = {{ .%s }}
|
|
|
|
tls_cert_file = %s
|
|
|
|
tls_key_file = %s
|
|
|
|
tls_trusted_ca_file = %s
|
|
|
|
`, tmp, consts.PortServerName, serverCrtPath, serverKeyPath, caCrtPath),
|
|
|
|
client: fmt.Sprintf(`
|
|
|
|
protocol = %s
|
|
|
|
tls_enable = true
|
|
|
|
tls_cert_file = %s
|
|
|
|
tls_key_file = %s
|
|
|
|
tls_trusted_ca_file = %s
|
|
|
|
`, tmp, clientCrtPath, clientKeyPath, caCrtPath),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.Describe("TLS with custom certificate and specified server name", func() {
|
2021-08-02 13:07:28 +08:00
|
|
|
var (
|
|
|
|
caCrtPath string
|
|
|
|
serverCrtPath, serverKeyPath string
|
|
|
|
clientCrtPath, clientKeyPath string
|
|
|
|
)
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.JustBeforeEach(func() {
|
2021-08-02 13:07:28 +08:00
|
|
|
generator := &cert.SelfSignedCertGenerator{}
|
|
|
|
artifacts, err := generator.Generate("example.com")
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
|
|
|
caCrtPath = f.WriteTempFile("ca.crt", string(artifacts.CACert))
|
|
|
|
serverCrtPath = f.WriteTempFile("server.crt", string(artifacts.Cert))
|
|
|
|
serverKeyPath = f.WriteTempFile("server.key", string(artifacts.Key))
|
|
|
|
generator.SetCA(artifacts.CACert, artifacts.CAKey)
|
2022-08-29 01:02:53 +08:00
|
|
|
_, err = generator.Generate("example.com")
|
|
|
|
framework.ExpectNoError(err)
|
2021-08-02 13:07:28 +08:00
|
|
|
clientCrtPath = f.WriteTempFile("client.crt", string(artifacts.Cert))
|
|
|
|
clientKeyPath = f.WriteTempFile("client.key", string(artifacts.Key))
|
|
|
|
})
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("mutual authentication", func() {
|
2021-08-02 13:07:28 +08:00
|
|
|
runClientServerTest(f, &generalTestConfigures{
|
|
|
|
server: fmt.Sprintf(`
|
|
|
|
tls_cert_file = %s
|
|
|
|
tls_key_file = %s
|
|
|
|
tls_trusted_ca_file = %s
|
|
|
|
`, serverCrtPath, serverKeyPath, caCrtPath),
|
|
|
|
client: fmt.Sprintf(`
|
|
|
|
tls_enable = true
|
|
|
|
tls_server_name = example.com
|
|
|
|
tls_cert_file = %s
|
|
|
|
tls_key_file = %s
|
|
|
|
tls_trusted_ca_file = %s
|
|
|
|
`, clientCrtPath, clientKeyPath, caCrtPath),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("mutual authentication with incorrect server name", func() {
|
2021-08-02 13:07:28 +08:00
|
|
|
runClientServerTest(f, &generalTestConfigures{
|
|
|
|
server: fmt.Sprintf(`
|
|
|
|
tls_cert_file = %s
|
|
|
|
tls_key_file = %s
|
|
|
|
tls_trusted_ca_file = %s
|
|
|
|
`, serverCrtPath, serverKeyPath, caCrtPath),
|
|
|
|
client: fmt.Sprintf(`
|
|
|
|
tls_enable = true
|
|
|
|
tls_server_name = invalid.com
|
|
|
|
tls_cert_file = %s
|
|
|
|
tls_key_file = %s
|
|
|
|
tls_trusted_ca_file = %s
|
|
|
|
`, clientCrtPath, clientKeyPath, caCrtPath),
|
|
|
|
expectError: true,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2021-08-11 23:10:35 +08:00
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.Describe("TLS with disable_custom_tls_first_byte", func() {
|
2021-08-11 23:10:35 +08:00
|
|
|
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
|
|
|
|
disable_custom_tls_first_byte = true
|
|
|
|
`, protocol),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2022-02-09 15:19:35 +08:00
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.Describe("IPv6 bind address", func() {
|
2022-02-09 15:19:35 +08:00
|
|
|
supportProtocols := []string{"tcp", "kcp", "websocket"}
|
|
|
|
for _, protocol := range supportProtocols {
|
|
|
|
tmp := protocol
|
|
|
|
defineClientServerTest("IPv6 bind address: "+strings.ToUpper(tmp), f, &generalTestConfigures{
|
|
|
|
server: fmt.Sprintf(`
|
|
|
|
bind_addr = ::
|
|
|
|
kcp_bind_port = {{ .%s }}
|
|
|
|
protocol = %s
|
|
|
|
`, consts.PortServerName, protocol),
|
|
|
|
client: fmt.Sprintf(`
|
|
|
|
tls_enable = true
|
|
|
|
protocol = %s
|
|
|
|
disable_custom_tls_first_byte = true
|
|
|
|
`, protocol),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2020-09-07 14:57:23 +08:00
|
|
|
})
|