| 9 | "github.com/fatedier/frp/test/e2e/framework" |
| 10 | "github.com/fatedier/frp/test/e2e/pkg/request" |
| 11 | ) |
| 12 |
| 13 | const ( |
| 14 | ConfigValidStr = "syntax is ok" |
| 15 | ) |
| 16 |
| 17 | var _ = ginkgo.Describe("[Feature: Cmd]", func() { |
| 18 | f := framework.NewDefaultFramework() |
| 19 |
| 20 | ginkgo.Describe("Verify", func() { |
| 21 | ginkgo.It("frps valid", func() { |
| 22 | path := f.GenerateConfigFile(` |
| 23 | bindAddr = "0.0.0.0" |
| 24 | bindPort = 7000 |
| 25 | `) |
| 26 | _, output, err := f.RunFrps("verify", "-c", path) |
| 27 | framework.ExpectNoError(err) |
| 28 | framework.ExpectTrue(strings.Contains(output, ConfigValidStr), "output: %s", output) |
| 29 | }) |
| 30 | ginkgo.It("frps invalid", func() { |
| 31 | path := f.GenerateConfigFile(` |
| 32 | bindAddr = "0.0.0.0" |
| 33 | bindPort = 70000 |
| 34 | `) |
| 35 | _, output, err := f.RunFrps("verify", "-c", path) |
| 36 | framework.ExpectNoError(err) |
| 37 | framework.ExpectTrue(!strings.Contains(output, ConfigValidStr), "output: %s", output) |
| 38 | }) |
| 39 | ginkgo.It("frpc valid", func() { |
| 40 | path := f.GenerateConfigFile(` |
| 41 | serverAddr = "0.0.0.0" |
| 42 | serverPort = 7000 |
| 43 | `) |
| 44 | _, output, err := f.RunFrpc("verify", "-c", path) |
| 45 | framework.ExpectNoError(err) |
| 46 | framework.ExpectTrue(strings.Contains(output, ConfigValidStr), "output: %s", output) |
| 47 | }) |
| 48 | ginkgo.It("frpc invalid", func() { |
| 49 | path := f.GenerateConfigFile(` |
| 50 | serverAddr = "0.0.0.0" |
| 51 | serverPort = 7000 |
| 52 | transport.protocol = "invalid" |
| 53 | `) |
| 54 | _, output, err := f.RunFrpc("verify", "-c", path) |
| 55 | framework.ExpectNoError(err) |
| 56 | framework.ExpectTrue(!strings.Contains(output, ConfigValidStr), "output: %s", output) |
| 57 | }) |
| 58 | }) |
| 59 |
| 60 | ginkgo.Describe("Single proxy", func() { |
| 61 | ginkgo.It("TCP", func() { |
| 62 | serverPort := f.AllocPort() |
| 63 | _, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort)) |
| 64 | framework.ExpectNoError(err) |
| 65 |
| 66 | localPort := f.PortByName(framework.TCPEchoServerPort) |
| 67 | remotePort := f.AllocPort() |
| 68 | _, _, err = f.RunFrpc("tcp", "-s", "127.0.0.1", "-P", strconv.Itoa(serverPort), "-t", "123", "-u", "test", |
| 69 | "-l", strconv.Itoa(localPort), "-r", strconv.Itoa(remotePort), "-n", "tcp_test") |
| 70 | framework.ExpectNoError(err) |
| 71 |
| 72 | framework.NewRequestExpect(f).Port(remotePort).Ensure() |
| 73 | }) |
| 74 |
| 75 | ginkgo.It("UDP", func() { |
| 76 | serverPort := f.AllocPort() |
| 77 | _, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort)) |
| 78 | framework.ExpectNoError(err) |
| 79 |
| 80 | localPort := f.PortByName(framework.UDPEchoServerPort) |
| 81 | remotePort := f.AllocPort() |
| 82 | _, _, err = f.RunFrpc("udp", "-s", "127.0.0.1", "-P", strconv.Itoa(serverPort), "-t", "123", "-u", "test", |
| 83 | "-l", strconv.Itoa(localPort), "-r", strconv.Itoa(remotePort), "-n", "udp_test") |
| 84 | framework.ExpectNoError(err) |
| 85 |
| 86 | framework.NewRequestExpect(f).Protocol("udp"). |
| 87 | Port(remotePort).Ensure() |
| 88 | }) |
| 89 |
| 90 | ginkgo.It("HTTP", func() { |
| 91 | serverPort := f.AllocPort() |
| 92 | vhostHTTPPort := f.AllocPort() |
| 93 | _, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort), "--vhost-http-port", strconv.Itoa(vhostHTTPPort)) |
| 94 | framework.ExpectNoError(err) |
| 95 |
| 96 | _, _, err = f.RunFrpc("http", "-s", "127.0.0.1", "-P", strconv.Itoa(serverPort), "-t", "123", "-u", "test", |
| 97 | "-n", "udp_test", "-l", strconv.Itoa(f.PortByName(framework.HTTPSimpleServerPort)), |
| 98 | "--custom-domain", "test.example.com") |
| 99 | framework.ExpectNoError(err) |
| 100 |
| 101 | framework.NewRequestExpect(f).Port(vhostHTTPPort). |
| 102 | RequestModify(func(r *request.Request) { |
| 103 | r.HTTP().HTTPHost("test.example.com") |
| 104 | }). |
| 105 | Ensure() |
| 106 | }) |
| 107 | }) |
| 108 | }) |