2020-09-07 14:57:23 +08:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-06-18 16:48:36 +08:00
|
|
|
"strconv"
|
2020-09-07 14:57:23 +08:00
|
|
|
|
|
|
|
"github.com/fatedier/frp/test/e2e/framework"
|
|
|
|
"github.com/fatedier/frp/test/e2e/framework/consts"
|
2021-03-31 16:57:39 +08:00
|
|
|
"github.com/fatedier/frp/test/e2e/pkg/port"
|
2021-06-18 16:48:36 +08:00
|
|
|
"github.com/fatedier/frp/test/e2e/pkg/request"
|
2020-09-07 14:57:23 +08:00
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("[Feature: Client-Plugins]", func() {
|
|
|
|
f := framework.NewDefaultFramework()
|
|
|
|
|
|
|
|
Describe("UnixDomainSocket", func() {
|
|
|
|
It("Expose a unix domain socket echo server", func() {
|
|
|
|
serverConf := consts.DefaultServerConfig
|
|
|
|
clientConf := consts.DefaultClientConfig
|
|
|
|
|
|
|
|
getProxyConf := func(proxyName string, portName string, extra string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
[%s]
|
|
|
|
type = tcp
|
|
|
|
remote_port = {{ .%s }}
|
|
|
|
plugin = unix_domain_socket
|
|
|
|
plugin_unix_path = {{ .%s }}
|
|
|
|
`+extra, proxyName, portName, framework.UDSEchoServerAddr)
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
proxyName string
|
|
|
|
portName string
|
|
|
|
extraConfig string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
proxyName: "normal",
|
2021-03-31 16:57:39 +08:00
|
|
|
portName: port.GenName("Normal"),
|
2020-09-07 14:57:23 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
proxyName: "with-encryption",
|
2021-03-31 16:57:39 +08:00
|
|
|
portName: port.GenName("WithEncryption"),
|
2020-09-07 14:57:23 +08:00
|
|
|
extraConfig: "use_encryption = true",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
proxyName: "with-compression",
|
2021-03-31 16:57:39 +08:00
|
|
|
portName: port.GenName("WithCompression"),
|
2020-09-07 14:57:23 +08:00
|
|
|
extraConfig: "use_compression = true",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
proxyName: "with-encryption-and-compression",
|
2021-03-31 16:57:39 +08:00
|
|
|
portName: port.GenName("WithEncryptionAndCompression"),
|
2020-09-07 14:57:23 +08:00
|
|
|
extraConfig: `
|
|
|
|
use_encryption = true
|
|
|
|
use_compression = true
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// build all client config
|
|
|
|
for _, test := range tests {
|
|
|
|
clientConf += getProxyConf(test.proxyName, test.portName, test.extraConfig) + "\n"
|
|
|
|
}
|
|
|
|
// run frps and frpc
|
|
|
|
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2021-06-18 16:48:36 +08:00
|
|
|
framework.NewRequestExpect(f).Port(f.PortByName(test.portName)).Ensure()
|
2020-09-07 14:57:23 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2021-06-18 16:48:36 +08:00
|
|
|
|
|
|
|
It("plugin http_proxy", func() {
|
|
|
|
serverConf := consts.DefaultServerConfig
|
|
|
|
clientConf := consts.DefaultClientConfig
|
|
|
|
|
|
|
|
remotePort := f.AllocPort()
|
|
|
|
clientConf += fmt.Sprintf(`
|
|
|
|
[tcp]
|
|
|
|
type = tcp
|
|
|
|
remote_port = %d
|
|
|
|
plugin = http_proxy
|
|
|
|
plugin_http_user = abc
|
|
|
|
plugin_http_passwd = 123
|
|
|
|
`, remotePort)
|
|
|
|
|
|
|
|
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
|
|
|
|
|
|
|
// http proxy, no auth info
|
|
|
|
framework.NewRequestExpect(f).PortName(framework.HTTPSimpleServerPort).RequestModify(func(r *request.Request) {
|
|
|
|
r.HTTP().Proxy("http://127.0.0.1:" + strconv.Itoa(remotePort))
|
|
|
|
}).Ensure(framework.ExpectResponseCode(407))
|
|
|
|
|
|
|
|
// http proxy, correct auth
|
|
|
|
framework.NewRequestExpect(f).PortName(framework.HTTPSimpleServerPort).RequestModify(func(r *request.Request) {
|
|
|
|
r.HTTP().Proxy("http://abc:123@127.0.0.1:" + strconv.Itoa(remotePort))
|
|
|
|
}).Ensure()
|
|
|
|
|
|
|
|
// connect TCP server by CONNECT method
|
|
|
|
framework.NewRequestExpect(f).PortName(framework.TCPEchoServerPort).RequestModify(func(r *request.Request) {
|
|
|
|
r.TCP().Proxy("http://abc:123@127.0.0.1:" + strconv.Itoa(remotePort))
|
|
|
|
})
|
|
|
|
})
|
2020-09-07 14:57:23 +08:00
|
|
|
})
|