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
|
|
|
|
|
|
|
"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"
|
2021-06-18 16:48:36 +08:00
|
|
|
clientsdk "github.com/fatedier/frp/test/e2e/pkg/sdk/client"
|
2021-03-31 16:57:39 +08:00
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("[Feature: Server Manager]", func() {
|
|
|
|
f := framework.NewDefaultFramework()
|
|
|
|
|
|
|
|
It("Ports Whitelist", func() {
|
|
|
|
serverConf := consts.DefaultServerConfig
|
|
|
|
clientConf := consts.DefaultClientConfig
|
|
|
|
|
|
|
|
serverConf += `
|
2021-06-18 16:48:36 +08:00
|
|
|
allow_ports = 20000-25000,25002,30000-50000
|
2021-03-31 16:57:39 +08:00
|
|
|
`
|
|
|
|
|
2021-06-18 16:48:36 +08:00
|
|
|
tcpPortName := port.GenName("TCP", port.WithRangePorts(20000, 25000))
|
2021-03-31 16:57:39 +08:00
|
|
|
udpPortName := port.GenName("UDP", port.WithRangePorts(30000, 50000))
|
|
|
|
clientConf += fmt.Sprintf(`
|
|
|
|
[tcp-allowded-in-range]
|
|
|
|
type = tcp
|
|
|
|
local_port = {{ .%s }}
|
|
|
|
remote_port = {{ .%s }}
|
|
|
|
`, framework.TCPEchoServerPort, tcpPortName)
|
|
|
|
clientConf += fmt.Sprintf(`
|
|
|
|
[tcp-port-not-allowed]
|
|
|
|
type = tcp
|
|
|
|
local_port = {{ .%s }}
|
|
|
|
remote_port = 20001
|
|
|
|
`, framework.TCPEchoServerPort)
|
|
|
|
clientConf += fmt.Sprintf(`
|
|
|
|
[tcp-port-unavailable]
|
|
|
|
type = tcp
|
|
|
|
local_port = {{ .%s }}
|
|
|
|
remote_port = {{ .%s }}
|
|
|
|
`, framework.TCPEchoServerPort, consts.PortServerName)
|
|
|
|
clientConf += fmt.Sprintf(`
|
|
|
|
[udp-allowed-in-range]
|
|
|
|
type = udp
|
|
|
|
local_port = {{ .%s }}
|
|
|
|
remote_port = {{ .%s }}
|
|
|
|
`, framework.UDPEchoServerPort, udpPortName)
|
|
|
|
clientConf += fmt.Sprintf(`
|
|
|
|
[udp-port-not-allowed]
|
|
|
|
type = udp
|
|
|
|
local_port = {{ .%s }}
|
|
|
|
remote_port = 20003
|
|
|
|
`, framework.UDPEchoServerPort)
|
|
|
|
|
|
|
|
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
|
|
|
|
|
|
|
// TCP
|
|
|
|
// Allowed in range
|
|
|
|
framework.NewRequestExpect(f).PortName(tcpPortName).Ensure()
|
|
|
|
|
|
|
|
// Not Allowed
|
2021-06-18 16:48:36 +08:00
|
|
|
framework.NewRequestExpect(f).Port(25003).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) {
|
2021-06-18 16:48:36 +08:00
|
|
|
r.UDP().Port(25003)
|
2021-03-31 16:57:39 +08:00
|
|
|
}).ExpectError(true).Ensure()
|
|
|
|
})
|
2021-06-18 16:48:36 +08:00
|
|
|
|
|
|
|
It("Alloc Random Port", func() {
|
|
|
|
serverConf := consts.DefaultServerConfig
|
|
|
|
clientConf := consts.DefaultClientConfig
|
|
|
|
|
|
|
|
adminPort := f.AllocPort()
|
|
|
|
clientConf += fmt.Sprintf(`
|
2021-08-02 13:07:28 +08:00
|
|
|
admin_port = %d
|
2021-06-18 16:48:36 +08:00
|
|
|
|
2021-08-02 13:07:28 +08:00
|
|
|
[tcp]
|
|
|
|
type = tcp
|
|
|
|
local_port = {{ .%s }}
|
2021-06-18 16:48:36 +08:00
|
|
|
|
2021-08-02 13:07:28 +08:00
|
|
|
[udp]
|
|
|
|
type = udp
|
|
|
|
local_port = {{ .%s }}
|
|
|
|
`, adminPort, framework.TCPEchoServerPort, framework.UDPEchoServerPort)
|
2021-06-18 16:48:36 +08:00
|
|
|
|
|
|
|
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()
|
|
|
|
})
|
2021-08-02 13:07:28 +08:00
|
|
|
|
|
|
|
It("Port Reuse", func() {
|
|
|
|
serverConf := consts.DefaultServerConfig
|
|
|
|
// Use same port as PortServer
|
|
|
|
serverConf += fmt.Sprintf(`
|
|
|
|
vhost_http_port = {{ .%s }}
|
|
|
|
`, consts.PortServerName)
|
|
|
|
|
|
|
|
clientConf := consts.DefaultClientConfig + 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()
|
|
|
|
})
|
2021-03-31 16:57:39 +08:00
|
|
|
})
|