frp/test/e2e/legacy/basic/client.go

132 lines
3.4 KiB
Go
Raw Permalink Normal View History

2021-06-18 16:48:36 +08:00
package basic
import (
"fmt"
"strconv"
"strings"
"time"
2023-02-27 14:44:16 +08:00
"github.com/onsi/ginkgo/v2"
2022-08-29 01:02:53 +08:00
2021-06-18 16:48:36 +08:00
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
"github.com/fatedier/frp/test/e2e/pkg/request"
2021-06-18 16:48:36 +08:00
)
2022-08-29 01:02:53 +08:00
var _ = ginkgo.Describe("[Feature: ClientManage]", func() {
2021-06-18 16:48:36 +08:00
f := framework.NewDefaultFramework()
2022-08-29 01:02:53 +08:00
ginkgo.It("Update && Reload API", func() {
2023-09-13 16:32:39 +08:00
serverConf := consts.LegacyDefaultServerConfig
2021-06-18 16:48:36 +08:00
adminPort := f.AllocPort()
p1Port := f.AllocPort()
p2Port := f.AllocPort()
p3Port := f.AllocPort()
2023-09-13 16:32:39 +08:00
clientConf := consts.LegacyDefaultClientConfig + fmt.Sprintf(`
2021-06-18 16:48:36 +08:00
admin_port = %d
[p1]
type = tcp
local_port = {{ .%s }}
remote_port = %d
[p2]
type = tcp
local_port = {{ .%s }}
remote_port = %d
[p3]
type = tcp
local_port = {{ .%s }}
remote_port = %d
`, adminPort,
framework.TCPEchoServerPort, p1Port,
framework.TCPEchoServerPort, p2Port,
framework.TCPEchoServerPort, p3Port)
f.RunProcesses([]string{serverConf}, []string{clientConf})
framework.NewRequestExpect(f).Port(p1Port).Ensure()
framework.NewRequestExpect(f).Port(p2Port).Ensure()
framework.NewRequestExpect(f).Port(p3Port).Ensure()
client := f.APIClientForFrpc(adminPort)
2021-06-18 16:48:36 +08:00
conf, err := client.GetConfig()
framework.ExpectNoError(err)
newP2Port := f.AllocPort()
// change p2 port and remove p3 proxy
newClientConf := strings.ReplaceAll(conf, strconv.Itoa(p2Port), strconv.Itoa(newP2Port))
p3Index := strings.Index(newClientConf, "[p3]")
2022-08-29 01:02:53 +08:00
if p3Index >= 0 {
newClientConf = newClientConf[:p3Index]
}
2021-06-18 16:48:36 +08:00
err = client.UpdateConfig(newClientConf)
framework.ExpectNoError(err)
2023-11-16 21:03:36 +08:00
err = client.Reload(true)
2021-06-18 16:48:36 +08:00
framework.ExpectNoError(err)
time.Sleep(time.Second)
framework.NewRequestExpect(f).Port(p1Port).Explain("p1 port").Ensure()
framework.NewRequestExpect(f).Port(p2Port).Explain("original p2 port").ExpectError(true).Ensure()
framework.NewRequestExpect(f).Port(newP2Port).Explain("new p2 port").Ensure()
framework.NewRequestExpect(f).Port(p3Port).Explain("p3 port").ExpectError(true).Ensure()
})
2022-08-29 01:02:53 +08:00
ginkgo.It("healthz", func() {
2023-09-13 16:32:39 +08:00
serverConf := consts.LegacyDefaultServerConfig
dashboardPort := f.AllocPort()
2023-09-13 16:32:39 +08:00
clientConf := consts.LegacyDefaultClientConfig + fmt.Sprintf(`
admin_addr = 0.0.0.0
admin_port = %d
admin_user = admin
admin_pwd = admin
`, dashboardPort)
f.RunProcesses([]string{serverConf}, []string{clientConf})
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
r.HTTP().HTTPPath("/healthz")
}).Port(dashboardPort).ExpectResp([]byte("")).Ensure()
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
r.HTTP().HTTPPath("/")
}).Port(dashboardPort).
Ensure(framework.ExpectResponseCode(401))
})
2023-06-30 17:35:37 +08:00
ginkgo.It("stop", func() {
2023-09-13 16:32:39 +08:00
serverConf := consts.LegacyDefaultServerConfig
2023-06-30 17:35:37 +08:00
adminPort := f.AllocPort()
testPort := f.AllocPort()
2023-09-13 16:32:39 +08:00
clientConf := consts.LegacyDefaultClientConfig + fmt.Sprintf(`
2023-06-30 17:35:37 +08:00
admin_port = %d
[test]
type = tcp
local_port = {{ .%s }}
remote_port = %d
`, adminPort, framework.TCPEchoServerPort, testPort)
f.RunProcesses([]string{serverConf}, []string{clientConf})
framework.NewRequestExpect(f).Port(testPort).Ensure()
client := f.APIClientForFrpc(adminPort)
2023-06-30 17:35:37 +08:00
err := client.Stop()
framework.ExpectNoError(err)
time.Sleep(3 * time.Second)
// frpc stopped so the port is not listened, expect error
framework.NewRequestExpect(f).Port(testPort).ExpectError(true).Ensure()
})
2021-06-18 16:48:36 +08:00
})