"Fossies" - the Fresh Open Source Software Archive

Member "frp-0.36.2/pkg/config/server_test.go" (22 Mar 2021, 5772 Bytes) of package /linux/misc/frp-0.36.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "server_test.go": 0.36.1_vs_0.36.2.

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