mirror of
https://github.com/fatedier/frp.git
synced 2025-07-29 09:18:11 +00:00
add e2e tests (#2334)
This commit is contained in:
@@ -3,16 +3,15 @@ package basic
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
)
|
||||
|
||||
var connTimeout = 2 * time.Second
|
||||
|
||||
var _ = Describe("[Feature: Basic]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
@@ -50,21 +49,21 @@ var _ = Describe("[Feature: Basic]", func() {
|
||||
}{
|
||||
{
|
||||
proxyName: "normal",
|
||||
portName: framework.GenPortName("Normal"),
|
||||
portName: port.GenName("Normal"),
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption",
|
||||
portName: framework.GenPortName("WithEncryption"),
|
||||
portName: port.GenName("WithEncryption"),
|
||||
extraConfig: "use_encryption = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-compression",
|
||||
portName: framework.GenPortName("WithCompression"),
|
||||
portName: port.GenName("WithCompression"),
|
||||
extraConfig: "use_compression = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption-and-compression",
|
||||
portName: framework.GenPortName("WithEncryptionAndCompression"),
|
||||
portName: port.GenName("WithEncryptionAndCompression"),
|
||||
extraConfig: `
|
||||
use_encryption = true
|
||||
use_compression = true
|
||||
@@ -80,8 +79,11 @@ var _ = Describe("[Feature: Basic]", func() {
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
for _, test := range tests {
|
||||
framework.ExpectRequest(protocol, f.UsedPorts[test.portName],
|
||||
[]byte(consts.TestString), []byte(consts.TestString), connTimeout, test.proxyName)
|
||||
framework.NewRequestExpect(f).
|
||||
Request(framework.SetRequestProtocol(protocol)).
|
||||
PortName(test.portName).
|
||||
Explain(test.proxyName).
|
||||
Ensure()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -139,24 +141,24 @@ var _ = Describe("[Feature: Basic]", func() {
|
||||
}{
|
||||
{
|
||||
proxyName: "normal",
|
||||
bindPortName: framework.GenPortName("Normal"),
|
||||
bindPortName: port.GenName("Normal"),
|
||||
visitorSK: correctSK,
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption",
|
||||
bindPortName: framework.GenPortName("WithEncryption"),
|
||||
bindPortName: port.GenName("WithEncryption"),
|
||||
visitorSK: correctSK,
|
||||
extraConfig: "use_encryption = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-compression",
|
||||
bindPortName: framework.GenPortName("WithCompression"),
|
||||
bindPortName: port.GenName("WithCompression"),
|
||||
visitorSK: correctSK,
|
||||
extraConfig: "use_compression = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption-and-compression",
|
||||
bindPortName: framework.GenPortName("WithEncryptionAndCompression"),
|
||||
bindPortName: port.GenName("WithEncryptionAndCompression"),
|
||||
visitorSK: correctSK,
|
||||
extraConfig: `
|
||||
use_encryption = true
|
||||
@@ -165,7 +167,7 @@ var _ = Describe("[Feature: Basic]", func() {
|
||||
},
|
||||
{
|
||||
proxyName: "with-error-sk",
|
||||
bindPortName: framework.GenPortName("WithErrorSK"),
|
||||
bindPortName: port.GenName("WithErrorSK"),
|
||||
visitorSK: wrongSK,
|
||||
expectError: true,
|
||||
},
|
||||
@@ -182,17 +184,89 @@ var _ = Describe("[Feature: Basic]", func() {
|
||||
f.RunProcesses([]string{serverConf}, []string{clientServerConf, clientVisitorConf})
|
||||
|
||||
for _, test := range tests {
|
||||
expectResp := []byte(consts.TestString)
|
||||
if test.expectError {
|
||||
framework.ExpectRequestError(protocol, f.UsedPorts[test.bindPortName],
|
||||
[]byte(consts.TestString), connTimeout, test.proxyName)
|
||||
continue
|
||||
}
|
||||
framework.NewRequestExpect(f).
|
||||
Request(framework.SetRequestProtocol(protocol)).
|
||||
PortName(test.bindPortName).
|
||||
Explain(test.proxyName).
|
||||
ExpectError(test.expectError).
|
||||
Ensure()
|
||||
|
||||
framework.ExpectRequest(protocol, f.UsedPorts[test.bindPortName],
|
||||
[]byte(consts.TestString), expectResp, connTimeout, test.proxyName)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Describe("TCPMUX", func() {
|
||||
It("Type tcpmux", func() {
|
||||
serverConf := consts.DefaultServerConfig
|
||||
clientConf := consts.DefaultClientConfig
|
||||
|
||||
tcpmuxHTTPConnectPortName := port.GenName("TCPMUX")
|
||||
serverConf += fmt.Sprintf(`
|
||||
tcpmux_httpconnect_port = {{ .%s }}
|
||||
`, tcpmuxHTTPConnectPortName)
|
||||
|
||||
getProxyConf := func(proxyName string, extra string) string {
|
||||
return fmt.Sprintf(`
|
||||
[%s]
|
||||
type = tcpmux
|
||||
multiplexer = httpconnect
|
||||
local_port = {{ .%s }}
|
||||
custom_domains = %s
|
||||
`+extra, proxyName, framework.TCPEchoServerPort, proxyName)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
proxyName string
|
||||
portName string
|
||||
extraConfig string
|
||||
}{
|
||||
{
|
||||
proxyName: "normal",
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption",
|
||||
extraConfig: "use_encryption = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-compression",
|
||||
extraConfig: "use_compression = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption-and-compression",
|
||||
extraConfig: `
|
||||
use_encryption = true
|
||||
use_compression = true
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
// build all client config
|
||||
for _, test := range tests {
|
||||
clientConf += getProxyConf(test.proxyName, test.extraConfig) + "\n"
|
||||
}
|
||||
// run frps and frpc
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
// Request without HTTP connect should get error
|
||||
framework.NewRequestExpect(f).
|
||||
PortName(tcpmuxHTTPConnectPortName).
|
||||
ExpectError(true).
|
||||
Explain("request without HTTP connect expect error").
|
||||
Ensure()
|
||||
|
||||
proxyURL := fmt.Sprintf("http://127.0.0.1:%d", f.PortByName(tcpmuxHTTPConnectPortName))
|
||||
// Request with incorrect connect hostname
|
||||
framework.NewRequestExpect(f).Request(func(r *request.Request) {
|
||||
r.Proxy(proxyURL, "invalid")
|
||||
}).ExpectError(true).Explain("request without HTTP connect expect error").Ensure()
|
||||
|
||||
// Request with correct connect hostname
|
||||
for _, test := range tests {
|
||||
framework.NewRequestExpect(f).Request(func(r *request.Request) {
|
||||
r.Proxy(proxyURL, test.proxyName)
|
||||
}).Explain(test.proxyName).Ensure()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"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"
|
||||
)
|
||||
@@ -16,6 +17,7 @@ type generalTestConfigures struct {
|
||||
expectError bool
|
||||
}
|
||||
|
||||
// defineClientServerTest test a normal tcp and udp proxy with specified TestConfigures.
|
||||
func defineClientServerTest(desc string, f *framework.Framework, configures *generalTestConfigures) {
|
||||
It(desc, func() {
|
||||
serverConf := consts.DefaultServerConfig
|
||||
@@ -25,6 +27,8 @@ func defineClientServerTest(desc string, f *framework.Framework, configures *gen
|
||||
%s
|
||||
`, configures.server)
|
||||
|
||||
tcpPortName := port.GenName("TCP")
|
||||
udpPortName := port.GenName("UDP")
|
||||
clientConf += fmt.Sprintf(`
|
||||
%s
|
||||
|
||||
@@ -38,23 +42,15 @@ func defineClientServerTest(desc string, f *framework.Framework, configures *gen
|
||||
local_port = {{ .%s }}
|
||||
remote_port = {{ .%s }}
|
||||
`, configures.client,
|
||||
framework.TCPEchoServerPort, framework.GenPortName("TCP"),
|
||||
framework.UDPEchoServerPort, framework.GenPortName("UDP"),
|
||||
framework.TCPEchoServerPort, tcpPortName,
|
||||
framework.UDPEchoServerPort, udpPortName,
|
||||
)
|
||||
|
||||
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")
|
||||
}
|
||||
framework.NewRequestExpect(f).PortName(tcpPortName).ExpectError(configures.expectError).Explain("tcp proxy").Ensure()
|
||||
framework.NewRequestExpect(f).Request(framework.SetRequestProtocol("udp")).
|
||||
PortName(udpPortName).ExpectError(configures.expectError).Explain("udp proxy").Ensure()
|
||||
})
|
||||
}
|
||||
|
||||
|
79
test/e2e/basic/server.go
Normal file
79
test/e2e/basic/server.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
)
|
||||
|
||||
var _ = Describe("[Feature: Server Manager]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
It("Ports Whitelist", func() {
|
||||
serverConf := consts.DefaultServerConfig
|
||||
clientConf := consts.DefaultClientConfig
|
||||
|
||||
serverConf += `
|
||||
allow_ports = 10000-20000,20002,30000-50000
|
||||
`
|
||||
|
||||
tcpPortName := port.GenName("TCP", port.WithRangePorts(10000, 20000))
|
||||
udpPortName := port.GenName("UDP", port.WithRangePorts(30000, 50000))
|
||||
clientConf += fmt.Sprintf(`
|
||||
[tcp-allowded-in-range]
|
||||
type = tcp
|
||||
local_port = {{ .%s }}
|
||||
remote_port = {{ .%s }}
|
||||
`, framework.TCPEchoServerPort, tcpPortName)
|
||||
clientConf += fmt.Sprintf(`
|
||||
[tcp-port-not-allowed]
|
||||
type = tcp
|
||||
local_port = {{ .%s }}
|
||||
remote_port = 20001
|
||||
`, framework.TCPEchoServerPort)
|
||||
clientConf += fmt.Sprintf(`
|
||||
[tcp-port-unavailable]
|
||||
type = tcp
|
||||
local_port = {{ .%s }}
|
||||
remote_port = {{ .%s }}
|
||||
`, framework.TCPEchoServerPort, consts.PortServerName)
|
||||
clientConf += fmt.Sprintf(`
|
||||
[udp-allowed-in-range]
|
||||
type = udp
|
||||
local_port = {{ .%s }}
|
||||
remote_port = {{ .%s }}
|
||||
`, framework.UDPEchoServerPort, udpPortName)
|
||||
clientConf += fmt.Sprintf(`
|
||||
[udp-port-not-allowed]
|
||||
type = udp
|
||||
local_port = {{ .%s }}
|
||||
remote_port = 20003
|
||||
`, framework.UDPEchoServerPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
// TCP
|
||||
// Allowed in range
|
||||
framework.NewRequestExpect(f).PortName(tcpPortName).Ensure()
|
||||
|
||||
// Not Allowed
|
||||
framework.NewRequestExpect(f).Request(framework.SetRequestPort(20001)).ExpectError(true).Ensure()
|
||||
|
||||
// Unavailable, already bind by frps
|
||||
framework.NewRequestExpect(f).PortName(consts.PortServerName).ExpectError(true).Ensure()
|
||||
|
||||
// UDP
|
||||
// Allowed in range
|
||||
framework.NewRequestExpect(f).Request(framework.SetRequestProtocol("udp")).PortName(udpPortName).Ensure()
|
||||
|
||||
// Not Allowed
|
||||
framework.NewRequestExpect(f).Request(func(r *request.Request) {
|
||||
r.UDP().Port(20003)
|
||||
}).ExpectError(true).Ensure()
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user