client.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package basic
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "github.com/fatedier/frp/test/e2e/framework"
  8. "github.com/fatedier/frp/test/e2e/framework/consts"
  9. "github.com/fatedier/frp/test/e2e/pkg/request"
  10. clientsdk "github.com/fatedier/frp/test/e2e/pkg/sdk/client"
  11. . "github.com/onsi/ginkgo"
  12. )
  13. var _ = Describe("[Feature: ClientManage]", func() {
  14. f := framework.NewDefaultFramework()
  15. It("Update && Reload API", func() {
  16. serverConf := consts.DefaultServerConfig
  17. adminPort := f.AllocPort()
  18. p1Port := f.AllocPort()
  19. p2Port := f.AllocPort()
  20. p3Port := f.AllocPort()
  21. clientConf := consts.DefaultClientConfig + fmt.Sprintf(`
  22. admin_port = %d
  23. [p1]
  24. type = tcp
  25. local_port = {{ .%s }}
  26. remote_port = %d
  27. [p2]
  28. type = tcp
  29. local_port = {{ .%s }}
  30. remote_port = %d
  31. [p3]
  32. type = tcp
  33. local_port = {{ .%s }}
  34. remote_port = %d
  35. `, adminPort,
  36. framework.TCPEchoServerPort, p1Port,
  37. framework.TCPEchoServerPort, p2Port,
  38. framework.TCPEchoServerPort, p3Port)
  39. f.RunProcesses([]string{serverConf}, []string{clientConf})
  40. framework.NewRequestExpect(f).Port(p1Port).Ensure()
  41. framework.NewRequestExpect(f).Port(p2Port).Ensure()
  42. framework.NewRequestExpect(f).Port(p3Port).Ensure()
  43. client := clientsdk.New("127.0.0.1", adminPort)
  44. conf, err := client.GetConfig()
  45. framework.ExpectNoError(err)
  46. newP2Port := f.AllocPort()
  47. // change p2 port and remove p3 proxy
  48. newClientConf := strings.ReplaceAll(conf, strconv.Itoa(p2Port), strconv.Itoa(newP2Port))
  49. p3Index := strings.Index(newClientConf, "[p3]")
  50. newClientConf = newClientConf[:p3Index]
  51. err = client.UpdateConfig(newClientConf)
  52. framework.ExpectNoError(err)
  53. err = client.Reload()
  54. framework.ExpectNoError(err)
  55. time.Sleep(time.Second)
  56. framework.NewRequestExpect(f).Port(p1Port).Explain("p1 port").Ensure()
  57. framework.NewRequestExpect(f).Port(p2Port).Explain("original p2 port").ExpectError(true).Ensure()
  58. framework.NewRequestExpect(f).Port(newP2Port).Explain("new p2 port").Ensure()
  59. framework.NewRequestExpect(f).Port(p3Port).Explain("p3 port").ExpectError(true).Ensure()
  60. })
  61. It("healthz", func() {
  62. serverConf := consts.DefaultServerConfig
  63. dashboardPort := f.AllocPort()
  64. clientConf := consts.DefaultClientConfig + fmt.Sprintf(`
  65. admin_addr = 0.0.0.0
  66. admin_port = %d
  67. admin_user = admin
  68. admin_pwd = admin
  69. `, dashboardPort)
  70. f.RunProcesses([]string{serverConf}, []string{clientConf})
  71. framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
  72. r.HTTP().HTTPPath("/healthz")
  73. }).Port(dashboardPort).ExpectResp([]byte("")).Ensure()
  74. framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
  75. r.HTTP().HTTPPath("/")
  76. }).Port(dashboardPort).
  77. Ensure(framework.ExpectResponseCode(401))
  78. })
  79. })