cmd.go 3.3 KB

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