client_plugins.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package plugin
  2. import (
  3. "fmt"
  4. "strconv"
  5. "github.com/fatedier/frp/test/e2e/framework"
  6. "github.com/fatedier/frp/test/e2e/framework/consts"
  7. "github.com/fatedier/frp/test/e2e/pkg/port"
  8. "github.com/fatedier/frp/test/e2e/pkg/request"
  9. . "github.com/onsi/ginkgo"
  10. )
  11. var _ = Describe("[Feature: Client-Plugins]", func() {
  12. f := framework.NewDefaultFramework()
  13. Describe("UnixDomainSocket", func() {
  14. It("Expose a unix domain socket echo server", func() {
  15. serverConf := consts.DefaultServerConfig
  16. clientConf := consts.DefaultClientConfig
  17. getProxyConf := func(proxyName string, portName string, extra string) string {
  18. return fmt.Sprintf(`
  19. [%s]
  20. type = tcp
  21. remote_port = {{ .%s }}
  22. plugin = unix_domain_socket
  23. plugin_unix_path = {{ .%s }}
  24. `+extra, proxyName, portName, framework.UDSEchoServerAddr)
  25. }
  26. tests := []struct {
  27. proxyName string
  28. portName string
  29. extraConfig string
  30. }{
  31. {
  32. proxyName: "normal",
  33. portName: port.GenName("Normal"),
  34. },
  35. {
  36. proxyName: "with-encryption",
  37. portName: port.GenName("WithEncryption"),
  38. extraConfig: "use_encryption = true",
  39. },
  40. {
  41. proxyName: "with-compression",
  42. portName: port.GenName("WithCompression"),
  43. extraConfig: "use_compression = true",
  44. },
  45. {
  46. proxyName: "with-encryption-and-compression",
  47. portName: port.GenName("WithEncryptionAndCompression"),
  48. extraConfig: `
  49. use_encryption = true
  50. use_compression = true
  51. `,
  52. },
  53. }
  54. // build all client config
  55. for _, test := range tests {
  56. clientConf += getProxyConf(test.proxyName, test.portName, test.extraConfig) + "\n"
  57. }
  58. // run frps and frpc
  59. f.RunProcesses([]string{serverConf}, []string{clientConf})
  60. for _, test := range tests {
  61. framework.NewRequestExpect(f).Port(f.PortByName(test.portName)).Ensure()
  62. }
  63. })
  64. })
  65. It("plugin http_proxy", func() {
  66. serverConf := consts.DefaultServerConfig
  67. clientConf := consts.DefaultClientConfig
  68. remotePort := f.AllocPort()
  69. clientConf += fmt.Sprintf(`
  70. [tcp]
  71. type = tcp
  72. remote_port = %d
  73. plugin = http_proxy
  74. plugin_http_user = abc
  75. plugin_http_passwd = 123
  76. `, remotePort)
  77. f.RunProcesses([]string{serverConf}, []string{clientConf})
  78. // http proxy, no auth info
  79. framework.NewRequestExpect(f).PortName(framework.HTTPSimpleServerPort).RequestModify(func(r *request.Request) {
  80. r.HTTP().Proxy("http://127.0.0.1:" + strconv.Itoa(remotePort))
  81. }).Ensure(framework.ExpectResponseCode(407))
  82. // http proxy, correct auth
  83. framework.NewRequestExpect(f).PortName(framework.HTTPSimpleServerPort).RequestModify(func(r *request.Request) {
  84. r.HTTP().Proxy("http://abc:123@127.0.0.1:" + strconv.Itoa(remotePort))
  85. }).Ensure()
  86. // connect TCP server by CONNECT method
  87. framework.NewRequestExpect(f).PortName(framework.TCPEchoServerPort).RequestModify(func(r *request.Request) {
  88. r.TCP().Proxy("http://abc:123@127.0.0.1:" + strconv.Itoa(remotePort))
  89. })
  90. })
  91. })