cmd.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. bindAddr = "0.0.0.0"
  18. bindPort = 7000
  19. `)
  20. _, output, err := f.RunFrps("verify", "-c", path)
  21. framework.ExpectNoError(err)
  22. framework.ExpectTrue(strings.Contains(output, ConfigValidStr), "output: %s", output)
  23. })
  24. ginkgo.It("frps invalid", func() {
  25. path := f.GenerateConfigFile(`
  26. bindAddr = "0.0.0.0"
  27. bindPort = 70000
  28. `)
  29. _, output, err := f.RunFrps("verify", "-c", path)
  30. framework.ExpectNoError(err)
  31. framework.ExpectTrue(!strings.Contains(output, ConfigValidStr), "output: %s", output)
  32. })
  33. ginkgo.It("frpc valid", func() {
  34. path := f.GenerateConfigFile(`
  35. serverAddr = "0.0.0.0"
  36. serverPort = 7000
  37. `)
  38. _, output, err := f.RunFrpc("verify", "-c", path)
  39. framework.ExpectNoError(err)
  40. framework.ExpectTrue(strings.Contains(output, ConfigValidStr), "output: %s", output)
  41. })
  42. ginkgo.It("frpc invalid", func() {
  43. path := f.GenerateConfigFile(`
  44. serverAddr = "0.0.0.0"
  45. serverPort = 7000
  46. transport.protocol = "invalid"
  47. `)
  48. _, output, err := f.RunFrpc("verify", "-c", path)
  49. framework.ExpectNoError(err)
  50. framework.ExpectTrue(!strings.Contains(output, ConfigValidStr), "output: %s", output)
  51. })
  52. })
  53. ginkgo.Describe("Single proxy", func() {
  54. ginkgo.It("TCP", func() {
  55. serverPort := f.AllocPort()
  56. _, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort))
  57. framework.ExpectNoError(err)
  58. localPort := f.PortByName(framework.TCPEchoServerPort)
  59. remotePort := f.AllocPort()
  60. _, _, err = f.RunFrpc("tcp", "-s", "127.0.0.1", "-P", strconv.Itoa(serverPort), "-t", "123", "-u", "test",
  61. "-l", strconv.Itoa(localPort), "-r", strconv.Itoa(remotePort), "-n", "tcp_test")
  62. framework.ExpectNoError(err)
  63. framework.NewRequestExpect(f).Port(remotePort).Ensure()
  64. })
  65. ginkgo.It("UDP", func() {
  66. serverPort := f.AllocPort()
  67. _, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort))
  68. framework.ExpectNoError(err)
  69. localPort := f.PortByName(framework.UDPEchoServerPort)
  70. remotePort := f.AllocPort()
  71. _, _, err = f.RunFrpc("udp", "-s", "127.0.0.1", "-P", strconv.Itoa(serverPort), "-t", "123", "-u", "test",
  72. "-l", strconv.Itoa(localPort), "-r", strconv.Itoa(remotePort), "-n", "udp_test")
  73. framework.ExpectNoError(err)
  74. framework.NewRequestExpect(f).Protocol("udp").
  75. Port(remotePort).Ensure()
  76. })
  77. ginkgo.It("HTTP", func() {
  78. serverPort := f.AllocPort()
  79. vhostHTTPPort := f.AllocPort()
  80. _, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort), "--vhost-http-port", strconv.Itoa(vhostHTTPPort))
  81. framework.ExpectNoError(err)
  82. _, _, err = f.RunFrpc("http", "-s", "127.0.0.1", "-P", strconv.Itoa(serverPort), "-t", "123", "-u", "test",
  83. "-n", "udp_test", "-l", strconv.Itoa(f.PortByName(framework.HTTPSimpleServerPort)),
  84. "--custom-domain", "test.example.com")
  85. framework.ExpectNoError(err)
  86. framework.NewRequestExpect(f).Port(vhostHTTPPort).
  87. RequestModify(func(r *request.Request) {
  88. r.HTTP().HTTPHost("test.example.com")
  89. }).
  90. Ensure()
  91. })
  92. })
  93. })