server_test.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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/fatedier/frp/pkg/auth"
  18. plugin "github.com/fatedier/frp/pkg/plugin/server"
  19. "github.com/stretchr/testify/assert"
  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. ProxyBindAddr: "127.0.0.9",
  104. VhostHTTPPort: 89,
  105. VhostHTTPSPort: 449,
  106. VhostHTTPTimeout: 69,
  107. TCPMuxHTTPConnectPort: 1339,
  108. DashboardAddr: "0.0.0.9",
  109. DashboardPort: 7509,
  110. DashboardUser: "admin9",
  111. DashboardPwd: "admin9",
  112. EnablePrometheus: true,
  113. AssetsDir: "./static9",
  114. LogFile: "./frps.log9",
  115. LogWay: "file",
  116. LogLevel: "info9",
  117. LogMaxDays: 39,
  118. DisableLogColor: false,
  119. DetailedErrorsToClient: true,
  120. HeartbeatTimeout: 99,
  121. UserConnTimeout: 9,
  122. AllowPorts: map[int]struct{}{
  123. 10: struct{}{},
  124. 11: struct{}{},
  125. 12: struct{}{},
  126. 99: struct{}{},
  127. },
  128. MaxPoolCount: 59,
  129. MaxPortsPerClient: 9,
  130. TLSOnly: true,
  131. TLSCertFile: "server.crt",
  132. TLSKeyFile: "server.key",
  133. TLSTrustedCaFile: "ca.crt",
  134. SubDomainHost: "frps.com",
  135. TCPMux: true,
  136. TCPMuxKeepaliveInterval: 60,
  137. UDPPacketSize: 1509,
  138. HTTPPlugins: map[string]plugin.HTTPPluginOptions{
  139. "user-manager": {
  140. Name: "user-manager",
  141. Addr: "127.0.0.1:9009",
  142. Path: "/handler",
  143. Ops: []string{"Login"},
  144. },
  145. "port-manager": {
  146. Name: "port-manager",
  147. Addr: "127.0.0.1:9009",
  148. Path: "/handler",
  149. Ops: []string{"NewProxy"},
  150. TLSVerify: true,
  151. },
  152. },
  153. },
  154. },
  155. {
  156. source: []byte(`
  157. # [common] is integral section
  158. [common]
  159. bind_addr = 0.0.0.9
  160. bind_port = 7009
  161. bind_udp_port = 7008
  162. `),
  163. expected: ServerCommonConf{
  164. ServerConfig: auth.ServerConfig{
  165. BaseConfig: auth.BaseConfig{
  166. AuthenticationMethod: "token",
  167. AuthenticateHeartBeats: false,
  168. AuthenticateNewWorkConns: false,
  169. },
  170. },
  171. BindAddr: "0.0.0.9",
  172. BindPort: 7009,
  173. BindUDPPort: 7008,
  174. ProxyBindAddr: "0.0.0.9",
  175. VhostHTTPTimeout: 60,
  176. DashboardAddr: "0.0.0.0",
  177. DashboardUser: "",
  178. DashboardPwd: "",
  179. EnablePrometheus: false,
  180. LogFile: "console",
  181. LogWay: "console",
  182. LogLevel: "info",
  183. LogMaxDays: 3,
  184. DetailedErrorsToClient: true,
  185. TCPMux: true,
  186. TCPMuxKeepaliveInterval: 60,
  187. AllowPorts: make(map[int]struct{}),
  188. MaxPoolCount: 5,
  189. HeartbeatTimeout: 90,
  190. UserConnTimeout: 10,
  191. HTTPPlugins: make(map[string]plugin.HTTPPluginOptions),
  192. UDPPacketSize: 1500,
  193. },
  194. },
  195. }
  196. for _, c := range testcases {
  197. actual, err := UnmarshalServerConfFromIni(c.source)
  198. assert.NoError(err)
  199. actual.Complete()
  200. assert.Equal(c.expected, actual)
  201. }
  202. }