server_test.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. kcp_bind_port = 7007
  34. proxy_bind_addr = 127.0.0.9
  35. vhost_http_port = 89
  36. vhost_https_port = 449
  37. vhost_http_timeout = 69
  38. tcpmux_httpconnect_port = 1339
  39. dashboard_addr = 0.0.0.9
  40. dashboard_port = 7509
  41. dashboard_user = admin9
  42. dashboard_pwd = admin9
  43. enable_prometheus
  44. assets_dir = ./static9
  45. log_file = ./frps.log9
  46. log_way = file
  47. log_level = info9
  48. log_max_days = 39
  49. disable_log_color = false
  50. detailed_errors_to_client
  51. authentication_method = token
  52. authenticate_heartbeats = false
  53. authenticate_new_work_conns = false
  54. token = 123456789
  55. oidc_issuer = test9
  56. oidc_audience = test9
  57. oidc_skip_expiry_check
  58. oidc_skip_issuer_check
  59. heartbeat_timeout = 99
  60. user_conn_timeout = 9
  61. allow_ports = 10-12,99
  62. max_pool_count = 59
  63. max_ports_per_client = 9
  64. tls_only = false
  65. tls_cert_file = server.crt
  66. tls_key_file = server.key
  67. tls_trusted_ca_file = ca.crt
  68. subdomain_host = frps.com
  69. tcp_mux
  70. udp_packet_size = 1509
  71. [plugin.user-manager]
  72. addr = 127.0.0.1:9009
  73. path = /handler
  74. ops = Login
  75. [plugin.port-manager]
  76. addr = 127.0.0.1:9009
  77. path = /handler
  78. ops = NewProxy
  79. tls_verify
  80. `),
  81. expected: ServerCommonConf{
  82. ServerConfig: auth.ServerConfig{
  83. BaseConfig: auth.BaseConfig{
  84. AuthenticationMethod: "token",
  85. AuthenticateHeartBeats: false,
  86. AuthenticateNewWorkConns: false,
  87. },
  88. TokenConfig: auth.TokenConfig{
  89. Token: "123456789",
  90. },
  91. OidcServerConfig: auth.OidcServerConfig{
  92. OidcIssuer: "test9",
  93. OidcAudience: "test9",
  94. OidcSkipExpiryCheck: true,
  95. OidcSkipIssuerCheck: true,
  96. },
  97. },
  98. BindAddr: "0.0.0.9",
  99. BindPort: 7009,
  100. KCPBindPort: 7007,
  101. QUICKeepalivePeriod: 10,
  102. QUICMaxIdleTimeout: 30,
  103. QUICMaxIncomingStreams: 100000,
  104. ProxyBindAddr: "127.0.0.9",
  105. VhostHTTPPort: 89,
  106. VhostHTTPSPort: 449,
  107. VhostHTTPTimeout: 69,
  108. TCPMuxHTTPConnectPort: 1339,
  109. DashboardAddr: "0.0.0.9",
  110. DashboardPort: 7509,
  111. DashboardUser: "admin9",
  112. DashboardPwd: "admin9",
  113. EnablePrometheus: true,
  114. AssetsDir: "./static9",
  115. LogFile: "./frps.log9",
  116. LogWay: "file",
  117. LogLevel: "info9",
  118. LogMaxDays: 39,
  119. DisableLogColor: false,
  120. DetailedErrorsToClient: true,
  121. HeartbeatTimeout: 99,
  122. UserConnTimeout: 9,
  123. AllowPorts: map[int]struct{}{
  124. 10: {},
  125. 11: {},
  126. 12: {},
  127. 99: {},
  128. },
  129. AllowPortsStr: "10-12,99",
  130. MaxPoolCount: 59,
  131. MaxPortsPerClient: 9,
  132. TLSOnly: true,
  133. TLSCertFile: "server.crt",
  134. TLSKeyFile: "server.key",
  135. TLSTrustedCaFile: "ca.crt",
  136. SubDomainHost: "frps.com",
  137. TCPMux: true,
  138. TCPMuxKeepaliveInterval: 60,
  139. TCPKeepAlive: 7200,
  140. UDPPacketSize: 1509,
  141. NatHoleAnalysisDataReserveHours: 7 * 24,
  142. HTTPPlugins: map[string]plugin.HTTPPluginOptions{
  143. "user-manager": {
  144. Name: "user-manager",
  145. Addr: "127.0.0.1:9009",
  146. Path: "/handler",
  147. Ops: []string{"Login"},
  148. },
  149. "port-manager": {
  150. Name: "port-manager",
  151. Addr: "127.0.0.1:9009",
  152. Path: "/handler",
  153. Ops: []string{"NewProxy"},
  154. TLSVerify: true,
  155. },
  156. },
  157. },
  158. },
  159. {
  160. source: []byte(`
  161. # [common] is integral section
  162. [common]
  163. bind_addr = 0.0.0.9
  164. bind_port = 7009
  165. `),
  166. expected: ServerCommonConf{
  167. ServerConfig: auth.ServerConfig{
  168. BaseConfig: auth.BaseConfig{
  169. AuthenticationMethod: "token",
  170. AuthenticateHeartBeats: false,
  171. AuthenticateNewWorkConns: false,
  172. },
  173. },
  174. BindAddr: "0.0.0.9",
  175. BindPort: 7009,
  176. QUICKeepalivePeriod: 10,
  177. QUICMaxIdleTimeout: 30,
  178. QUICMaxIncomingStreams: 100000,
  179. ProxyBindAddr: "0.0.0.9",
  180. VhostHTTPTimeout: 60,
  181. DashboardAddr: "0.0.0.0",
  182. DashboardUser: "",
  183. DashboardPwd: "",
  184. EnablePrometheus: false,
  185. LogFile: "console",
  186. LogWay: "console",
  187. LogLevel: "info",
  188. LogMaxDays: 3,
  189. DetailedErrorsToClient: true,
  190. TCPMux: true,
  191. TCPMuxKeepaliveInterval: 60,
  192. TCPKeepAlive: 7200,
  193. AllowPorts: make(map[int]struct{}),
  194. MaxPoolCount: 5,
  195. HeartbeatTimeout: 90,
  196. UserConnTimeout: 10,
  197. HTTPPlugins: make(map[string]plugin.HTTPPluginOptions),
  198. UDPPacketSize: 1500,
  199. NatHoleAnalysisDataReserveHours: 7 * 24,
  200. },
  201. },
  202. }
  203. for _, c := range testcases {
  204. actual, err := UnmarshalServerConfFromIni(c.source)
  205. assert.NoError(err)
  206. actual.Complete()
  207. assert.Equal(c.expected, actual)
  208. }
  209. }