cmd.go 3.3 KB

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