2021-06-18 16:48:36 +08:00
|
|
|
package basic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2023-02-27 14:44:16 +08:00
|
|
|
"github.com/onsi/ginkgo/v2"
|
2022-08-29 01:02:53 +08:00
|
|
|
|
2021-06-18 16:48:36 +08:00
|
|
|
"github.com/fatedier/frp/test/e2e/framework"
|
|
|
|
"github.com/fatedier/frp/test/e2e/pkg/request"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
ConfigValidStr = "syntax is ok"
|
|
|
|
)
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
var _ = ginkgo.Describe("[Feature: Cmd]", func() {
|
2021-06-18 16:48:36 +08:00
|
|
|
f := framework.NewDefaultFramework()
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.Describe("Verify", func() {
|
|
|
|
ginkgo.It("frps valid", func() {
|
2021-06-18 16:48:36 +08:00
|
|
|
path := f.GenerateConfigFile(`
|
2023-09-13 16:32:39 +08:00
|
|
|
bindAddr = "0.0.0.0"
|
|
|
|
bindPort = 7000
|
2021-06-18 16:48:36 +08:00
|
|
|
`)
|
|
|
|
_, output, err := f.RunFrps("verify", "-c", path)
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
framework.ExpectTrue(strings.Contains(output, ConfigValidStr), "output: %s", output)
|
|
|
|
})
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("frps invalid", func() {
|
2021-06-18 16:48:36 +08:00
|
|
|
path := f.GenerateConfigFile(`
|
2023-09-13 16:32:39 +08:00
|
|
|
bindAddr = "0.0.0.0"
|
|
|
|
bindPort = 70000
|
2021-06-18 16:48:36 +08:00
|
|
|
`)
|
|
|
|
_, output, err := f.RunFrps("verify", "-c", path)
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
framework.ExpectTrue(!strings.Contains(output, ConfigValidStr), "output: %s", output)
|
|
|
|
})
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("frpc valid", func() {
|
2021-06-18 16:48:36 +08:00
|
|
|
path := f.GenerateConfigFile(`
|
2023-09-13 16:32:39 +08:00
|
|
|
serverAddr = "0.0.0.0"
|
|
|
|
serverPort = 7000
|
2021-06-18 16:48:36 +08:00
|
|
|
`)
|
|
|
|
_, output, err := f.RunFrpc("verify", "-c", path)
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
framework.ExpectTrue(strings.Contains(output, ConfigValidStr), "output: %s", output)
|
|
|
|
})
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("frpc invalid", func() {
|
2021-06-18 16:48:36 +08:00
|
|
|
path := f.GenerateConfigFile(`
|
2023-09-13 16:32:39 +08:00
|
|
|
serverAddr = "0.0.0.0"
|
|
|
|
serverPort = 7000
|
|
|
|
transport.protocol = "invalid"
|
2021-06-18 16:48:36 +08:00
|
|
|
`)
|
|
|
|
_, output, err := f.RunFrpc("verify", "-c", path)
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
framework.ExpectTrue(!strings.Contains(output, ConfigValidStr), "output: %s", output)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.Describe("Single proxy", func() {
|
|
|
|
ginkgo.It("TCP", func() {
|
2021-06-18 16:48:36 +08:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("UDP", func() {
|
2021-06-18 16:48:36 +08:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("HTTP", func() {
|
2021-06-18 16:48:36 +08:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|