client_server.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package basic
  2. import (
  3. "fmt"
  4. "strings"
  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/onsi/ginkgo"
  9. )
  10. type generalTestConfigures struct {
  11. server string
  12. client string
  13. expectError bool
  14. }
  15. // defineClientServerTest test a normal tcp and udp proxy with specified TestConfigures.
  16. func defineClientServerTest(desc string, f *framework.Framework, configures *generalTestConfigures) {
  17. It(desc, func() {
  18. serverConf := consts.DefaultServerConfig
  19. clientConf := consts.DefaultClientConfig
  20. serverConf += fmt.Sprintf(`
  21. %s
  22. `, configures.server)
  23. tcpPortName := port.GenName("TCP")
  24. udpPortName := port.GenName("UDP")
  25. clientConf += fmt.Sprintf(`
  26. %s
  27. [tcp]
  28. type = tcp
  29. local_port = {{ .%s }}
  30. remote_port = {{ .%s }}
  31. [udp]
  32. type = udp
  33. local_port = {{ .%s }}
  34. remote_port = {{ .%s }}
  35. `, configures.client,
  36. framework.TCPEchoServerPort, tcpPortName,
  37. framework.UDPEchoServerPort, udpPortName,
  38. )
  39. f.RunProcesses([]string{serverConf}, []string{clientConf})
  40. framework.NewRequestExpect(f).PortName(tcpPortName).ExpectError(configures.expectError).Explain("tcp proxy").Ensure()
  41. framework.NewRequestExpect(f).RequestModify(framework.SetRequestProtocol("udp")).
  42. PortName(udpPortName).ExpectError(configures.expectError).Explain("udp proxy").Ensure()
  43. })
  44. }
  45. var _ = Describe("[Feature: Client-Server]", func() {
  46. f := framework.NewDefaultFramework()
  47. Describe("Protocol", func() {
  48. supportProtocols := []string{"tcp", "kcp", "websocket"}
  49. for _, protocol := range supportProtocols {
  50. configures := &generalTestConfigures{
  51. server: fmt.Sprintf(`
  52. kcp_bind_port = {{ .%s }}
  53. protocol = %s"
  54. `, consts.PortServerName, protocol),
  55. client: "protocol = " + protocol,
  56. }
  57. defineClientServerTest(protocol, f, configures)
  58. }
  59. })
  60. Describe("Authentication", func() {
  61. defineClientServerTest("Token Correct", f, &generalTestConfigures{
  62. server: "token = 123456",
  63. client: "token = 123456",
  64. })
  65. defineClientServerTest("Token Incorrect", f, &generalTestConfigures{
  66. server: "token = 123456",
  67. client: "token = invalid",
  68. expectError: true,
  69. })
  70. })
  71. Describe("TLS", func() {
  72. supportProtocols := []string{"tcp", "kcp", "websocket"}
  73. for _, protocol := range supportProtocols {
  74. tmp := protocol
  75. defineClientServerTest("TLS over "+strings.ToUpper(tmp), f, &generalTestConfigures{
  76. server: fmt.Sprintf(`
  77. kcp_bind_port = {{ .%s }}
  78. protocol = %s
  79. `, consts.PortServerName, protocol),
  80. client: fmt.Sprintf(`tls_enable = true
  81. protocol = %s
  82. `, protocol),
  83. })
  84. }
  85. defineClientServerTest("enable tls_only, client with TLS", f, &generalTestConfigures{
  86. server: "tls_only = true",
  87. client: "tls_enable = true",
  88. })
  89. defineClientServerTest("enable tls_only, client without TLS", f, &generalTestConfigures{
  90. server: "tls_only = true",
  91. expectError: true,
  92. })
  93. })
  94. })