2021-03-31 16:57:39 +08:00
|
|
|
package basic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-06-18 16:48:36 +08:00
|
|
|
"net"
|
|
|
|
"strconv"
|
2021-03-31 16:57:39 +08:00
|
|
|
|
2023-02-27 14:44:16 +08:00
|
|
|
"github.com/onsi/ginkgo/v2"
|
2022-08-29 01:02:53 +08:00
|
|
|
|
2021-03-31 16:57:39 +08:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
var _ = ginkgo.Describe("[Feature: Server Manager]", func() {
|
2021-03-31 16:57:39 +08:00
|
|
|
f := framework.NewDefaultFramework()
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("Ports Whitelist", func() {
|
2021-03-31 16:57:39 +08:00
|
|
|
serverConf := consts.DefaultServerConfig
|
|
|
|
clientConf := consts.DefaultClientConfig
|
|
|
|
|
|
|
|
serverConf += `
|
2023-09-13 16:32:39 +08:00
|
|
|
allowPorts = [
|
2023-12-21 22:46:08 +08:00
|
|
|
{ start = 10000, end = 11000 },
|
|
|
|
{ single = 11002 },
|
|
|
|
{ start = 12000, end = 13000 },
|
2023-09-13 16:32:39 +08:00
|
|
|
]
|
2021-03-31 16:57:39 +08:00
|
|
|
`
|
|
|
|
|
2023-12-21 22:46:08 +08:00
|
|
|
tcpPortName := port.GenName("TCP", port.WithRangePorts(10000, 11000))
|
|
|
|
udpPortName := port.GenName("UDP", port.WithRangePorts(12000, 13000))
|
2021-03-31 16:57:39 +08:00
|
|
|
clientConf += fmt.Sprintf(`
|
2023-09-13 16:32:39 +08:00
|
|
|
[[proxies]]
|
|
|
|
name = "tcp-allowded-in-range"
|
|
|
|
type = "tcp"
|
|
|
|
localPort = {{ .%s }}
|
|
|
|
remotePort = {{ .%s }}
|
2021-03-31 16:57:39 +08:00
|
|
|
`, framework.TCPEchoServerPort, tcpPortName)
|
|
|
|
clientConf += fmt.Sprintf(`
|
2023-09-13 16:32:39 +08:00
|
|
|
[[proxies]]
|
|
|
|
name = "tcp-port-not-allowed"
|
|
|
|
type = "tcp"
|
|
|
|
localPort = {{ .%s }}
|
2023-12-21 22:46:08 +08:00
|
|
|
remotePort = 11001
|
2021-03-31 16:57:39 +08:00
|
|
|
`, framework.TCPEchoServerPort)
|
|
|
|
clientConf += fmt.Sprintf(`
|
2023-09-13 16:32:39 +08:00
|
|
|
[[proxies]]
|
|
|
|
name = "tcp-port-unavailable"
|
|
|
|
type = "tcp"
|
|
|
|
localPort = {{ .%s }}
|
|
|
|
remotePort = {{ .%s }}
|
2021-03-31 16:57:39 +08:00
|
|
|
`, framework.TCPEchoServerPort, consts.PortServerName)
|
|
|
|
clientConf += fmt.Sprintf(`
|
2023-09-13 16:32:39 +08:00
|
|
|
[[proxies]]
|
|
|
|
name = "udp-allowed-in-range"
|
|
|
|
type = "udp"
|
|
|
|
localPort = {{ .%s }}
|
|
|
|
remotePort = {{ .%s }}
|
2021-03-31 16:57:39 +08:00
|
|
|
`, framework.UDPEchoServerPort, udpPortName)
|
|
|
|
clientConf += fmt.Sprintf(`
|
2023-09-13 16:32:39 +08:00
|
|
|
[[proxies]]
|
|
|
|
name = "udp-port-not-allowed"
|
|
|
|
type = "udp"
|
|
|
|
localPort = {{ .%s }}
|
2023-12-21 22:46:08 +08:00
|
|
|
remotePort = 11003
|
2021-03-31 16:57:39 +08:00
|
|
|
`, framework.UDPEchoServerPort)
|
|
|
|
|
|
|
|
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
|
|
|
|
|
|
|
// TCP
|
|
|
|
// Allowed in range
|
|
|
|
framework.NewRequestExpect(f).PortName(tcpPortName).Ensure()
|
|
|
|
|
|
|
|
// Not Allowed
|
2023-12-21 22:46:08 +08:00
|
|
|
framework.NewRequestExpect(f).Port(11001).ExpectError(true).Ensure()
|
2021-03-31 16:57:39 +08:00
|
|
|
|
|
|
|
// Unavailable, already bind by frps
|
|
|
|
framework.NewRequestExpect(f).PortName(consts.PortServerName).ExpectError(true).Ensure()
|
|
|
|
|
|
|
|
// UDP
|
|
|
|
// Allowed in range
|
2021-06-18 16:48:36 +08:00
|
|
|
framework.NewRequestExpect(f).Protocol("udp").PortName(udpPortName).Ensure()
|
2021-03-31 16:57:39 +08:00
|
|
|
|
|
|
|
// Not Allowed
|
2021-06-02 23:54:22 +08:00
|
|
|
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
|
2023-12-21 22:46:08 +08:00
|
|
|
r.UDP().Port(11003)
|
2021-03-31 16:57:39 +08:00
|
|
|
}).ExpectError(true).Ensure()
|
|
|
|
})
|
2021-06-18 16:48:36 +08:00
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("Alloc Random Port", func() {
|
2021-06-18 16:48:36 +08:00
|
|
|
serverConf := consts.DefaultServerConfig
|
|
|
|
clientConf := consts.DefaultClientConfig
|
|
|
|
|
|
|
|
adminPort := f.AllocPort()
|
|
|
|
clientConf += fmt.Sprintf(`
|
2023-09-13 16:32:39 +08:00
|
|
|
webServer.port = %d
|
2021-06-18 16:48:36 +08:00
|
|
|
|
2023-09-13 16:32:39 +08:00
|
|
|
[[proxies]]
|
|
|
|
name = "tcp"
|
|
|
|
type = "tcp"
|
|
|
|
localPort = {{ .%s }}
|
2021-06-18 16:48:36 +08:00
|
|
|
|
2023-09-13 16:32:39 +08:00
|
|
|
[[proxies]]
|
|
|
|
name = "udp"
|
|
|
|
type = "udp"
|
|
|
|
localPort = {{ .%s }}
|
2021-08-02 13:07:28 +08:00
|
|
|
`, adminPort, framework.TCPEchoServerPort, framework.UDPEchoServerPort)
|
2021-06-18 16:48:36 +08:00
|
|
|
|
|
|
|
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
|
|
|
|
2024-03-15 17:23:16 +08:00
|
|
|
client := f.APIClientForFrpc(adminPort)
|
2021-06-18 16:48:36 +08:00
|
|
|
|
|
|
|
// 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()
|
|
|
|
})
|
2021-08-02 13:07:28 +08:00
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("Port Reuse", func() {
|
2021-08-02 13:07:28 +08:00
|
|
|
serverConf := consts.DefaultServerConfig
|
|
|
|
// Use same port as PortServer
|
|
|
|
serverConf += fmt.Sprintf(`
|
2023-09-13 16:32:39 +08:00
|
|
|
vhostHTTPPort = {{ .%s }}
|
2021-08-02 13:07:28 +08:00
|
|
|
`, consts.PortServerName)
|
|
|
|
|
|
|
|
clientConf := consts.DefaultClientConfig + fmt.Sprintf(`
|
2023-09-13 16:32:39 +08:00
|
|
|
[[proxies]]
|
|
|
|
name = "http"
|
|
|
|
type = "http"
|
|
|
|
localPort = {{ .%s }}
|
|
|
|
customDomains = ["example.com"]
|
2021-08-02 13:07:28 +08:00
|
|
|
`, 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()
|
|
|
|
})
|
2021-11-23 14:14:27 +08:00
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("healthz", func() {
|
2021-11-23 14:14:27 +08:00
|
|
|
serverConf := consts.DefaultServerConfig
|
|
|
|
dashboardPort := f.AllocPort()
|
|
|
|
|
|
|
|
// Use same port as PortServer
|
|
|
|
serverConf += fmt.Sprintf(`
|
2023-09-13 16:32:39 +08:00
|
|
|
vhostHTTPPort = {{ .%s }}
|
|
|
|
webServer.addr = "0.0.0.0"
|
|
|
|
webServer.port = %d
|
|
|
|
webServer.user = "admin"
|
|
|
|
webServer.password = "admin"
|
2021-11-23 14:14:27 +08:00
|
|
|
`, consts.PortServerName, dashboardPort)
|
|
|
|
|
|
|
|
clientConf := consts.DefaultClientConfig + fmt.Sprintf(`
|
2023-09-13 16:32:39 +08:00
|
|
|
[[proxies]]
|
|
|
|
name = "http"
|
|
|
|
type = "http"
|
|
|
|
localPort = {{ .%s }}
|
|
|
|
customDomains = ["example.com"]
|
2021-11-23 14:14:27 +08:00
|
|
|
`, 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))
|
|
|
|
})
|
2021-03-31 16:57:39 +08:00
|
|
|
})
|