| 9 |
| 10 | "github.com/onsi/ginkgo/v2" |
| 11 |
| 12 | "github.com/fatedier/frp/test/e2e/framework" |
| 13 | "github.com/fatedier/frp/test/e2e/framework/consts" |
| 14 | "github.com/fatedier/frp/test/e2e/pkg/request" |
| 15 | ) |
| 16 |
| 17 | var _ = ginkgo.Describe("[Feature: ClientManage]", func() { |
| 18 | f := framework.NewDefaultFramework() |
| 19 |
| 20 | ginkgo.It("Update && Reload API", func() { |
| 21 | serverConf := consts.LegacyDefaultServerConfig |
| 22 |
| 23 | adminPort := f.AllocPort() |
| 24 |
| 25 | p1Port := f.AllocPort() |
| 26 | p2Port := f.AllocPort() |
| 27 | p3Port := f.AllocPort() |
| 28 |
| 29 | clientConf := consts.LegacyDefaultClientConfig + fmt.Sprintf(` |
| 30 | admin_port = %d |
| 31 |
| 32 | [p1] |
| 33 | type = tcp |
| 34 | local_port = {{ .%s }} |
| 35 | remote_port = %d |
| 36 |
| 37 | [p2] |
| 38 | type = tcp |
| 39 | local_port = {{ .%s }} |
| 40 | remote_port = %d |
| 41 |
| 42 | [p3] |
| 43 | type = tcp |
| 44 | local_port = {{ .%s }} |
| 45 | remote_port = %d |
| 46 | `, adminPort, |
| 47 | framework.TCPEchoServerPort, p1Port, |
| 48 | framework.TCPEchoServerPort, p2Port, |
| 49 | framework.TCPEchoServerPort, p3Port) |
| 50 |
| 51 | f.RunProcesses(serverConf, []string{clientConf}) |
| 52 |
| 53 | framework.NewRequestExpect(f).Port(p1Port).Ensure() |
| 54 | framework.NewRequestExpect(f).Port(p2Port).Ensure() |
| 55 | framework.NewRequestExpect(f).Port(p3Port).Ensure() |
| 56 |
| 57 | client := f.APIClientForFrpc(adminPort) |
| 58 | conf, err := client.GetConfig(context.Background()) |
| 59 | framework.ExpectNoError(err) |
| 60 |
| 61 | newP2Port := f.AllocPort() |
| 62 | // change p2 port and remove p3 proxy |
| 63 | newClientConf := strings.ReplaceAll(conf, strconv.Itoa(p2Port), strconv.Itoa(newP2Port)) |
| 64 | p3Index := strings.Index(newClientConf, "[p3]") |
| 65 | if p3Index >= 0 { |
| 66 | newClientConf = newClientConf[:p3Index] |
| 67 | } |
| 68 |
| 69 | err = client.UpdateConfig(context.Background(), newClientConf) |
| 70 | framework.ExpectNoError(err) |
| 71 |
| 72 | err = client.Reload(context.Background(), true) |
| 73 | framework.ExpectNoError(err) |
| 74 | time.Sleep(time.Second) |
| 75 |
| 76 | framework.NewRequestExpect(f).Port(p1Port).Explain("p1 port").Ensure() |
| 77 | framework.NewRequestExpect(f).Port(p2Port).Explain("original p2 port").ExpectError(true).Ensure() |
| 78 | framework.NewRequestExpect(f).Port(newP2Port).Explain("new p2 port").Ensure() |
| 79 | framework.NewRequestExpect(f).Port(p3Port).Explain("p3 port").ExpectError(true).Ensure() |
| 80 | }) |
| 81 |
| 82 | ginkgo.It("healthz", func() { |
| 83 | serverConf := consts.LegacyDefaultServerConfig |
| 84 |
| 85 | dashboardPort := f.AllocPort() |
| 86 | clientConf := consts.LegacyDefaultClientConfig + fmt.Sprintf(` |
| 87 | admin_addr = 0.0.0.0 |
| 88 | admin_port = %d |
| 89 | admin_user = admin |
| 90 | admin_pwd = admin |
| 91 | `, dashboardPort) |
| 92 |
| 93 | f.RunProcesses(serverConf, []string{clientConf}) |
| 94 |
| 95 | framework.NewRequestExpect(f).RequestModify(func(r *request.Request) { |
| 96 | r.HTTP().HTTPPath("/healthz") |
| 97 | }).Port(dashboardPort).ExpectResp([]byte("")).Ensure() |
| 98 |
| 99 | framework.NewRequestExpect(f).RequestModify(func(r *request.Request) { |
| 100 | r.HTTP().HTTPPath("/") |
| 101 | }).Port(dashboardPort). |
| 102 | Ensure(framework.ExpectResponseCode(401)) |
| 103 | }) |
| 104 |
| 105 | ginkgo.It("stop", func() { |
| 106 | serverConf := consts.LegacyDefaultServerConfig |
| 107 |
| 108 | adminPort := f.AllocPort() |
| 109 | testPort := f.AllocPort() |
| 110 | clientConf := consts.LegacyDefaultClientConfig + fmt.Sprintf(` |
| 111 | admin_port = %d |
| 112 |
| 113 | [test] |
| 114 | type = tcp |
| 115 | local_port = {{ .%s }} |
| 116 | remote_port = %d |
| 117 | `, adminPort, framework.TCPEchoServerPort, testPort) |
| 118 |
| 119 | f.RunProcesses(serverConf, []string{clientConf}) |
| 120 |
| 121 | framework.NewRequestExpect(f).Port(testPort).Ensure() |
| 122 |
| 123 | client := f.APIClientForFrpc(adminPort) |
| 124 | err := client.Stop(context.Background()) |
| 125 | framework.ExpectNoError(err) |
| 126 |
| 127 | time.Sleep(3 * time.Second) |
| 128 |
| 129 | // frpc stopped so the port is not listened, expect error |
| 130 | framework.NewRequestExpect(f).Port(testPort).ExpectError(true).Ensure() |
| 131 | }) |
| 132 | }) |