cmd.go 3.4 KB

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