1
0

server_test.go 6.0 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. BindUDPPort: 7008,
  102. KCPBindPort: 7007,
  103. QUICKeepalivePeriod: 10,
  104. QUICMaxIdleTimeout: 30,
  105. QUICMaxIncomingStreams: 100000,
  106. ProxyBindAddr: "127.0.0.9",
  107. VhostHTTPPort: 89,
  108. VhostHTTPSPort: 449,
  109. VhostHTTPTimeout: 69,
  110. TCPMuxHTTPConnectPort: 1339,
  111. DashboardAddr: "0.0.0.9",
  112. DashboardPort: 7509,
  113. DashboardUser: "admin9",
  114. DashboardPwd: "admin9",
  115. EnablePrometheus: true,
  116. AssetsDir: "./static9",
  117. LogFile: "./frps.log9",
  118. LogWay: "file",
  119. LogLevel: "info9",
  120. LogMaxDays: 39,
  121. DisableLogColor: false,
  122. DetailedErrorsToClient: true,
  123. HeartbeatTimeout: 99,
  124. UserConnTimeout: 9,
  125. AllowPorts: map[int]struct{}{
  126. 10: {},
  127. 11: {},
  128. 12: {},
  129. 99: {},
  130. },
  131. AllowPortsStr: "10-12,99",
  132. MaxPoolCount: 59,
  133. MaxPortsPerClient: 9,
  134. TLSOnly: true,
  135. TLSCertFile: "server.crt",
  136. TLSKeyFile: "server.key",
  137. TLSTrustedCaFile: "ca.crt",
  138. SubDomainHost: "frps.com",
  139. TCPMux: true,
  140. TCPMuxKeepaliveInterval: 60,
  141. TCPKeepAlive: 7200,
  142. UDPPacketSize: 1509,
  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. BindUDPPort: 7008,
  179. QUICKeepalivePeriod: 10,
  180. QUICMaxIdleTimeout: 30,
  181. QUICMaxIncomingStreams: 100000,
  182. ProxyBindAddr: "0.0.0.9",
  183. VhostHTTPTimeout: 60,
  184. DashboardAddr: "0.0.0.0",
  185. DashboardUser: "",
  186. DashboardPwd: "",
  187. EnablePrometheus: false,
  188. LogFile: "console",
  189. LogWay: "console",
  190. LogLevel: "info",
  191. LogMaxDays: 3,
  192. DetailedErrorsToClient: true,
  193. TCPMux: true,
  194. TCPMuxKeepaliveInterval: 60,
  195. TCPKeepAlive: 7200,
  196. AllowPorts: make(map[int]struct{}),
  197. MaxPoolCount: 5,
  198. HeartbeatTimeout: 90,
  199. UserConnTimeout: 10,
  200. HTTPPlugins: make(map[string]plugin.HTTPPluginOptions),
  201. UDPPacketSize: 1500,
  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. }