| 9 | "github.com/fatedier/frp/test/e2e/framework" |
| 10 | "github.com/fatedier/frp/test/e2e/framework/consts" |
| 11 | "github.com/fatedier/frp/test/e2e/pkg/port" |
| 12 | ) |
| 13 |
| 14 | var _ = ginkgo.Describe("[Feature: Config]", func() { |
| 15 | f := framework.NewDefaultFramework() |
| 16 |
| 17 | ginkgo.Describe("Template", func() { |
| 18 | ginkgo.It("render by env", func() { |
| 19 | serverConf := consts.DefaultServerConfig |
| 20 | clientConf := consts.DefaultClientConfig |
| 21 |
| 22 | portName := port.GenName("TCP") |
| 23 | serverConf += fmt.Sprintf(` |
| 24 | auth.token = "{{ %s{{ .Envs.FRP_TOKEN }}%s }}" |
| 25 | `, "`", "`") |
| 26 |
| 27 | clientConf += fmt.Sprintf(` |
| 28 | auth.token = "{{ %s{{ .Envs.FRP_TOKEN }}%s }}" |
| 29 |
| 30 | [[proxies]] |
| 31 | name = "tcp" |
| 32 | type = "tcp" |
| 33 | localPort = {{ .%s }} |
| 34 | remotePort = {{ .%s }} |
| 35 | `, "`", "`", framework.TCPEchoServerPort, portName) |
| 36 |
| 37 | f.SetEnvs([]string{"FRP_TOKEN=123"}) |
| 38 | f.RunProcesses(serverConf, []string{clientConf}) |
| 39 |
| 40 | framework.NewRequestExpect(f).PortName(portName).Ensure() |
| 41 | }) |
| 42 |
| 43 | ginkgo.It("Range ports mapping", func() { |
| 44 | serverConf := consts.DefaultServerConfig |
| 45 | clientConf := consts.DefaultClientConfig |
| 46 |
| 47 | adminPort := f.AllocPort() |
| 48 |
| 49 | localPortsRange := "13010-13012,13014" |
| 50 | remotePortsRange := "23010-23012,23014" |
| 51 | escapeTemplate := func(s string) string { |
| 52 | return "{{ `" + s + "` }}" |
| 53 | } |
| 54 | clientConf += fmt.Sprintf(` |
| 55 | webServer.port = %d |
| 56 |
| 57 | %s |
| 58 | [[proxies]] |
| 59 | name = "tcp-%s" |
| 60 | type = "tcp" |
| 61 | localPort = %s |
| 62 | remotePort = %s |
| 63 | %s |
| 64 | `, adminPort, |
| 65 | escapeTemplate(fmt.Sprintf(`{{- range $_, $v := parseNumberRangePair "%s" "%s" }}`, localPortsRange, remotePortsRange)), |
| 66 | escapeTemplate("{{ $v.First }}"), |
| 67 | escapeTemplate("{{ $v.First }}"), |
| 68 | escapeTemplate("{{ $v.Second }}"), |
| 69 | escapeTemplate("{{- end }}"), |
| 70 | ) |
| 71 |
| 72 | f.RunProcesses(serverConf, []string{clientConf}) |
| 73 |
| 74 | client := f.APIClientForFrpc(adminPort) |
| 75 | checkProxyFn := func(name string, localPort, remotePort int) { |
| 76 | status, err := client.GetProxyStatus(context.Background(), name) |
| 77 | framework.ExpectNoError(err) |
| 78 |
| 79 | framework.ExpectContainSubstring(status.LocalAddr, fmt.Sprintf(":%d", localPort)) |
| 80 | framework.ExpectContainSubstring(status.RemoteAddr, fmt.Sprintf(":%d", remotePort)) |
| 81 | } |
| 82 | checkProxyFn("tcp-13010", 13010, 23010) |
| 83 | checkProxyFn("tcp-13011", 13011, 23011) |
| 84 | checkProxyFn("tcp-13012", 13012, 23012) |
| 85 | checkProxyFn("tcp-13014", 13014, 23014) |
| 86 | }) |
| 87 | }) |
| 88 |
| 89 | ginkgo.Describe("Includes", func() { |
| 90 | ginkgo.It("split tcp proxies into different files", func() { |
| 91 | serverPort := f.AllocPort() |
| 92 | serverConfigPath := f.GenerateConfigFile(fmt.Sprintf(` |
| 93 | bindAddr = "0.0.0.0" |
| 94 | bindPort = %d |
| 95 | `, serverPort)) |
| 96 |
| 97 | remotePort := f.AllocPort() |
| 98 | proxyConfigPath := f.GenerateConfigFile(fmt.Sprintf(` |
| 99 | [[proxies]] |
| 100 | name = "tcp" |
| 101 | type = "tcp" |
| 102 | localPort = %d |
| 103 | remotePort = %d |
| 104 | `, f.PortByName(framework.TCPEchoServerPort), remotePort)) |
| 105 |
| 106 | remotePort2 := f.AllocPort() |
| 107 | proxyConfigPath2 := f.GenerateConfigFile(fmt.Sprintf(` |
| 108 | [[proxies]] |
| 109 | name = "tcp2" |
| 110 | type = "tcp" |
| 111 | localPort = %d |
| 112 | remotePort = %d |
| 113 | `, f.PortByName(framework.TCPEchoServerPort), remotePort2)) |
| 114 |
| 115 | clientConfigPath := f.GenerateConfigFile(fmt.Sprintf(` |
| 116 | serverPort = %d |
| 117 | includes = ["%s","%s"] |
| 118 | `, serverPort, proxyConfigPath, proxyConfigPath2)) |
| 119 |
| 120 | _, _, err := f.RunFrps("-c", serverConfigPath) |
| 121 | framework.ExpectNoError(err) |
| 122 |
| 123 | _, _, err = f.RunFrpc("-c", clientConfigPath) |
| 124 | framework.ExpectNoError(err) |
| 125 |
| 126 | framework.NewRequestExpect(f).Port(remotePort).Ensure() |
| 127 | framework.NewRequestExpect(f).Port(remotePort2).Ensure() |
| 128 | }) |
| 129 | }) |
| 130 |
| 131 | ginkgo.Describe("Support Formats", func() { |
| 132 | ginkgo.It("YAML", func() { |
| 133 | serverConf := fmt.Sprintf(` |
| 134 | bindPort: {{ .%s }} |
| 135 | log: |
| 136 | level: trace |
| 137 | `, port.GenName("Server")) |
| 138 |
| 139 | remotePort := f.AllocPort() |
| 140 | clientConf := fmt.Sprintf(` |
| 141 | serverPort: {{ .%s }} |
| 142 | log: |
| 143 | level: trace |
| 144 |
| 145 | proxies: |
| 146 | - name: tcp |
| 147 | type: tcp |
| 148 | localPort: {{ .%s }} |
| 149 | remotePort: %d |
| 150 | `, port.GenName("Server"), framework.TCPEchoServerPort, remotePort) |
| 151 |
| 152 | f.RunProcesses(serverConf, []string{clientConf}) |
| 153 | framework.NewRequestExpect(f).Port(remotePort).Ensure() |
| 154 | }) |
| 155 |
| 156 | ginkgo.It("JSON", func() { |
| 157 | serverConf := fmt.Sprintf(`{"bindPort": {{ .%s }}, "log": {"level": "trace"}}`, port.GenName("Server")) |
| 158 |
| 159 | remotePort := f.AllocPort() |
| 160 | clientConf := fmt.Sprintf(`{"serverPort": {{ .%s }}, "log": {"level": "trace"}, |
| 161 | "proxies": [{"name": "tcp", "type": "tcp", "localPort": {{ .%s }}, "remotePort": %d}]}`, |
| 162 | port.GenName("Server"), framework.TCPEchoServerPort, remotePort) |
| 163 |
| 164 | f.RunProcesses(serverConf, []string{clientConf}) |
| 165 | framework.NewRequestExpect(f).Port(remotePort).Ensure() |
| 166 | }) |
| 167 | }) |
| 168 | }) |