1
0

server_test.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // Copyright 2020 The frp Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package config
  15. import (
  16. "testing"
  17. "github.com/stretchr/testify/assert"
  18. "github.com/fatedier/frp/pkg/auth"
  19. plugin "github.com/fatedier/frp/pkg/plugin/server"
  20. )
  21. func Test_LoadServerCommonConf(t *testing.T) {
  22. assert := assert.New(t)
  23. testcases := []struct {
  24. source []byte
  25. expected ServerCommonConf
  26. }{
  27. {
  28. source: []byte(`
  29. # [common] is integral section
  30. [common]
  31. bind_addr = 0.0.0.9
  32. bind_port = 7009
  33. bind_udp_port = 7008
  34. kcp_bind_port = 7007
  35. proxy_bind_addr = 127.0.0.9
  36. vhost_http_port = 89
  37. vhost_https_port = 449
  38. vhost_http_timeout = 69
  39. tcpmux_httpconnect_port = 1339
  40. dashboard_addr = 0.0.0.9
  41. dashboard_port = 7509
  42. dashboard_user = admin9
  43. dashboard_pwd = admin9
  44. enable_prometheus
  45. assets_dir = ./static9
  46. log_file = ./frps.log9
  47. log_way = file
  48. log_level = info9
  49. log_max_days = 39
  50. disable_log_color = false
  51. detailed_errors_to_client
  52. authentication_method = token
  53. authenticate_heartbeats = false
  54. authenticate_new_work_conns = false
  55. token = 123456789
  56. oidc_issuer = test9
  57. oidc_audience = test9
  58. oidc_skip_expiry_check
  59. oidc_skip_issuer_check
  60. heartbeat_timeout = 99
  61. user_conn_timeout = 9
  62. allow_ports = 10-12,99
  63. max_pool_count = 59
  64. max_ports_per_client = 9
  65. tls_only = false
  66. tls_cert_file = server.crt
  67. tls_key_file = server.key
  68. tls_trusted_ca_file = ca.crt
  69. subdomain_host = frps.com
  70. tcp_mux
  71. udp_packet_size = 1509
  72. [plugin.user-manager]
  73. addr = 127.0.0.1:9009
  74. path = /handler
  75. ops = Login
  76. [plugin.port-manager]
  77. addr = 127.0.0.1:9009
  78. path = /handler
  79. ops = NewProxy
  80. tls_verify
  81. `),
  82. expected: ServerCommonConf{
  83. ServerConfig: auth.ServerConfig{
  84. BaseConfig: auth.BaseConfig{
  85. AuthenticationMethod: "token",
  86. AuthenticateHeartBeats: false,
  87. AuthenticateNewWorkConns: false,
  88. },
  89. TokenConfig: auth.TokenConfig{
  90. Token: "123456789",
  91. },
  92. OidcServerConfig: auth.OidcServerConfig{
  93. OidcIssuer: "test9",
  94. OidcAudience: "test9",
  95. OidcSkipExpiryCheck: true,
  96. OidcSkipIssuerCheck: true,
  97. },
  98. },
  99. BindAddr: "0.0.0.9",
  100. BindPort: 7009,
  101. KCPBindPort: 7007,
  102. QUICKeepalivePeriod: 10,
  103. QUICMaxIdleTimeout: 30,
  104. QUICMaxIncomingStreams: 100000,
  105. ProxyBindAddr: "127.0.0.9",
  106. VhostHTTPPort: 89,
  107. VhostHTTPSPort: 449,
  108. VhostHTTPTimeout: 69,
  109. TCPMuxHTTPConnectPort: 1339,
  110. DashboardAddr: "0.0.0.9",
  111. DashboardPort: 7509,
  112. DashboardUser: "admin9",
  113. DashboardPwd: "admin9",
  114. EnablePrometheus: true,
  115. AssetsDir: "./static9",
  116. LogFile: "./frps.log9",
  117. LogWay: "file",
  118. LogLevel: "info9",
  119. LogMaxDays: 39,
  120. DisableLogColor: false,
  121. DetailedErrorsToClient: true,
  122. HeartbeatTimeout: 99,
  123. UserConnTimeout: 9,
  124. AllowPorts: map[int]struct{}{
  125. 10: {},
  126. 11: {},
  127. 12: {},
  128. 99: {},
  129. },
  130. AllowPortsStr: "10-12,99",
  131. MaxPoolCount: 59,
  132. MaxPortsPerClient: 9,
  133. TLSOnly: true,
  134. TLSCertFile: "server.crt",
  135. TLSKeyFile: "server.key",
  136. TLSTrustedCaFile: "ca.crt",
  137. SubDomainHost: "frps.com",
  138. TCPMux: true,
  139. TCPMuxKeepaliveInterval: 60,
  140. TCPKeepAlive: 7200,
  141. UDPPacketSize: 1509,
  142. NatHoleAnalysisDataReserveHours: 7 * 24,
  143. HTTPPlugins: map[string]plugin.HTTPPluginOptions{
  144. "user-manager": {
  145. Name: "user-manager",
  146. Addr: "127.0.0.1:9009",
  147. Path: "/handler",
  148. Ops: []string{"Login"},
  149. },
  150. "port-manager": {
  151. Name: "port-manager",
  152. Addr: "127.0.0.1:9009",
  153. Path: "/handler",
  154. Ops: []string{"NewProxy"},
  155. TLSVerify: true,
  156. },
  157. },
  158. },
  159. },
  160. {
  161. source: []byte(`
  162. # [common] is integral section
  163. [common]
  164. bind_addr = 0.0.0.9
  165. bind_port = 7009
  166. bind_udp_port = 7008
  167. `),
  168. expected: ServerCommonConf{
  169. ServerConfig: auth.ServerConfig{
  170. BaseConfig: auth.BaseConfig{
  171. AuthenticationMethod: "token",
  172. AuthenticateHeartBeats: false,
  173. AuthenticateNewWorkConns: false,
  174. },
  175. },
  176. BindAddr: "0.0.0.9",
  177. BindPort: 7009,
  178. QUICKeepalivePeriod: 10,
  179. QUICMaxIdleTimeout: 30,
  180. QUICMaxIncomingStreams: 100000,
  181. ProxyBindAddr: "0.0.0.9",
  182. VhostHTTPTimeout: 60,
  183. DashboardAddr: "0.0.0.0",
  184. DashboardUser: "",
  185. DashboardPwd: "",
  186. EnablePrometheus: false,
  187. LogFile: "console",
  188. LogWay: "console",
  189. LogLevel: "info",
  190. LogMaxDays: 3,
  191. DetailedErrorsToClient: true,
  192. TCPMux: true,
  193. TCPMuxKeepaliveInterval: 60,
  194. TCPKeepAlive: 7200,
  195. AllowPorts: make(map[int]struct{}),
  196. MaxPoolCount: 5,
  197. HeartbeatTimeout: 90,
  198. UserConnTimeout: 10,
  199. HTTPPlugins: make(map[string]plugin.HTTPPluginOptions),
  200. UDPPacketSize: 1500,
  201. NatHoleAnalysisDataReserveHours: 7 * 24,
  202. },
  203. },
  204. }
  205. for _, c := range testcases {
  206. actual, err := UnmarshalServerConfFromIni(c.source)
  207. assert.NoError(err)
  208. actual.Complete()
  209. assert.Equal(c.expected, actual)
  210. }
  211. }