mirror of
https://github.com/fatedier/frp.git
synced 2025-07-27 07:35:07 +00:00
add e2e tests for v1 config (#3608)
This commit is contained in:
524
test/e2e/v1/basic/basic.go
Normal file
524
test/e2e/v1/basic/basic.go
Normal file
@@ -0,0 +1,524 @@
|
||||
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.DefaultServerConfig
|
||||
clientConf := consts.DefaultClientConfig
|
||||
|
||||
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(`
|
||||
[[proxies]]
|
||||
name = "%s"
|
||||
type = "%s"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = {{ .%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: "transport.useEncryption = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-compression",
|
||||
portName: port.GenName("WithCompression"),
|
||||
extraConfig: "transport.useCompression = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption-and-compression",
|
||||
portName: port.GenName("WithEncryptionAndCompression"),
|
||||
extraConfig: `
|
||||
transport.useEncryption = true
|
||||
transport.useCompression = 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.DefaultServerConfig
|
||||
vhostHTTPPort := f.AllocPort()
|
||||
serverConf += fmt.Sprintf(`
|
||||
vhostHTTPPort = %d
|
||||
`, vhostHTTPPort)
|
||||
|
||||
clientConf := consts.DefaultClientConfig
|
||||
|
||||
getProxyConf := func(proxyName string, customDomains string, extra string) string {
|
||||
return fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "%s"
|
||||
type = "http"
|
||||
localPort = {{ .%s }}
|
||||
customDomains = %s
|
||||
`+extra, proxyName, framework.HTTPSimpleServerPort, customDomains)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
proxyName string
|
||||
customDomains string
|
||||
extraConfig string
|
||||
}{
|
||||
{
|
||||
proxyName: "normal",
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption",
|
||||
extraConfig: "transport.useEncryption = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-compression",
|
||||
extraConfig: "transport.useCompression = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption-and-compression",
|
||||
extraConfig: `
|
||||
transport.useEncryption = true
|
||||
transport.useCompression = 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 = fmt.Sprintf(`["%s"]`, 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)
|
||||
domain = strings.TrimLeft(domain, "[\"")
|
||||
domain = strings.TrimRight(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.DefaultServerConfig
|
||||
vhostHTTPSPort := f.AllocPort()
|
||||
serverConf += fmt.Sprintf(`
|
||||
vhostHTTPSPort = %d
|
||||
`, vhostHTTPSPort)
|
||||
|
||||
localPort := f.AllocPort()
|
||||
clientConf := consts.DefaultClientConfig
|
||||
getProxyConf := func(proxyName string, customDomains string, extra string) string {
|
||||
return fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "%s"
|
||||
type = "https"
|
||||
localPort = %d
|
||||
customDomains = %s
|
||||
`+extra, proxyName, localPort, customDomains)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
proxyName string
|
||||
customDomains string
|
||||
extraConfig string
|
||||
}{
|
||||
{
|
||||
proxyName: "normal",
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption",
|
||||
extraConfig: "transport.useEncryption = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-compression",
|
||||
extraConfig: "transport.useCompression = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption-and-compression",
|
||||
extraConfig: `
|
||||
transport.useEncryption = true
|
||||
transport.useCompression = 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 = fmt.Sprintf(`["%s"]`, 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)
|
||||
domain = strings.TrimLeft(domain, "[\"")
|
||||
domain = strings.TrimRight(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.DefaultServerConfig
|
||||
clientServerConf := consts.DefaultClientConfig + "\nuser = \"user1\""
|
||||
clientVisitorConf := consts.DefaultClientConfig + "\nuser = \"user1\""
|
||||
clientUser2VisitorConf := consts.DefaultClientConfig + "\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(`
|
||||
[[proxies]]
|
||||
name = "%s"
|
||||
type = "%s"
|
||||
secretKey = "%s"
|
||||
localPort = {{ .%s }}
|
||||
`+extra, proxyName, proxyType, correctSK, localPortName)
|
||||
}
|
||||
getProxyVisitorConf := func(proxyName string, portName, visitorSK, extra string) string {
|
||||
return fmt.Sprintf(`
|
||||
[[visitors]]
|
||||
name = "%s"
|
||||
type = "%s"
|
||||
serverName = "%s"
|
||||
secretKey = "%s"
|
||||
bindPort = {{ .%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: "transport.useEncryption = true",
|
||||
skipXTCP: true,
|
||||
},
|
||||
{
|
||||
proxyName: "with-compression",
|
||||
bindPortName: port.GenName("WithCompression"),
|
||||
visitorSK: correctSK,
|
||||
commonExtraConfig: "transport.useCompression = true",
|
||||
skipXTCP: true,
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption-and-compression",
|
||||
bindPortName: port.GenName("WithEncryptionAndCompression"),
|
||||
visitorSK: correctSK,
|
||||
commonExtraConfig: `
|
||||
transport.useEncryption = true
|
||||
transport.useCompression = 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: `allowUsers = ["another", "user2"]`,
|
||||
visitorExtraConfig: `serverUser = "user1"`,
|
||||
deployUser2Client: true,
|
||||
},
|
||||
{
|
||||
proxyName: "not-allowed-user",
|
||||
bindPortName: port.GenName("NotAllowedUser"),
|
||||
visitorSK: correctSK,
|
||||
proxyExtraConfig: `allowUsers = ["invalid"]`,
|
||||
visitorExtraConfig: `serverUser = "user1"`,
|
||||
expectError: true,
|
||||
},
|
||||
{
|
||||
proxyName: "allow-all",
|
||||
bindPortName: port.GenName("AllowAll"),
|
||||
visitorSK: correctSK,
|
||||
proxyExtraConfig: `allowUsers = ["*"]`,
|
||||
visitorExtraConfig: `serverUser = "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.DefaultServerConfig
|
||||
clientConf := consts.DefaultClientConfig
|
||||
|
||||
tcpmuxHTTPConnectPortName := port.GenName("TCPMUX")
|
||||
serverConf += fmt.Sprintf(`
|
||||
tcpmuxHTTPConnectPort = {{ .%s }}
|
||||
`, tcpmuxHTTPConnectPortName)
|
||||
|
||||
getProxyConf := func(proxyName string, extra string) string {
|
||||
return fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "%s"
|
||||
type = "tcpmux"
|
||||
multiplexer = "httpconnect"
|
||||
localPort = {{ .%s }}
|
||||
customDomains = ["%s"]
|
||||
`+extra, proxyName, port.GenName(proxyName), proxyName)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
proxyName string
|
||||
extraConfig string
|
||||
}{
|
||||
{
|
||||
proxyName: "normal",
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption",
|
||||
extraConfig: "transport.useEncryption = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-compression",
|
||||
extraConfig: "transport.useCompression = true",
|
||||
},
|
||||
{
|
||||
proxyName: "with-encryption-and-compression",
|
||||
extraConfig: `
|
||||
transport.useEncryption = true
|
||||
transport.useCompression = 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()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
136
test/e2e/v1/basic/client.go
Normal file
136
test/e2e/v1/basic/client.go
Normal file
@@ -0,0 +1,136 @@
|
||||
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.DefaultServerConfig
|
||||
|
||||
adminPort := f.AllocPort()
|
||||
|
||||
p1Port := f.AllocPort()
|
||||
p2Port := f.AllocPort()
|
||||
p3Port := f.AllocPort()
|
||||
|
||||
clientConf := consts.DefaultClientConfig + fmt.Sprintf(`
|
||||
webServer.port = %d
|
||||
|
||||
[[proxies]]
|
||||
name = "p1"
|
||||
type = "tcp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = %d
|
||||
|
||||
[[proxies]]
|
||||
name = "p2"
|
||||
type = "tcp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = %d
|
||||
|
||||
[[proxies]]
|
||||
name = "p3"
|
||||
type = "tcp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = %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.LastIndex(newClientConf, "[[proxies]]")
|
||||
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.DefaultServerConfig
|
||||
|
||||
dashboardPort := f.AllocPort()
|
||||
clientConf := consts.DefaultClientConfig + fmt.Sprintf(`
|
||||
webServer.addr = "0.0.0.0"
|
||||
webServer.port = %d
|
||||
webServer.user = "admin"
|
||||
webServer.password = "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.DefaultServerConfig
|
||||
|
||||
adminPort := f.AllocPort()
|
||||
testPort := f.AllocPort()
|
||||
clientConf := consts.DefaultClientConfig + fmt.Sprintf(`
|
||||
webServer.port = %d
|
||||
|
||||
[[proxies]]
|
||||
name = "test"
|
||||
type = "tcp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = %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()
|
||||
})
|
||||
})
|
325
test/e2e/v1/basic/client_server.go
Normal file
325
test/e2e/v1/basic/client_server.go
Normal file
@@ -0,0 +1,325 @@
|
||||
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(`kcpBindPort = {{ .%s }}`, consts.PortServerName)
|
||||
} else if protocol == "quic" {
|
||||
return fmt.Sprintf(`quicBindPort = {{ .%s }}`, consts.PortServerName)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func runClientServerTest(f *framework.Framework, configures *generalTestConfigures) {
|
||||
serverConf := consts.DefaultServerConfig
|
||||
clientConf := consts.DefaultClientConfig
|
||||
if configures.clientPrefix != "" {
|
||||
clientConf = configures.clientPrefix
|
||||
}
|
||||
|
||||
serverConf += fmt.Sprintf(`
|
||||
%s
|
||||
`, configures.server)
|
||||
|
||||
tcpPortName := port.GenName("TCP")
|
||||
udpPortName := port.GenName("UDP")
|
||||
clientConf += fmt.Sprintf(`
|
||||
%s
|
||||
|
||||
[[proxies]]
|
||||
name = "tcp"
|
||||
type = "tcp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = {{ .%s }}
|
||||
|
||||
[[proxies]]
|
||||
name = "udp"
|
||||
type = "udp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = {{ .%s }}
|
||||
`, configures.client,
|
||||
framework.TCPEchoServerPort, tcpPortName,
|
||||
framework.UDPEchoServerPort, udpPortName,
|
||||
)
|
||||
|
||||
clientConfs := []string{clientConf}
|
||||
if configures.client2 != "" {
|
||||
client2Conf := consts.DefaultClientConfig
|
||||
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: fmt.Sprintf(`transport.protocol = "%s"`, 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(`
|
||||
serverAddr = "127.0.0.1"
|
||||
serverPort = %d
|
||||
loginFailExit = false
|
||||
transport.protocol = "wss"
|
||||
log.level = "trace"
|
||||
`, 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(`
|
||||
[[proxies]]
|
||||
name = "wss2ws"
|
||||
type = "tcp"
|
||||
remotePort = %d
|
||||
[proxies.plugin]
|
||||
type = "https2http"
|
||||
localAddr = "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: `auth.token = "123456"`,
|
||||
client: `auth.token = "123456"`,
|
||||
})
|
||||
|
||||
defineClientServerTest("Token Incorrect", f, &generalTestConfigures{
|
||||
server: `auth.token = "123456"`,
|
||||
client: `auth.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(`transport.tls.enable = false
|
||||
transport.protocol = "%s"
|
||||
`, protocol),
|
||||
})
|
||||
}
|
||||
|
||||
defineClientServerTest("enable tls force, client with TLS", f, &generalTestConfigures{
|
||||
server: "transport.tls.force = true",
|
||||
})
|
||||
defineClientServerTest("enable tls force, client without TLS", f, &generalTestConfigures{
|
||||
server: "transport.tls.force = true",
|
||||
client: "transport.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
|
||||
transport.tls.trustedCaFile = "%s"
|
||||
`, renderBindPortConfig(tmp), caCrtPath),
|
||||
client: fmt.Sprintf(`
|
||||
transport.protocol = "%s"
|
||||
transport.tls.certFile = "%s"
|
||||
transport.tls.keyFile = "%s"
|
||||
`, tmp, clientCrtPath, clientKeyPath),
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.It("mutual authentication: "+tmp, func() {
|
||||
runClientServerTest(f, &generalTestConfigures{
|
||||
server: fmt.Sprintf(`
|
||||
%s
|
||||
transport.tls.certFile = "%s"
|
||||
transport.tls.keyFile = "%s"
|
||||
transport.tls.trustedCaFile = "%s"
|
||||
`, renderBindPortConfig(tmp), serverCrtPath, serverKeyPath, caCrtPath),
|
||||
client: fmt.Sprintf(`
|
||||
transport.protocol = "%s"
|
||||
transport.tls.certFile = "%s"
|
||||
transport.tls.keyFile = "%s"
|
||||
transport.tls.trustedCaFile = "%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(`
|
||||
transport.tls.certFile = "%s"
|
||||
transport.tls.keyFile = "%s"
|
||||
transport.tls.trustedCaFile = "%s"
|
||||
`, serverCrtPath, serverKeyPath, caCrtPath),
|
||||
client: fmt.Sprintf(`
|
||||
transport.tls.serverName = "example.com"
|
||||
transport.tls.certFile = "%s"
|
||||
transport.tls.keyFile = "%s"
|
||||
transport.tls.trustedCaFile = "%s"
|
||||
`, clientCrtPath, clientKeyPath, caCrtPath),
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.It("mutual authentication with incorrect server name", func() {
|
||||
runClientServerTest(f, &generalTestConfigures{
|
||||
server: fmt.Sprintf(`
|
||||
transport.tls.certFile = "%s"
|
||||
transport.tls.keyFile = "%s"
|
||||
transport.tls.trustedCaFile = "%s"
|
||||
`, serverCrtPath, serverKeyPath, caCrtPath),
|
||||
client: fmt.Sprintf(`
|
||||
transport.tls.serverName = "invalid.com"
|
||||
transport.tls.certFile = "%s"
|
||||
transport.tls.keyFile = "%s"
|
||||
transport.tls.trustedCaFile = "%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(`
|
||||
transport.protocol = "%s"
|
||||
transport.tls.disableCustomTLSFirstByte = 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(`
|
||||
bindAddr = "::"
|
||||
%s
|
||||
`, renderBindPortConfig(protocol)),
|
||||
client: fmt.Sprintf(`
|
||||
transport.protocol = "%s"
|
||||
`, protocol),
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
109
test/e2e/v1/basic/cmd.go
Normal file
109
test/e2e/v1/basic/cmd.go
Normal file
@@ -0,0 +1,109 @@
|
||||
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(`
|
||||
bindAddr = "0.0.0.0"
|
||||
bindPort = 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(`
|
||||
bindAddr = "0.0.0.0"
|
||||
bindPort = 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(`
|
||||
serverAddr = "0.0.0.0"
|
||||
serverPort = 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(`
|
||||
serverAddr = "0.0.0.0"
|
||||
serverPort = 7000
|
||||
transport.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()
|
||||
})
|
||||
})
|
||||
})
|
84
test/e2e/v1/basic/config.go
Normal file
84
test/e2e/v1/basic/config.go
Normal file
@@ -0,0 +1,84 @@
|
||||
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.DefaultServerConfig
|
||||
clientConf := consts.DefaultClientConfig
|
||||
|
||||
portName := port.GenName("TCP")
|
||||
serverConf += fmt.Sprintf(`
|
||||
auth.token = "{{ %s{{ .Envs.FRP_TOKEN }}%s }}"
|
||||
`, "`", "`")
|
||||
|
||||
clientConf += fmt.Sprintf(`
|
||||
auth.token = "{{ %s{{ .Envs.FRP_TOKEN }}%s }}"
|
||||
|
||||
[[proxies]]
|
||||
name = "tcp"
|
||||
type = "tcp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = {{ .%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(`
|
||||
bindAddr = "0.0.0.0"
|
||||
bindPort = %d
|
||||
`, serverPort))
|
||||
|
||||
remotePort := f.AllocPort()
|
||||
proxyConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "tcp"
|
||||
type = "tcp"
|
||||
localPort = %d
|
||||
remotePort = %d
|
||||
`, f.PortByName(framework.TCPEchoServerPort), remotePort))
|
||||
|
||||
remotePort2 := f.AllocPort()
|
||||
proxyConfigPath2 := f.GenerateConfigFile(fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "tcp2"
|
||||
type = "tcp"
|
||||
localPort = %d
|
||||
remotePort = %d
|
||||
`, f.PortByName(framework.TCPEchoServerPort), remotePort2))
|
||||
|
||||
clientConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
|
||||
serverPort = %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()
|
||||
})
|
||||
})
|
||||
})
|
388
test/e2e/v1/basic/http.go
Normal file
388
test/e2e/v1/basic/http.go
Normal file
@@ -0,0 +1,388 @@
|
||||
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.DefaultServerConfig + `
|
||||
vhostHTTPPort = %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.DefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "foo"
|
||||
type = "http"
|
||||
localPort = %d
|
||||
customDomains = ["normal.example.com"]
|
||||
locations = ["/","/foo"]
|
||||
|
||||
[[proxies]]
|
||||
name = "bar"
|
||||
type = "http"
|
||||
localPort = %d
|
||||
customDomains = ["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.DefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "foo"
|
||||
type = "http"
|
||||
localPort = %d
|
||||
customDomains = ["normal.example.com"]
|
||||
routeByHTTPUser = "user1"
|
||||
|
||||
[[proxies]]
|
||||
name = "bar"
|
||||
type = "http"
|
||||
localPort = %d
|
||||
customDomains = ["normal.example.com"]
|
||||
routeByHTTPUser = "user2"
|
||||
|
||||
[[proxies]]
|
||||
name = "catchAll"
|
||||
type = "http"
|
||||
localPort = %d
|
||||
customDomains = ["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.DefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "test"
|
||||
type = "http"
|
||||
localPort = {{ .%s }}
|
||||
customDomains = ["normal.example.com"]
|
||||
httpUser = "test"
|
||||
httpPassword = "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.DefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "test"
|
||||
type = "http"
|
||||
localPort = {{ .%s }}
|
||||
customDomains = ["*.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 += `
|
||||
subdomainHost = "example.com"
|
||||
`
|
||||
|
||||
fooPort := f.AllocPort()
|
||||
f.RunServer("", newHTTPServer(fooPort, "foo"))
|
||||
|
||||
barPort := f.AllocPort()
|
||||
f.RunServer("", newHTTPServer(barPort, "bar"))
|
||||
|
||||
clientConf := consts.DefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "foo"
|
||||
type = "http"
|
||||
localPort = %d
|
||||
subdomain = "foo"
|
||||
|
||||
[[proxies]]
|
||||
name = "bar"
|
||||
type = "http"
|
||||
localPort = %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.DefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "test"
|
||||
type = "http"
|
||||
localPort = %d
|
||||
customDomains = ["normal.example.com"]
|
||||
requestHeaders.set.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.DefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "test"
|
||||
type = "http"
|
||||
localPort = %d
|
||||
customDomains = ["normal.example.com"]
|
||||
hostHeaderRewrite = "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.DefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "test"
|
||||
type = "http"
|
||||
localPort = %d
|
||||
customDomains = ["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))
|
||||
})
|
||||
})
|
192
test/e2e/v1/basic/server.go
Normal file
192
test/e2e/v1/basic/server.go
Normal file
@@ -0,0 +1,192 @@
|
||||
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.DefaultServerConfig
|
||||
clientConf := consts.DefaultClientConfig
|
||||
|
||||
serverConf += `
|
||||
allowPorts = [
|
||||
{ start = 20000, end = 25000 },
|
||||
{ single = 25002 },
|
||||
{ start = 30000, end = 50000 },
|
||||
]
|
||||
`
|
||||
|
||||
tcpPortName := port.GenName("TCP", port.WithRangePorts(20000, 25000))
|
||||
udpPortName := port.GenName("UDP", port.WithRangePorts(30000, 50000))
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "tcp-allowded-in-range"
|
||||
type = "tcp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = {{ .%s }}
|
||||
`, framework.TCPEchoServerPort, tcpPortName)
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "tcp-port-not-allowed"
|
||||
type = "tcp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = 25001
|
||||
`, framework.TCPEchoServerPort)
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "tcp-port-unavailable"
|
||||
type = "tcp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = {{ .%s }}
|
||||
`, framework.TCPEchoServerPort, consts.PortServerName)
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "udp-allowed-in-range"
|
||||
type = "udp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = {{ .%s }}
|
||||
`, framework.UDPEchoServerPort, udpPortName)
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "udp-port-not-allowed"
|
||||
type = "udp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = 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.DefaultServerConfig
|
||||
clientConf := consts.DefaultClientConfig
|
||||
|
||||
adminPort := f.AllocPort()
|
||||
clientConf += fmt.Sprintf(`
|
||||
webServer.port = %d
|
||||
|
||||
[[proxies]]
|
||||
name = "tcp"
|
||||
type = "tcp"
|
||||
localPort = {{ .%s }}
|
||||
|
||||
[[proxies]]
|
||||
name = "udp"
|
||||
type = "udp"
|
||||
localPort = {{ .%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.DefaultServerConfig
|
||||
// Use same port as PortServer
|
||||
serverConf += fmt.Sprintf(`
|
||||
vhostHTTPPort = {{ .%s }}
|
||||
`, consts.PortServerName)
|
||||
|
||||
clientConf := consts.DefaultClientConfig + fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "http"
|
||||
type = "http"
|
||||
localPort = {{ .%s }}
|
||||
customDomains = ["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.DefaultServerConfig
|
||||
dashboardPort := f.AllocPort()
|
||||
|
||||
// Use same port as PortServer
|
||||
serverConf += fmt.Sprintf(`
|
||||
vhostHTTPPort = {{ .%s }}
|
||||
webServer.addr = "0.0.0.0"
|
||||
webServer.port = %d
|
||||
webServer.user = "admin"
|
||||
webServer.password = "admin"
|
||||
`, consts.PortServerName, dashboardPort)
|
||||
|
||||
clientConf := consts.DefaultClientConfig + fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "http"
|
||||
type = "http"
|
||||
localPort = {{ .%s }}
|
||||
customDomains = ["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))
|
||||
})
|
||||
})
|
223
test/e2e/v1/basic/tcpmux.go
Normal file
223
test/e2e/v1/basic/tcpmux.go
Normal file
@@ -0,0 +1,223 @@
|
||||
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.DefaultServerConfig + `
|
||||
tcpmuxHTTPConnectPort = %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.DefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "foo"
|
||||
type = "tcpmux"
|
||||
multiplexer = "httpconnect"
|
||||
localPort = %d
|
||||
customDomains = ["normal.example.com"]
|
||||
routeByHTTPUser = "user1"
|
||||
|
||||
[[proxies]]
|
||||
name = "bar"
|
||||
type = "tcpmux"
|
||||
multiplexer = "httpconnect"
|
||||
localPort = %d
|
||||
customDomains = ["normal.example.com"]
|
||||
routeByHTTPUser = "user2"
|
||||
|
||||
[[proxies]]
|
||||
name = "catchAll"
|
||||
type = "tcpmux"
|
||||
multiplexer = "httpconnect"
|
||||
localPort = %d
|
||||
customDomains = ["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.DefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "test"
|
||||
type = "tcpmux"
|
||||
multiplexer = "httpconnect"
|
||||
localPort = %d
|
||||
customDomains = ["normal.example.com"]
|
||||
httpUser = "test"
|
||||
httpPassword = "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 += `
|
||||
tcpmuxPassthrough = 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.DefaultClientConfig
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "test"
|
||||
type = "tcpmux"
|
||||
multiplexer = "httpconnect"
|
||||
localPort = %d
|
||||
customDomains = ["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")
|
||||
})
|
||||
})
|
53
test/e2e/v1/basic/xtcp.go
Normal file
53
test/e2e/v1/basic/xtcp.go
Normal file
@@ -0,0 +1,53 @@
|
||||
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.DefaultServerConfig
|
||||
clientConf := consts.DefaultClientConfig
|
||||
|
||||
bindPortName := port.GenName("XTCP")
|
||||
clientConf += fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "foo"
|
||||
type = "stcp"
|
||||
localPort = {{ .%s }}
|
||||
|
||||
[[visitors]]
|
||||
name = "foo-visitor"
|
||||
type = "stcp"
|
||||
serverName = "foo"
|
||||
bindPort = -1
|
||||
|
||||
[[visitors]]
|
||||
name = "bar-visitor"
|
||||
type = "xtcp"
|
||||
serverName = "bar"
|
||||
bindPort = {{ .%s }}
|
||||
keepTunnelOpen = true
|
||||
fallbackTo = "foo-visitor"
|
||||
fallbackTimeoutMs = 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