client_server.go 3.1 KB

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