| 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 | [common] |
| 24 | bind_addr = 0.0.0.0 |
| 25 | bind_port = 7000 |
| 26 | `) |
| 27 | _, output, err := f.RunFrps("verify", "-c", path) |
| 28 | framework.ExpectNoError(err) |
| 29 | framework.ExpectTrue(strings.Contains(output, ConfigValidStr), "output: %s", output) |
| 30 | }) |
| 31 | ginkgo.It("frps invalid", func() { |
| 32 | path := f.GenerateConfigFile(` |
| 33 | [common] |
| 34 | bind_addr = 0.0.0.0 |
| 35 | bind_port = 70000 |
| 36 | `) |
| 37 | _, output, err := f.RunFrps("verify", "-c", path) |
| 38 | framework.ExpectNoError(err) |
| 39 | framework.ExpectTrue(!strings.Contains(output, ConfigValidStr), "output: %s", output) |
| 40 | }) |
| 41 | ginkgo.It("frpc valid", func() { |
| 42 | path := f.GenerateConfigFile(` |
| 43 | [common] |
| 44 | server_addr = 0.0.0.0 |
| 45 | server_port = 7000 |
| 46 | `) |
| 47 | _, output, err := f.RunFrpc("verify", "-c", path) |
| 48 | framework.ExpectNoError(err) |
| 49 | framework.ExpectTrue(strings.Contains(output, ConfigValidStr), "output: %s", output) |
| 50 | }) |
| 51 | ginkgo.It("frpc invalid", func() { |
| 52 | path := f.GenerateConfigFile(` |
| 53 | [common] |
| 54 | server_addr = 0.0.0.0 |
| 55 | server_port = 7000 |
| 56 | protocol = invalid |
| 57 | `) |
| 58 | _, output, err := f.RunFrpc("verify", "-c", path) |
| 59 | framework.ExpectNoError(err) |
| 60 | framework.ExpectTrue(!strings.Contains(output, ConfigValidStr), "output: %s", output) |
| 61 | }) |
| 62 | }) |
| 63 |
| 64 | ginkgo.Describe("Single proxy", func() { |
| 65 | ginkgo.It("TCP", func() { |
| 66 | serverPort := f.AllocPort() |
| 67 | _, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort)) |
| 68 | framework.ExpectNoError(err) |
| 69 |
| 70 | localPort := f.PortByName(framework.TCPEchoServerPort) |
| 71 | remotePort := f.AllocPort() |
| 72 | _, _, err = f.RunFrpc("tcp", "-s", "127.0.0.1", "-P", strconv.Itoa(serverPort), "-t", "123", "-u", "test", |
| 73 | "-l", strconv.Itoa(localPort), "-r", strconv.Itoa(remotePort), "-n", "tcp_test") |
| 74 | framework.ExpectNoError(err) |
| 75 |
| 76 | framework.NewRequestExpect(f).Port(remotePort).Ensure() |
| 77 | }) |
| 78 |
| 79 | ginkgo.It("UDP", func() { |
| 80 | serverPort := f.AllocPort() |
| 81 | _, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort)) |
| 82 | framework.ExpectNoError(err) |
| 83 |
| 84 | localPort := f.PortByName(framework.UDPEchoServerPort) |
| 85 | remotePort := f.AllocPort() |
| 86 | _, _, err = f.RunFrpc("udp", "-s", "127.0.0.1", "-P", strconv.Itoa(serverPort), "-t", "123", "-u", "test", |
| 87 | "-l", strconv.Itoa(localPort), "-r", strconv.Itoa(remotePort), "-n", "udp_test") |
| 88 | framework.ExpectNoError(err) |
| 89 |
| 90 | framework.NewRequestExpect(f).Protocol("udp"). |
| 91 | Port(remotePort).Ensure() |
| 92 | }) |
| 93 |
| 94 | ginkgo.It("HTTP", func() { |
| 95 | serverPort := f.AllocPort() |
| 96 | vhostHTTPPort := f.AllocPort() |
| 97 | _, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort), "--vhost_http_port", strconv.Itoa(vhostHTTPPort)) |
| 98 | framework.ExpectNoError(err) |
| 99 |
| 100 | _, _, err = f.RunFrpc("http", "-s", "127.0.0.1", "-P", strconv.Itoa(serverPort), "-t", "123", "-u", "test", |
| 101 | "-n", "udp_test", "-l", strconv.Itoa(f.PortByName(framework.HTTPSimpleServerPort)), |
| 102 | "--custom_domain", "test.example.com") |
| 103 | framework.ExpectNoError(err) |
| 104 |
| 105 | framework.NewRequestExpect(f).Port(vhostHTTPPort). |
| 106 | RequestModify(func(r *request.Request) { |
| 107 | r.HTTP().HTTPHost("test.example.com") |
| 108 | }). |
| 109 | Ensure() |
| 110 | }) |
| 111 | }) |
| 112 | }) |