mirror of
https://github.com/fatedier/frp.git
synced 2026-01-11 22:23:12 +00:00
add e2e tests for v1 config (#3608)
This commit is contained in:
516
test/e2e/legacy/basic/basic.go
Normal file
516
test/e2e/legacy/basic/basic.go
Normal file
@@ -0,0 +1,516 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
|
||||
"github.com/fatedier/frp/pkg/transport"
|
||||
"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/port"
|
||||
"github.com/fatedier/frp/test/e2e/pkg/request"
|
||||
)
|
||||
|
||||
var _ = ginkgo.Describe("[Feature: Basic]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
ginkgo.Describe("TCP && UDP", func() {
|
||||
types := []string{"tcp", "udp"}
|
||||
for _, t := range types {
|
||||
proxyType := t
|
||||
ginkgo.It(fmt.Sprintf("Expose a %s echo server", strings.ToUpper(proxyType)), func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
|
||||
localPortName := ""
|
||||
protocol := "tcp"
|
||||
switch proxyType {
|
||||
case "tcp":
|
||||
localPortName = framework.TCPEchoServerPort
|
||||
protocol = "tcp"
|
||||
case "udp":
|
||||
localPortName = framework.UDPEchoServerPort
|
||||
protocol = "udp"
|
||||
}
|
||||
getProxyConf := func(proxyName string, portName string, extra string) string {
|
||||
return fmt.Sprintf(`
|
||||
[%s]
|
||||
type = %s
|
||||
local_port = {{ .%s }}
|
||||
remote_port = {{ .%s }}
|
||||
`+extra, proxyName, proxyType, localPortName, portName)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
proxyName string
|
||||
portName string
|
||||
extraConfig string
|
||||
}{
|
||||
{
|
||||
proxyName: "normal",
|
||||
portName: port.GenName("Normal"),
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption",
|
||||
portName: port.GenName("WithEncryption"),
|
||||
extraConfig: "use_encryption = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-compression",
|
||||
portName: port.GenName("WithCompression"),
|
||||
extraConfig: "use_compression = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption-and-compression",
|
||||
portName: port.GenName("WithEncryptionAndCompression"),
|
||||
extraConfig: `
|
||||
use_encryption = true
|
||||
use_compression = true
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
// build all client config
|
||||
for _, test := range tests {
|
||||
clientConf += getProxyConf(test.proxyName, test.portName, test.extraConfig) + "\n"
|
||||
}
|
||||
// run frps and frpc
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
for _, test := range tests {
|
||||
framework.NewRequestExpect(f).
|
||||
Protocol(protocol).
|
||||
PortName(test.portName).
|
||||
Explain(test.proxyName).
|
||||
Ensure()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
ginkgo.Describe("HTTP", func() {
|
||||
ginkgo.It("proxy to HTTP server", func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
vhostHTTPPort := f.AllocPort()
|
||||
serverConf += fmt.Sprintf(`
|
||||
vhost_http_port = %d
|
||||
`, vhostHTTPPort)
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
|
||||
getProxyConf := func(proxyName string, customDomains string, extra string) string {
|
||||
return fmt.Sprintf(`
|
||||
[%s]
|
||||
type = http
|
||||
local_port = {{ .%s }}
|
||||
custom_domains = %s
|
||||
`+extra, proxyName, framework.HTTPSimpleServerPort, customDomains)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
proxyName string
|
||||
customDomains 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
|
||||
`,
|
||||
},
|
||||
{
|
||||
proxyName: "multiple-custom-domains",
|
||||
customDomains: "a.example.com, b.example.com",
|
||||
},
|
||||
}
|
||||
|
||||
// build all client config
|
||||
for i, test := range tests {
|
||||
if tests[i].customDomains == "" {
|
||||
tests[i].customDomains = test.proxyName + ".example.com"
|
||||
}
|
||||
clientConf += getProxyConf(test.proxyName, tests[i].customDomains, test.extraConfig) + "\n"
|
||||
}
|
||||
// run frps and frpc
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
for _, test := range tests {
|
||||
for _, domain := range strings.Split(test.customDomains, ",") {
|
||||
domain = strings.TrimSpace(domain)
|
||||
framework.NewRequestExpect(f).
|
||||
Explain(test.proxyName + "-" + domain).
|
||||
Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost(domain)
|
||||
}).
|
||||
Ensure()
|
||||
}
|
||||
}
|
||||
|
||||
// not exist host
|
||||
framework.NewRequestExpect(f).
|
||||
Explain("not exist host").
|
||||
Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("not-exist.example.com")
|
||||
}).
|
||||
Ensure(framework.ExpectResponseCode(404))
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.Describe("HTTPS", func() {
|
||||
ginkgo.It("proxy to HTTPS server", func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
vhostHTTPSPort := f.AllocPort()
|
||||
serverConf += fmt.Sprintf(`
|
||||
vhost_https_port = %d
|
||||
`, vhostHTTPSPort)
|
||||
|
||||
localPort := f.AllocPort()
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
getProxyConf := func(proxyName string, customDomains string, extra string) string {
|
||||
return fmt.Sprintf(`
|
||||
[%s]
|
||||
type = https
|
||||
local_port = %d
|
||||
custom_domains = %s
|
||||
`+extra, proxyName, localPort, customDomains)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
proxyName string
|
||||
customDomains 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
|
||||
`,
|
||||
},
|
||||
{
|
||||
proxyName: "multiple-custom-domains",
|
||||
customDomains: "a.example.com, b.example.com",
|
||||
},
|
||||
}
|
||||
|
||||
// build all client config
|
||||
for i, test := range tests {
|
||||
if tests[i].customDomains == "" {
|
||||
tests[i].customDomains = test.proxyName + ".example.com"
|
||||
}
|
||||
clientConf += getProxyConf(test.proxyName, tests[i].customDomains, test.extraConfig) + "\n"
|
||||
}
|
||||
// run frps and frpc
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
tlsConfig, err := transport.NewServerTLSConfig("", "", "")
|
||||
framework.ExpectNoError(err)
|
||||
localServer := httpserver.New(
|
||||
httpserver.WithBindPort(localPort),
|
||||
httpserver.WithTLSConfig(tlsConfig),
|
||||
httpserver.WithResponse([]byte("test")),
|
||||
)
|
||||
f.RunServer("", localServer)
|
||||
|
||||
for _, test := range tests {
|
||||
for _, domain := range strings.Split(test.customDomains, ",") {
|
||||
domain = strings.TrimSpace(domain)
|
||||
framework.NewRequestExpect(f).
|
||||
Explain(test.proxyName + "-" + domain).
|
||||
Port(vhostHTTPSPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTPS().HTTPHost(domain).TLSConfig(&tls.Config{
|
||||
ServerName: domain,
|
||||
InsecureSkipVerify: true,
|
||||
})
|
||||
}).
|
||||
ExpectResp([]byte("test")).
|
||||
Ensure()
|
||||
}
|
||||
}
|
||||
|
||||
// not exist host
|
||||
notExistDomain := "not-exist.example.com"
|
||||
framework.NewRequestExpect(f).
|
||||
Explain("not exist host").
|
||||
Port(vhostHTTPSPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTPS().HTTPHost(notExistDomain).TLSConfig(&tls.Config{
|
||||
ServerName: notExistDomain,
|
||||
InsecureSkipVerify: true,
|
||||
})
|
||||
}).
|
||||
ExpectError(true).
|
||||
Ensure()
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.Describe("STCP && SUDP && XTCP", func() {
|
||||
types := []string{"stcp", "sudp", "xtcp"}
|
||||
for _, t := range types {
|
||||
proxyType := t
|
||||
ginkgo.It(fmt.Sprintf("Expose echo server with %s", strings.ToUpper(proxyType)), func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
clientServerConf := consts.LegacyDefaultClientConfig + "\nuser = user1"
|
||||
clientVisitorConf := consts.LegacyDefaultClientConfig + "\nuser = user1"
|
||||
clientUser2VisitorConf := consts.LegacyDefaultClientConfig + "\nuser = user2"
|
||||
|
||||
localPortName := ""
|
||||
protocol := "tcp"
|
||||
switch proxyType {
|
||||
case "stcp":
|
||||
localPortName = framework.TCPEchoServerPort
|
||||
protocol = "tcp"
|
||||
case "sudp":
|
||||
localPortName = framework.UDPEchoServerPort
|
||||
protocol = "udp"
|
||||
case "xtcp":
|
||||
localPortName = framework.TCPEchoServerPort
|
||||
protocol = "tcp"
|
||||
ginkgo.Skip("stun server is not stable")
|
||||
}
|
||||
|
||||
correctSK := "abc"
|
||||
wrongSK := "123"
|
||||
|
||||
getProxyServerConf := func(proxyName string, extra string) string {
|
||||
return fmt.Sprintf(`
|
||||
[%s]
|
||||
type = %s
|
||||
role = server
|
||||
sk = %s
|
||||
local_port = {{ .%s }}
|
||||
`+extra, proxyName, proxyType, correctSK, localPortName)
|
||||
}
|
||||
getProxyVisitorConf := func(proxyName string, portName, visitorSK, extra string) string {
|
||||
return fmt.Sprintf(`
|
||||
[%s]
|
||||
type = %s
|
||||
role = visitor
|
||||
server_name = %s
|
||||
sk = %s
|
||||
bind_port = {{ .%s }}
|
||||
`+extra, proxyName, proxyType, proxyName, visitorSK, portName)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
proxyName string
|
||||
bindPortName string
|
||||
visitorSK string
|
||||
commonExtraConfig string
|
||||
proxyExtraConfig string
|
||||
visitorExtraConfig string
|
||||
expectError bool
|
||||
deployUser2Client bool
|
||||
// skipXTCP is used to skip xtcp test case
|
||||
skipXTCP bool
|
||||
}{
|
||||
{
|
||||
proxyName: "normal",
|
||||
bindPortName: port.GenName("Normal"),
|
||||
visitorSK: correctSK,
|
||||
skipXTCP: true,
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption",
|
||||
bindPortName: port.GenName("WithEncryption"),
|
||||
visitorSK: correctSK,
|
||||
commonExtraConfig: "use_encryption = true",
|
||||
skipXTCP: true,
|
||||
},
|
||||
{
|
||||
proxyName: "with-compression",
|
||||
bindPortName: port.GenName("WithCompression"),
|
||||
visitorSK: correctSK,
|
||||
commonExtraConfig: "use_compression = true",
|
||||
skipXTCP: true,
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption-and-compression",
|
||||
bindPortName: port.GenName("WithEncryptionAndCompression"),
|
||||
visitorSK: correctSK,
|
||||
commonExtraConfig: `
|
||||
use_encryption = true
|
||||
use_compression = true
|
||||
`,
|
||||
skipXTCP: true,
|
||||
},
|
||||
{
|
||||
proxyName: "with-error-sk",
|
||||
bindPortName: port.GenName("WithErrorSK"),
|
||||
visitorSK: wrongSK,
|
||||
expectError: true,
|
||||
},
|
||||
{
|
||||
proxyName: "allowed-user",
|
||||
bindPortName: port.GenName("AllowedUser"),
|
||||
visitorSK: correctSK,
|
||||
proxyExtraConfig: "allow_users = another, user2",
|
||||
visitorExtraConfig: "server_user = user1",
|
||||
deployUser2Client: true,
|
||||
},
|
||||
{
|
||||
proxyName: "not-allowed-user",
|
||||
bindPortName: port.GenName("NotAllowedUser"),
|
||||
visitorSK: correctSK,
|
||||
proxyExtraConfig: "allow_users = invalid",
|
||||
visitorExtraConfig: "server_user = user1",
|
||||
expectError: true,
|
||||
},
|
||||
{
|
||||
proxyName: "allow-all",
|
||||
bindPortName: port.GenName("AllowAll"),
|
||||
visitorSK: correctSK,
|
||||
proxyExtraConfig: "allow_users = *",
|
||||
visitorExtraConfig: "server_user = user1",
|
||||
deployUser2Client: true,
|
||||
},
|
||||
}
|
||||
|
||||
// build all client config
|
||||
for _, test := range tests {
|
||||
clientServerConf += getProxyServerConf(test.proxyName, test.commonExtraConfig+"\n"+test.proxyExtraConfig) + "\n"
|
||||
}
|
||||
for _, test := range tests {
|
||||
config := getProxyVisitorConf(
|
||||
test.proxyName, test.bindPortName, test.visitorSK, test.commonExtraConfig+"\n"+test.visitorExtraConfig,
|
||||
) + "\n"
|
||||
if test.deployUser2Client {
|
||||
clientUser2VisitorConf += config
|
||||
} else {
|
||||
clientVisitorConf += config
|
||||
}
|
||||
}
|
||||
// run frps and frpc
|
||||
f.RunProcesses([]string{serverConf}, []string{clientServerConf, clientVisitorConf, clientUser2VisitorConf})
|
||||
|
||||
for _, test := range tests {
|
||||
timeout := time.Second
|
||||
if t == "xtcp" {
|
||||
if test.skipXTCP {
|
||||
continue
|
||||
}
|
||||
timeout = 10 * time.Second
|
||||
}
|
||||
framework.NewRequestExpect(f).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.Timeout(timeout)
|
||||
}).
|
||||
Protocol(protocol).
|
||||
PortName(test.bindPortName).
|
||||
Explain(test.proxyName).
|
||||
ExpectError(test.expectError).
|
||||
Ensure()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
ginkgo.Describe("TCPMUX", func() {
|
||||
ginkgo.It("Type tcpmux", func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
|
||||
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, port.GenName(proxyName), proxyName)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
proxyName 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"
|
||||
|
||||
localServer := streamserver.New(streamserver.TCP, streamserver.WithBindPort(f.AllocPort()), streamserver.WithRespContent([]byte(test.proxyName)))
|
||||
f.RunServer(port.GenName(test.proxyName), localServer)
|
||||
}
|
||||
|
||||
// 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).RequestModify(func(r *request.Request) {
|
||||
r.Addr("invalid").Proxy(proxyURL)
|
||||
}).ExpectError(true).Explain("request without HTTP connect expect error").Ensure()
|
||||
|
||||
// Request with correct connect hostname
|
||||
for _, test := range tests {
|
||||
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
|
||||
r.Addr(test.proxyName).Proxy(proxyURL)
|
||||
}).ExpectResp([]byte(test.proxyName)).Explain(test.proxyName).Ensure()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
132
test/e2e/legacy/basic/client.go
Normal file
132
test/e2e/legacy/basic/client.go
Normal file
@@ -0,0 +1,132 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
var _ = ginkgo.Describe("[Feature: ClientManage]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
ginkgo.It("Update && Reload API", func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
|
||||
adminPort := f.AllocPort()
|
||||
|
||||
p1Port := f.AllocPort()
|
||||
p2Port := f.AllocPort()
|
||||
p3Port := f.AllocPort()
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig + fmt.Sprintf(`
|
||||
admin_port = %d
|
||||
|
||||
[p1]
|
||||
type = tcp
|
||||
local_port = {{ .%s }}
|
||||
remote_port = %d
|
||||
|
||||
[p2]
|
||||
type = tcp
|
||||
local_port = {{ .%s }}
|
||||
remote_port = %d
|
||||
|
||||
[p3]
|
||||
type = tcp
|
||||
local_port = {{ .%s }}
|
||||
remote_port = %d
|
||||
`, adminPort,
|
||||
framework.TCPEchoServerPort, p1Port,
|
||||
framework.TCPEchoServerPort, p2Port,
|
||||
framework.TCPEchoServerPort, p3Port)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).Port(p1Port).Ensure()
|
||||
framework.NewRequestExpect(f).Port(p2Port).Ensure()
|
||||
framework.NewRequestExpect(f).Port(p3Port).Ensure()
|
||||
|
||||
client := clientsdk.New("127.0.0.1", adminPort)
|
||||
conf, err := client.GetConfig()
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
newP2Port := f.AllocPort()
|
||||
// change p2 port and remove p3 proxy
|
||||
newClientConf := strings.ReplaceAll(conf, strconv.Itoa(p2Port), strconv.Itoa(newP2Port))
|
||||
p3Index := strings.Index(newClientConf, "[p3]")
|
||||
if p3Index >= 0 {
|
||||
newClientConf = newClientConf[:p3Index]
|
||||
}
|
||||
|
||||
err = client.UpdateConfig(newClientConf)
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
err = client.Reload()
|
||||
framework.ExpectNoError(err)
|
||||
time.Sleep(time.Second)
|
||||
|
||||
framework.NewRequestExpect(f).Port(p1Port).Explain("p1 port").Ensure()
|
||||
framework.NewRequestExpect(f).Port(p2Port).Explain("original p2 port").ExpectError(true).Ensure()
|
||||
framework.NewRequestExpect(f).Port(newP2Port).Explain("new p2 port").Ensure()
|
||||
framework.NewRequestExpect(f).Port(p3Port).Explain("p3 port").ExpectError(true).Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("healthz", func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
|
||||
dashboardPort := f.AllocPort()
|
||||
clientConf := consts.LegacyDefaultClientConfig + fmt.Sprintf(`
|
||||
admin_addr = 0.0.0.0
|
||||
admin_port = %d
|
||||
admin_user = admin
|
||||
admin_pwd = admin
|
||||
`, dashboardPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPPath("/healthz")
|
||||
}).Port(dashboardPort).ExpectResp([]byte("")).Ensure()
|
||||
|
||||
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPPath("/")
|
||||
}).Port(dashboardPort).
|
||||
Ensure(framework.ExpectResponseCode(401))
|
||||
})
|
||||
|
||||
ginkgo.It("stop", func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
|
||||
adminPort := f.AllocPort()
|
||||
testPort := f.AllocPort()
|
||||
clientConf := consts.LegacyDefaultClientConfig + fmt.Sprintf(`
|
||||
admin_port = %d
|
||||
|
||||
[test]
|
||||
type = tcp
|
||||
local_port = {{ .%s }}
|
||||
remote_port = %d
|
||||
`, adminPort, framework.TCPEchoServerPort, testPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).Port(testPort).Ensure()
|
||||
|
||||
client := clientsdk.New("127.0.0.1", adminPort)
|
||||
err := client.Stop()
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
// frpc stopped so the port is not listened, expect error
|
||||
framework.NewRequestExpect(f).Port(testPort).ExpectError(true).Ensure()
|
||||
})
|
||||
})
|
||||
322
test/e2e/legacy/basic/client_server.go
Normal file
322
test/e2e/legacy/basic/client_server.go
Normal file
@@ -0,0 +1,322 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
type generalTestConfigures struct {
|
||||
server string
|
||||
client string
|
||||
clientPrefix string
|
||||
client2 string
|
||||
client2Prefix string
|
||||
testDelay time.Duration
|
||||
expectError bool
|
||||
}
|
||||
|
||||
func renderBindPortConfig(protocol string) string {
|
||||
if protocol == "kcp" {
|
||||
return fmt.Sprintf(`kcp_bind_port = {{ .%s }}`, consts.PortServerName)
|
||||
} else if protocol == "quic" {
|
||||
return fmt.Sprintf(`quic_bind_port = {{ .%s }}`, consts.PortServerName)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func runClientServerTest(f *framework.Framework, configures *generalTestConfigures) {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
if configures.clientPrefix != "" {
|
||||
clientConf = configures.clientPrefix
|
||||
}
|
||||
|
||||
serverConf += fmt.Sprintf(`
|
||||
%s
|
||||
`, configures.server)
|
||||
|
||||
tcpPortName := port.GenName("TCP")
|
||||
udpPortName := port.GenName("UDP")
|
||||
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, tcpPortName,
|
||||
framework.UDPEchoServerPort, udpPortName,
|
||||
)
|
||||
|
||||
clientConfs := []string{clientConf}
|
||||
if configures.client2 != "" {
|
||||
client2Conf := consts.LegacyDefaultClientConfig
|
||||
if configures.client2Prefix != "" {
|
||||
client2Conf = configures.client2Prefix
|
||||
}
|
||||
client2Conf += fmt.Sprintf(`
|
||||
%s
|
||||
`, configures.client2)
|
||||
clientConfs = append(clientConfs, client2Conf)
|
||||
}
|
||||
|
||||
f.RunProcesses([]string{serverConf}, clientConfs)
|
||||
|
||||
if configures.testDelay > 0 {
|
||||
time.Sleep(configures.testDelay)
|
||||
}
|
||||
|
||||
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) {
|
||||
ginkgo.It(desc, func() {
|
||||
runClientServerTest(f, configures)
|
||||
})
|
||||
}
|
||||
|
||||
var _ = ginkgo.Describe("[Feature: Client-Server]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
ginkgo.Describe("Protocol", func() {
|
||||
supportProtocols := []string{"tcp", "kcp", "quic", "websocket"}
|
||||
for _, protocol := range supportProtocols {
|
||||
configures := &generalTestConfigures{
|
||||
server: fmt.Sprintf(`
|
||||
%s
|
||||
`, renderBindPortConfig(protocol)),
|
||||
client: "protocol = " + protocol,
|
||||
}
|
||||
defineClientServerTest(protocol, f, configures)
|
||||
}
|
||||
})
|
||||
|
||||
// wss is special, it needs to be tested separately.
|
||||
// frps only supports ws, so there should be a proxy to terminate TLS before frps.
|
||||
ginkgo.Describe("Protocol wss", func() {
|
||||
wssPort := f.AllocPort()
|
||||
configures := &generalTestConfigures{
|
||||
clientPrefix: fmt.Sprintf(`
|
||||
[common]
|
||||
server_addr = 127.0.0.1
|
||||
server_port = %d
|
||||
protocol = wss
|
||||
log_level = trace
|
||||
login_fail_exit = false
|
||||
`, wssPort),
|
||||
// Due to the fact that frps cannot directly accept wss connections, we use the https2http plugin of another frpc to terminate TLS.
|
||||
client2: fmt.Sprintf(`
|
||||
[wss2ws]
|
||||
type = tcp
|
||||
remote_port = %d
|
||||
plugin = https2http
|
||||
plugin_local_addr = 127.0.0.1:{{ .%s }}
|
||||
`, wssPort, consts.PortServerName),
|
||||
testDelay: 10 * time.Second,
|
||||
}
|
||||
|
||||
defineClientServerTest("wss", f, configures)
|
||||
})
|
||||
|
||||
ginkgo.Describe("Authentication", func() {
|
||||
defineClientServerTest("Token Correct", f, &generalTestConfigures{
|
||||
server: "token = 123456",
|
||||
client: "token = 123456",
|
||||
})
|
||||
|
||||
defineClientServerTest("Token Incorrect", f, &generalTestConfigures{
|
||||
server: "token = 123456",
|
||||
client: "token = invalid",
|
||||
expectError: true,
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.Describe("TLS", func() {
|
||||
supportProtocols := []string{"tcp", "kcp", "quic", "websocket"}
|
||||
for _, protocol := range supportProtocols {
|
||||
tmp := protocol
|
||||
// Since v0.50.0, the default value of tls_enable has been changed to true.
|
||||
// Therefore, here it needs to be set as false to test the scenario of turning it off.
|
||||
defineClientServerTest("Disable TLS over "+strings.ToUpper(tmp), f, &generalTestConfigures{
|
||||
server: fmt.Sprintf(`
|
||||
%s
|
||||
`, renderBindPortConfig(protocol)),
|
||||
client: fmt.Sprintf(`tls_enable = false
|
||||
protocol = %s
|
||||
`, protocol),
|
||||
})
|
||||
}
|
||||
|
||||
defineClientServerTest("enable tls_only, client with TLS", f, &generalTestConfigures{
|
||||
server: "tls_only = true",
|
||||
})
|
||||
defineClientServerTest("enable tls_only, client without TLS", f, &generalTestConfigures{
|
||||
server: "tls_only = true",
|
||||
client: "tls_enable = false",
|
||||
expectError: true,
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.Describe("TLS with custom certificate", func() {
|
||||
supportProtocols := []string{"tcp", "kcp", "quic", "websocket"}
|
||||
|
||||
var (
|
||||
caCrtPath string
|
||||
serverCrtPath, serverKeyPath string
|
||||
clientCrtPath, clientKeyPath string
|
||||
)
|
||||
ginkgo.JustBeforeEach(func() {
|
||||
generator := &cert.SelfSignedCertGenerator{}
|
||||
artifacts, err := generator.Generate("127.0.0.1")
|
||||
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)
|
||||
_, err = generator.Generate("127.0.0.1")
|
||||
framework.ExpectNoError(err)
|
||||
clientCrtPath = f.WriteTempFile("client.crt", string(artifacts.Cert))
|
||||
clientKeyPath = f.WriteTempFile("client.key", string(artifacts.Key))
|
||||
})
|
||||
|
||||
for _, protocol := range supportProtocols {
|
||||
tmp := protocol
|
||||
|
||||
ginkgo.It("one-way authentication: "+tmp, func() {
|
||||
runClientServerTest(f, &generalTestConfigures{
|
||||
server: fmt.Sprintf(`
|
||||
%s
|
||||
tls_trusted_ca_file = %s
|
||||
`, renderBindPortConfig(tmp), caCrtPath),
|
||||
client: fmt.Sprintf(`
|
||||
protocol = %s
|
||||
tls_cert_file = %s
|
||||
tls_key_file = %s
|
||||
`, tmp, clientCrtPath, clientKeyPath),
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.It("mutual authentication: "+tmp, func() {
|
||||
runClientServerTest(f, &generalTestConfigures{
|
||||
server: fmt.Sprintf(`
|
||||
%s
|
||||
tls_cert_file = %s
|
||||
tls_key_file = %s
|
||||
tls_trusted_ca_file = %s
|
||||
`, renderBindPortConfig(tmp), serverCrtPath, serverKeyPath, caCrtPath),
|
||||
client: fmt.Sprintf(`
|
||||
protocol = %s
|
||||
tls_cert_file = %s
|
||||
tls_key_file = %s
|
||||
tls_trusted_ca_file = %s
|
||||
`, tmp, clientCrtPath, clientKeyPath, caCrtPath),
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
ginkgo.Describe("TLS with custom certificate and specified server name", func() {
|
||||
var (
|
||||
caCrtPath string
|
||||
serverCrtPath, serverKeyPath string
|
||||
clientCrtPath, clientKeyPath string
|
||||
)
|
||||
ginkgo.JustBeforeEach(func() {
|
||||
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)
|
||||
_, err = generator.Generate("example.com")
|
||||
framework.ExpectNoError(err)
|
||||
clientCrtPath = f.WriteTempFile("client.crt", string(artifacts.Cert))
|
||||
clientKeyPath = f.WriteTempFile("client.key", string(artifacts.Key))
|
||||
})
|
||||
|
||||
ginkgo.It("mutual authentication", func() {
|
||||
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_server_name = example.com
|
||||
tls_cert_file = %s
|
||||
tls_key_file = %s
|
||||
tls_trusted_ca_file = %s
|
||||
`, clientCrtPath, clientKeyPath, caCrtPath),
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.It("mutual authentication with incorrect server name", func() {
|
||||
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_server_name = invalid.com
|
||||
tls_cert_file = %s
|
||||
tls_key_file = %s
|
||||
tls_trusted_ca_file = %s
|
||||
`, clientCrtPath, clientKeyPath, caCrtPath),
|
||||
expectError: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.Describe("TLS with disable_custom_tls_first_byte set to false", func() {
|
||||
supportProtocols := []string{"tcp", "kcp", "quic", "websocket"}
|
||||
for _, protocol := range supportProtocols {
|
||||
tmp := protocol
|
||||
defineClientServerTest("TLS over "+strings.ToUpper(tmp), f, &generalTestConfigures{
|
||||
server: fmt.Sprintf(`
|
||||
%s
|
||||
`, renderBindPortConfig(protocol)),
|
||||
client: fmt.Sprintf(`
|
||||
protocol = %s
|
||||
disable_custom_tls_first_byte = false
|
||||
`, protocol),
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
ginkgo.Describe("IPv6 bind address", func() {
|
||||
supportProtocols := []string{"tcp", "kcp", "quic", "websocket"}
|
||||
for _, protocol := range supportProtocols {
|
||||
tmp := protocol
|
||||
defineClientServerTest("IPv6 bind address: "+strings.ToUpper(tmp), f, &generalTestConfigures{
|
||||
server: fmt.Sprintf(`
|
||||
bind_addr = ::
|
||||
%s
|
||||
`, renderBindPortConfig(protocol)),
|
||||
client: fmt.Sprintf(`
|
||||
protocol = %s
|
||||
`, protocol),
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
113
test/e2e/legacy/basic/cmd.go
Normal file
113
test/e2e/legacy/basic/cmd.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
|
||||
"github.com/fatedier/frp/test/e2e/framework"
|
||||
"github.com/fatedier/frp/test/e2e/pkg/request"
|
||||
)
|
||||
|
||||
const (
|
||||
ConfigValidStr = "syntax is ok"
|
||||
)
|
||||
|
||||
var _ = ginkgo.Describe("[Feature: Cmd]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
ginkgo.Describe("Verify", func() {
|
||||
ginkgo.It("frps valid", func() {
|
||||
path := f.GenerateConfigFile(`
|
||||
[common]
|
||||
bind_addr = 0.0.0.0
|
||||
bind_port = 7000
|
||||
`)
|
||||
_, output, err := f.RunFrps("verify", "-c", path)
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectTrue(strings.Contains(output, ConfigValidStr), "output: %s", output)
|
||||
})
|
||||
ginkgo.It("frps invalid", func() {
|
||||
path := f.GenerateConfigFile(`
|
||||
[common]
|
||||
bind_addr = 0.0.0.0
|
||||
bind_port = 70000
|
||||
`)
|
||||
_, output, err := f.RunFrps("verify", "-c", path)
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectTrue(!strings.Contains(output, ConfigValidStr), "output: %s", output)
|
||||
})
|
||||
ginkgo.It("frpc valid", func() {
|
||||
path := f.GenerateConfigFile(`
|
||||
[common]
|
||||
server_addr = 0.0.0.0
|
||||
server_port = 7000
|
||||
`)
|
||||
_, output, err := f.RunFrpc("verify", "-c", path)
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectTrue(strings.Contains(output, ConfigValidStr), "output: %s", output)
|
||||
})
|
||||
ginkgo.It("frpc invalid", func() {
|
||||
path := f.GenerateConfigFile(`
|
||||
[common]
|
||||
server_addr = 0.0.0.0
|
||||
server_port = 7000
|
||||
protocol = invalid
|
||||
`)
|
||||
_, output, err := f.RunFrpc("verify", "-c", path)
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectTrue(!strings.Contains(output, ConfigValidStr), "output: %s", output)
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.Describe("Single proxy", func() {
|
||||
ginkgo.It("TCP", func() {
|
||||
serverPort := f.AllocPort()
|
||||
_, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort))
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
localPort := f.PortByName(framework.TCPEchoServerPort)
|
||||
remotePort := f.AllocPort()
|
||||
_, _, err = f.RunFrpc("tcp", "-s", fmt.Sprintf("127.0.0.1:%d", serverPort), "-t", "123", "-u", "test",
|
||||
"-l", strconv.Itoa(localPort), "-r", strconv.Itoa(remotePort), "-n", "tcp_test")
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
framework.NewRequestExpect(f).Port(remotePort).Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("UDP", func() {
|
||||
serverPort := f.AllocPort()
|
||||
_, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort))
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
localPort := f.PortByName(framework.UDPEchoServerPort)
|
||||
remotePort := f.AllocPort()
|
||||
_, _, err = f.RunFrpc("udp", "-s", fmt.Sprintf("127.0.0.1:%d", serverPort), "-t", "123", "-u", "test",
|
||||
"-l", strconv.Itoa(localPort), "-r", strconv.Itoa(remotePort), "-n", "udp_test")
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
framework.NewRequestExpect(f).Protocol("udp").
|
||||
Port(remotePort).Ensure()
|
||||
})
|
||||
|
||||
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))
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
_, _, err = f.RunFrpc("http", "-s", "127.0.0.1:"+strconv.Itoa(serverPort), "-t", "123", "-u", "test",
|
||||
"-n", "udp_test", "-l", strconv.Itoa(f.PortByName(framework.HTTPSimpleServerPort)),
|
||||
"--custom_domain", "test.example.com")
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
framework.NewRequestExpect(f).Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("test.example.com")
|
||||
}).
|
||||
Ensure()
|
||||
})
|
||||
})
|
||||
})
|
||||
83
test/e2e/legacy/basic/config.go
Normal file
83
test/e2e/legacy/basic/config.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
|
||||
"github.com/fatedier/frp/test/e2e/framework"
|
||||
"github.com/fatedier/frp/test/e2e/framework/consts"
|
||||
"github.com/fatedier/frp/test/e2e/pkg/port"
|
||||
)
|
||||
|
||||
var _ = ginkgo.Describe("[Feature: Config]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
ginkgo.Describe("Template", func() {
|
||||
ginkgo.It("render by env", func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
|
||||
portName := port.GenName("TCP")
|
||||
serverConf += fmt.Sprintf(`
|
||||
token = {{ %s{{ .Envs.FRP_TOKEN }}%s }}
|
||||
`, "`", "`")
|
||||
|
||||
clientConf += fmt.Sprintf(`
|
||||
token = {{ %s{{ .Envs.FRP_TOKEN }}%s }}
|
||||
|
||||
[tcp]
|
||||
type = tcp
|
||||
local_port = {{ .%s }}
|
||||
remote_port = {{ .%s }}
|
||||
`, "`", "`", framework.TCPEchoServerPort, portName)
|
||||
|
||||
f.SetEnvs([]string{"FRP_TOKEN=123"})
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).PortName(portName).Ensure()
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.Describe("Includes", func() {
|
||||
ginkgo.It("split tcp proxies into different files", func() {
|
||||
serverPort := f.AllocPort()
|
||||
serverConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
|
||||
[common]
|
||||
bind_addr = 0.0.0.0
|
||||
bind_port = %d
|
||||
`, serverPort))
|
||||
|
||||
remotePort := f.AllocPort()
|
||||
proxyConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
|
||||
[tcp]
|
||||
type = tcp
|
||||
local_port = %d
|
||||
remote_port = %d
|
||||
`, f.PortByName(framework.TCPEchoServerPort), remotePort))
|
||||
|
||||
remotePort2 := f.AllocPort()
|
||||
proxyConfigPath2 := f.GenerateConfigFile(fmt.Sprintf(`
|
||||
[tcp2]
|
||||
type = tcp
|
||||
local_port = %d
|
||||
remote_port = %d
|
||||
`, f.PortByName(framework.TCPEchoServerPort), remotePort2))
|
||||
|
||||
clientConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
|
||||
[common]
|
||||
server_port = %d
|
||||
includes = %s,%s
|
||||
`, serverPort, proxyConfigPath, proxyConfigPath2))
|
||||
|
||||
_, _, err := f.RunFrps("-c", serverConfigPath)
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
_, _, err = f.RunFrpc("-c", clientConfigPath)
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
framework.NewRequestExpect(f).Port(remotePort).Ensure()
|
||||
framework.NewRequestExpect(f).Port(remotePort2).Ensure()
|
||||
})
|
||||
})
|
||||
})
|
||||
376
test/e2e/legacy/basic/http.go
Normal file
376
test/e2e/legacy/basic/http.go
Normal file
@@ -0,0 +1,376 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
var _ = ginkgo.Describe("[Feature: HTTP]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
getDefaultServerConf := func(vhostHTTPPort int) string {
|
||||
conf := consts.LegacyDefaultServerConfig + `
|
||||
vhost_http_port = %d
|
||||
`
|
||||
return fmt.Sprintf(conf, vhostHTTPPort)
|
||||
}
|
||||
newHTTPServer := func(port int, respContent string) *httpserver.Server {
|
||||
return httpserver.New(
|
||||
httpserver.WithBindPort(port),
|
||||
httpserver.WithHandler(framework.SpecifiedHTTPBodyHandler([]byte(respContent))),
|
||||
)
|
||||
}
|
||||
|
||||
ginkgo.It("HTTP route by locations", func() {
|
||||
vhostHTTPPort := f.AllocPort()
|
||||
serverConf := getDefaultServerConf(vhostHTTPPort)
|
||||
|
||||
fooPort := f.AllocPort()
|
||||
f.RunServer("", newHTTPServer(fooPort, "foo"))
|
||||
|
||||
barPort := f.AllocPort()
|
||||
f.RunServer("", newHTTPServer(barPort, "bar"))
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[foo]
|
||||
type = http
|
||||
local_port = %d
|
||||
custom_domains = normal.example.com
|
||||
locations = /,/foo
|
||||
|
||||
[bar]
|
||||
type = http
|
||||
local_port = %d
|
||||
custom_domains = normal.example.com
|
||||
locations = /bar
|
||||
`, fooPort, barPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
tests := []struct {
|
||||
path string
|
||||
expectResp string
|
||||
desc string
|
||||
}{
|
||||
{path: "/foo", expectResp: "foo", desc: "foo path"},
|
||||
{path: "/bar", expectResp: "bar", desc: "bar path"},
|
||||
{path: "/other", expectResp: "foo", desc: "other path"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
framework.NewRequestExpect(f).Explain(test.desc).Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("normal.example.com").HTTPPath(test.path)
|
||||
}).
|
||||
ExpectResp([]byte(test.expectResp)).
|
||||
Ensure()
|
||||
}
|
||||
})
|
||||
|
||||
ginkgo.It("HTTP route by HTTP user", func() {
|
||||
vhostHTTPPort := f.AllocPort()
|
||||
serverConf := getDefaultServerConf(vhostHTTPPort)
|
||||
|
||||
fooPort := f.AllocPort()
|
||||
f.RunServer("", newHTTPServer(fooPort, "foo"))
|
||||
|
||||
barPort := f.AllocPort()
|
||||
f.RunServer("", newHTTPServer(barPort, "bar"))
|
||||
|
||||
otherPort := f.AllocPort()
|
||||
f.RunServer("", newHTTPServer(otherPort, "other"))
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[foo]
|
||||
type = http
|
||||
local_port = %d
|
||||
custom_domains = normal.example.com
|
||||
route_by_http_user = user1
|
||||
|
||||
[bar]
|
||||
type = http
|
||||
local_port = %d
|
||||
custom_domains = normal.example.com
|
||||
route_by_http_user = user2
|
||||
|
||||
[catchAll]
|
||||
type = http
|
||||
local_port = %d
|
||||
custom_domains = normal.example.com
|
||||
`, fooPort, barPort, otherPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
// user1
|
||||
framework.NewRequestExpect(f).Explain("user1").Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("normal.example.com").HTTPAuth("user1", "")
|
||||
}).
|
||||
ExpectResp([]byte("foo")).
|
||||
Ensure()
|
||||
|
||||
// user2
|
||||
framework.NewRequestExpect(f).Explain("user2").Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("normal.example.com").HTTPAuth("user2", "")
|
||||
}).
|
||||
ExpectResp([]byte("bar")).
|
||||
Ensure()
|
||||
|
||||
// other user
|
||||
framework.NewRequestExpect(f).Explain("other user").Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("normal.example.com").HTTPAuth("user3", "")
|
||||
}).
|
||||
ExpectResp([]byte("other")).
|
||||
Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("HTTP Basic Auth", func() {
|
||||
vhostHTTPPort := f.AllocPort()
|
||||
serverConf := getDefaultServerConf(vhostHTTPPort)
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[test]
|
||||
type = http
|
||||
local_port = {{ .%s }}
|
||||
custom_domains = normal.example.com
|
||||
http_user = test
|
||||
http_pwd = test
|
||||
`, framework.HTTPSimpleServerPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
// not set auth header
|
||||
framework.NewRequestExpect(f).Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("normal.example.com")
|
||||
}).
|
||||
Ensure(framework.ExpectResponseCode(401))
|
||||
|
||||
// set incorrect auth header
|
||||
framework.NewRequestExpect(f).Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("normal.example.com").HTTPAuth("test", "invalid")
|
||||
}).
|
||||
Ensure(framework.ExpectResponseCode(401))
|
||||
|
||||
// set correct auth header
|
||||
framework.NewRequestExpect(f).Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("normal.example.com").HTTPAuth("test", "test")
|
||||
}).
|
||||
Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("Wildcard domain", func() {
|
||||
vhostHTTPPort := f.AllocPort()
|
||||
serverConf := getDefaultServerConf(vhostHTTPPort)
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[test]
|
||||
type = http
|
||||
local_port = {{ .%s }}
|
||||
custom_domains = *.example.com
|
||||
`, framework.HTTPSimpleServerPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
// not match host
|
||||
framework.NewRequestExpect(f).Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("not-match.test.com")
|
||||
}).
|
||||
Ensure(framework.ExpectResponseCode(404))
|
||||
|
||||
// test.example.com match *.example.com
|
||||
framework.NewRequestExpect(f).Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("test.example.com")
|
||||
}).
|
||||
Ensure()
|
||||
|
||||
// sub.test.example.com match *.example.com
|
||||
framework.NewRequestExpect(f).Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("sub.test.example.com")
|
||||
}).
|
||||
Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("Subdomain", func() {
|
||||
vhostHTTPPort := f.AllocPort()
|
||||
serverConf := getDefaultServerConf(vhostHTTPPort)
|
||||
serverConf += `
|
||||
subdomain_host = example.com
|
||||
`
|
||||
|
||||
fooPort := f.AllocPort()
|
||||
f.RunServer("", newHTTPServer(fooPort, "foo"))
|
||||
|
||||
barPort := f.AllocPort()
|
||||
f.RunServer("", newHTTPServer(barPort, "bar"))
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[foo]
|
||||
type = http
|
||||
local_port = %d
|
||||
subdomain = foo
|
||||
|
||||
[bar]
|
||||
type = http
|
||||
local_port = %d
|
||||
subdomain = bar
|
||||
`, fooPort, barPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
// foo
|
||||
framework.NewRequestExpect(f).Explain("foo subdomain").Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("foo.example.com")
|
||||
}).
|
||||
ExpectResp([]byte("foo")).
|
||||
Ensure()
|
||||
|
||||
// bar
|
||||
framework.NewRequestExpect(f).Explain("bar subdomain").Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("bar.example.com")
|
||||
}).
|
||||
ExpectResp([]byte("bar")).
|
||||
Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("Modify headers", func() {
|
||||
vhostHTTPPort := f.AllocPort()
|
||||
serverConf := getDefaultServerConf(vhostHTTPPort)
|
||||
|
||||
localPort := f.AllocPort()
|
||||
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")))
|
||||
})),
|
||||
)
|
||||
f.RunServer("", localServer)
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[test]
|
||||
type = http
|
||||
local_port = %d
|
||||
custom_domains = normal.example.com
|
||||
header_X-From-Where = frp
|
||||
`, localPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
// not set auth header
|
||||
framework.NewRequestExpect(f).Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("normal.example.com")
|
||||
}).
|
||||
ExpectResp([]byte("frp")). // local http server will write this X-From-Where header to response body
|
||||
Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("Host Header Rewrite", func() {
|
||||
vhostHTTPPort := f.AllocPort()
|
||||
serverConf := getDefaultServerConf(vhostHTTPPort)
|
||||
|
||||
localPort := f.AllocPort()
|
||||
localServer := httpserver.New(
|
||||
httpserver.WithBindPort(localPort),
|
||||
httpserver.WithHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
_, _ = w.Write([]byte(req.Host))
|
||||
})),
|
||||
)
|
||||
f.RunServer("", localServer)
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[test]
|
||||
type = http
|
||||
local_port = %d
|
||||
custom_domains = normal.example.com
|
||||
host_header_rewrite = rewrite.example.com
|
||||
`, localPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).Port(vhostHTTPPort).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("normal.example.com")
|
||||
}).
|
||||
ExpectResp([]byte("rewrite.example.com")). // local http server will write host header to response body
|
||||
Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("Websocket protocol", func() {
|
||||
vhostHTTPPort := f.AllocPort()
|
||||
serverConf := getDefaultServerConf(vhostHTTPPort)
|
||||
|
||||
upgrader := websocket.Upgrader{}
|
||||
|
||||
localPort := f.AllocPort()
|
||||
localServer := httpserver.New(
|
||||
httpserver.WithBindPort(localPort),
|
||||
httpserver.WithHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
c, err := upgrader.Upgrade(w, req, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer c.Close()
|
||||
for {
|
||||
mt, message, err := c.ReadMessage()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
err = c.WriteMessage(mt, message)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
})),
|
||||
)
|
||||
|
||||
f.RunServer("", localServer)
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[test]
|
||||
type = http
|
||||
local_port = %d
|
||||
custom_domains = 127.0.0.1
|
||||
`, localPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
u := url.URL{Scheme: "ws", Host: "127.0.0.1:" + strconv.Itoa(vhostHTTPPort)}
|
||||
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
err = c.WriteMessage(websocket.TextMessage, []byte(consts.TestString))
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
_, msg, err := c.ReadMessage()
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqualValues(consts.TestString, string(msg))
|
||||
})
|
||||
})
|
||||
179
test/e2e/legacy/basic/server.go
Normal file
179
test/e2e/legacy/basic/server.go
Normal file
@@ -0,0 +1,179 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
var _ = ginkgo.Describe("[Feature: Server Manager]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
ginkgo.It("Ports Whitelist", func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
|
||||
serverConf += `
|
||||
allow_ports = 20000-25000,25002,30000-50000
|
||||
`
|
||||
|
||||
tcpPortName := port.GenName("TCP", port.WithRangePorts(20000, 25000))
|
||||
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 = 25001
|
||||
`, 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 = 25003
|
||||
`, framework.UDPEchoServerPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
// TCP
|
||||
// Allowed in range
|
||||
framework.NewRequestExpect(f).PortName(tcpPortName).Ensure()
|
||||
|
||||
// Not Allowed
|
||||
framework.NewRequestExpect(f).Port(25001).ExpectError(true).Ensure()
|
||||
|
||||
// Unavailable, already bind by frps
|
||||
framework.NewRequestExpect(f).PortName(consts.PortServerName).ExpectError(true).Ensure()
|
||||
|
||||
// UDP
|
||||
// Allowed in range
|
||||
framework.NewRequestExpect(f).Protocol("udp").PortName(udpPortName).Ensure()
|
||||
|
||||
// Not Allowed
|
||||
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
|
||||
r.UDP().Port(25003)
|
||||
}).ExpectError(true).Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("Alloc Random Port", func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
|
||||
adminPort := f.AllocPort()
|
||||
clientConf += fmt.Sprintf(`
|
||||
admin_port = %d
|
||||
|
||||
[tcp]
|
||||
type = tcp
|
||||
local_port = {{ .%s }}
|
||||
|
||||
[udp]
|
||||
type = udp
|
||||
local_port = {{ .%s }}
|
||||
`, adminPort, framework.TCPEchoServerPort, framework.UDPEchoServerPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
client := clientsdk.New("127.0.0.1", adminPort)
|
||||
|
||||
// tcp random port
|
||||
status, err := client.GetProxyStatus("tcp")
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
_, portStr, err := net.SplitHostPort(status.RemoteAddr)
|
||||
framework.ExpectNoError(err)
|
||||
port, err := strconv.Atoi(portStr)
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
framework.NewRequestExpect(f).Port(port).Ensure()
|
||||
|
||||
// udp random port
|
||||
status, err = client.GetProxyStatus("udp")
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
_, portStr, err = net.SplitHostPort(status.RemoteAddr)
|
||||
framework.ExpectNoError(err)
|
||||
port, err = strconv.Atoi(portStr)
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
framework.NewRequestExpect(f).Protocol("udp").Port(port).Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("Port Reuse", func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
// Use same port as PortServer
|
||||
serverConf += fmt.Sprintf(`
|
||||
vhost_http_port = {{ .%s }}
|
||||
`, consts.PortServerName)
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig + fmt.Sprintf(`
|
||||
[http]
|
||||
type = http
|
||||
local_port = {{ .%s }}
|
||||
custom_domains = example.com
|
||||
`, framework.HTTPSimpleServerPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPHost("example.com")
|
||||
}).PortName(consts.PortServerName).Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("healthz", func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
dashboardPort := f.AllocPort()
|
||||
|
||||
// Use same port as PortServer
|
||||
serverConf += fmt.Sprintf(`
|
||||
vhost_http_port = {{ .%s }}
|
||||
dashboard_addr = 0.0.0.0
|
||||
dashboard_port = %d
|
||||
dashboard_user = admin
|
||||
dashboard_pwd = admin
|
||||
`, consts.PortServerName, dashboardPort)
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig + fmt.Sprintf(`
|
||||
[http]
|
||||
type = http
|
||||
local_port = {{ .%s }}
|
||||
custom_domains = example.com
|
||||
`, framework.HTTPSimpleServerPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPPath("/healthz")
|
||||
}).Port(dashboardPort).ExpectResp([]byte("")).Ensure()
|
||||
|
||||
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
|
||||
r.HTTP().HTTPPath("/")
|
||||
}).Port(dashboardPort).
|
||||
Ensure(framework.ExpectResponseCode(401))
|
||||
})
|
||||
})
|
||||
218
test/e2e/legacy/basic/tcpmux.go
Normal file
218
test/e2e/legacy/basic/tcpmux.go
Normal file
@@ -0,0 +1,218 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
|
||||
"github.com/fatedier/frp/pkg/util/util"
|
||||
"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/fatedier/frp/test/e2e/pkg/rpc"
|
||||
)
|
||||
|
||||
var _ = ginkgo.Describe("[Feature: TCPMUX httpconnect]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
getDefaultServerConf := func(httpconnectPort int) string {
|
||||
conf := consts.LegacyDefaultServerConfig + `
|
||||
tcpmux_httpconnect_port = %d
|
||||
`
|
||||
return fmt.Sprintf(conf, httpconnectPort)
|
||||
}
|
||||
newServer := func(port int, respContent string) *streamserver.Server {
|
||||
return streamserver.New(
|
||||
streamserver.TCP,
|
||||
streamserver.WithBindPort(port),
|
||||
streamserver.WithRespContent([]byte(respContent)),
|
||||
)
|
||||
}
|
||||
|
||||
proxyURLWithAuth := func(username, password string, port int) string {
|
||||
if username == "" {
|
||||
return fmt.Sprintf("http://127.0.0.1:%d", port)
|
||||
}
|
||||
return fmt.Sprintf("http://%s:%s@127.0.0.1:%d", username, password, port)
|
||||
}
|
||||
|
||||
ginkgo.It("Route by HTTP user", func() {
|
||||
vhostPort := f.AllocPort()
|
||||
serverConf := getDefaultServerConf(vhostPort)
|
||||
|
||||
fooPort := f.AllocPort()
|
||||
f.RunServer("", newServer(fooPort, "foo"))
|
||||
|
||||
barPort := f.AllocPort()
|
||||
f.RunServer("", newServer(barPort, "bar"))
|
||||
|
||||
otherPort := f.AllocPort()
|
||||
f.RunServer("", newServer(otherPort, "other"))
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[foo]
|
||||
type = tcpmux
|
||||
multiplexer = httpconnect
|
||||
local_port = %d
|
||||
custom_domains = normal.example.com
|
||||
route_by_http_user = user1
|
||||
|
||||
[bar]
|
||||
type = tcpmux
|
||||
multiplexer = httpconnect
|
||||
local_port = %d
|
||||
custom_domains = normal.example.com
|
||||
route_by_http_user = user2
|
||||
|
||||
[catchAll]
|
||||
type = tcpmux
|
||||
multiplexer = httpconnect
|
||||
local_port = %d
|
||||
custom_domains = normal.example.com
|
||||
`, fooPort, barPort, otherPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
// user1
|
||||
framework.NewRequestExpect(f).Explain("user1").
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.Addr("normal.example.com").Proxy(proxyURLWithAuth("user1", "", vhostPort))
|
||||
}).
|
||||
ExpectResp([]byte("foo")).
|
||||
Ensure()
|
||||
|
||||
// user2
|
||||
framework.NewRequestExpect(f).Explain("user2").
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.Addr("normal.example.com").Proxy(proxyURLWithAuth("user2", "", vhostPort))
|
||||
}).
|
||||
ExpectResp([]byte("bar")).
|
||||
Ensure()
|
||||
|
||||
// other user
|
||||
framework.NewRequestExpect(f).Explain("other user").
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.Addr("normal.example.com").Proxy(proxyURLWithAuth("user3", "", vhostPort))
|
||||
}).
|
||||
ExpectResp([]byte("other")).
|
||||
Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("Proxy auth", func() {
|
||||
vhostPort := f.AllocPort()
|
||||
serverConf := getDefaultServerConf(vhostPort)
|
||||
|
||||
fooPort := f.AllocPort()
|
||||
f.RunServer("", newServer(fooPort, "foo"))
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[test]
|
||||
type = tcpmux
|
||||
multiplexer = httpconnect
|
||||
local_port = %d
|
||||
custom_domains = normal.example.com
|
||||
http_user = test
|
||||
http_pwd = test
|
||||
`, fooPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
// not set auth header
|
||||
framework.NewRequestExpect(f).Explain("no auth").
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.Addr("normal.example.com").Proxy(proxyURLWithAuth("", "", vhostPort))
|
||||
}).
|
||||
ExpectError(true).
|
||||
Ensure()
|
||||
|
||||
// set incorrect auth header
|
||||
framework.NewRequestExpect(f).Explain("incorrect auth").
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.Addr("normal.example.com").Proxy(proxyURLWithAuth("test", "invalid", vhostPort))
|
||||
}).
|
||||
ExpectError(true).
|
||||
Ensure()
|
||||
|
||||
// set correct auth header
|
||||
framework.NewRequestExpect(f).Explain("correct auth").
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.Addr("normal.example.com").Proxy(proxyURLWithAuth("test", "test", vhostPort))
|
||||
}).
|
||||
ExpectResp([]byte("foo")).
|
||||
Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("TCPMux Passthrough", func() {
|
||||
vhostPort := f.AllocPort()
|
||||
serverConf := getDefaultServerConf(vhostPort)
|
||||
serverConf += `
|
||||
tcpmux_passthrough = true
|
||||
`
|
||||
|
||||
var (
|
||||
respErr error
|
||||
connectRequestHost string
|
||||
)
|
||||
newServer := func(port int) *streamserver.Server {
|
||||
return streamserver.New(
|
||||
streamserver.TCP,
|
||||
streamserver.WithBindPort(port),
|
||||
streamserver.WithCustomHandler(func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
|
||||
// read HTTP CONNECT request
|
||||
bufioReader := bufio.NewReader(conn)
|
||||
req, err := http.ReadRequest(bufioReader)
|
||||
if err != nil {
|
||||
respErr = err
|
||||
return
|
||||
}
|
||||
connectRequestHost = req.Host
|
||||
|
||||
// return ok response
|
||||
res := util.OkResponse()
|
||||
if res.Body != nil {
|
||||
defer res.Body.Close()
|
||||
}
|
||||
_ = res.Write(conn)
|
||||
|
||||
buf, err := rpc.ReadBytes(conn)
|
||||
if err != nil {
|
||||
respErr = err
|
||||
return
|
||||
}
|
||||
_, _ = rpc.WriteBytes(conn, buf)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
localPort := f.AllocPort()
|
||||
f.RunServer("", newServer(localPort))
|
||||
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[test]
|
||||
type = tcpmux
|
||||
multiplexer = httpconnect
|
||||
local_port = %d
|
||||
custom_domains = normal.example.com
|
||||
`, localPort)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
framework.NewRequestExpect(f).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.Addr("normal.example.com").Proxy(proxyURLWithAuth("", "", vhostPort)).Body([]byte("frp"))
|
||||
}).
|
||||
ExpectResp([]byte("frp")).
|
||||
Ensure()
|
||||
framework.ExpectNoError(respErr)
|
||||
framework.ExpectEqualValues(connectRequestHost, "normal.example.com")
|
||||
})
|
||||
})
|
||||
52
test/e2e/legacy/basic/xtcp.go
Normal file
52
test/e2e/legacy/basic/xtcp.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
var _ = ginkgo.Describe("[Feature: XTCP]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
ginkgo.It("Fallback To STCP", func() {
|
||||
serverConf := consts.LegacyDefaultServerConfig
|
||||
clientConf := consts.LegacyDefaultClientConfig
|
||||
|
||||
bindPortName := port.GenName("XTCP")
|
||||
clientConf += fmt.Sprintf(`
|
||||
[foo]
|
||||
type = stcp
|
||||
local_port = {{ .%s }}
|
||||
|
||||
[foo-visitor]
|
||||
type = stcp
|
||||
role = visitor
|
||||
server_name = foo
|
||||
bind_port = -1
|
||||
|
||||
[bar-visitor]
|
||||
type = xtcp
|
||||
role = visitor
|
||||
server_name = bar
|
||||
bind_port = {{ .%s }}
|
||||
keep_tunnel_open = true
|
||||
fallback_to = foo-visitor
|
||||
fallback_timeout_ms = 200
|
||||
`, framework.TCPEchoServerPort, bindPortName)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
framework.NewRequestExpect(f).
|
||||
RequestModify(func(r *request.Request) {
|
||||
r.Timeout(time.Second)
|
||||
}).
|
||||
PortName(bindPortName).
|
||||
Ensure()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user