mirror of
https://github.com/hacdias/webdav.git
synced 2026-09-22 03:20:41 +08:00
fix: config parsing keys
This commit is contained in:
+9
-9
@@ -31,7 +31,7 @@ type Config struct {
|
|||||||
Key string
|
Key string
|
||||||
Prefix string
|
Prefix string
|
||||||
NoSniff bool
|
NoSniff bool
|
||||||
LogFormat string
|
LogFormat string `mapstructure:"log_format"`
|
||||||
Auth bool
|
Auth bool
|
||||||
CORS CORS
|
CORS CORS
|
||||||
Users []User
|
Users []User
|
||||||
@@ -74,12 +74,12 @@ func ParseConfig(filename string, flags *pflag.FlagSet) (*Config, error) {
|
|||||||
v.SetDefault("Port", DefaultPort)
|
v.SetDefault("Port", DefaultPort)
|
||||||
v.SetDefault("Auth", DefaultAuth)
|
v.SetDefault("Auth", DefaultAuth)
|
||||||
v.SetDefault("Prefix", DefaultPrefix)
|
v.SetDefault("Prefix", DefaultPrefix)
|
||||||
v.SetDefault("LogFormat", DefaultLogFormat)
|
v.SetDefault("Log_Format", DefaultLogFormat)
|
||||||
|
|
||||||
// Other defaults
|
// Other defaults
|
||||||
v.SetDefault("CORS.AllowedHeaders", []string{"*"})
|
v.SetDefault("CORS.Allowed_Headers", []string{"*"})
|
||||||
v.SetDefault("CORS.AllowedHosts", []string{"*"})
|
v.SetDefault("CORS.Allowed_Hosts", []string{"*"})
|
||||||
v.SetDefault("CORS.AllowedMethods", []string{"*"})
|
v.SetDefault("CORS.Allowed_Methods", []string{"*"})
|
||||||
|
|
||||||
// Read and unmarshal configuration
|
// Read and unmarshal configuration
|
||||||
err := v.ReadInConfig()
|
err := v.ReadInConfig()
|
||||||
@@ -172,8 +172,8 @@ func (c *Config) Validate() error {
|
|||||||
type CORS struct {
|
type CORS struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
Credentials bool
|
Credentials bool
|
||||||
AllowedHeaders []string
|
AllowedHeaders []string `mapstructure:"allowed_headers"`
|
||||||
AllowedHosts []string
|
AllowedHosts []string `mapstructure:"allowed_hosts"`
|
||||||
AllowedMethods []string
|
AllowedMethods []string `mapstructure:"allowed_methods"`
|
||||||
ExposedHeaders []string
|
ExposedHeaders []string `mapstructure:"exposed_headers"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,3 +142,29 @@ rules = [ ]
|
|||||||
check(t, cfg)
|
check(t, cfg)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigKeys(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
cfg := writeAndParseConfig(t, `
|
||||||
|
cors:
|
||||||
|
enabled: true
|
||||||
|
credentials: true
|
||||||
|
allowed_headers:
|
||||||
|
- Depth
|
||||||
|
allowed_hosts:
|
||||||
|
- http://localhost:8080
|
||||||
|
allowed_methods:
|
||||||
|
- GET
|
||||||
|
exposed_headers:
|
||||||
|
- Content-Length
|
||||||
|
- Content-Range`, ".yml")
|
||||||
|
require.NoError(t, cfg.Validate())
|
||||||
|
|
||||||
|
require.True(t, cfg.CORS.Enabled)
|
||||||
|
require.True(t, cfg.CORS.Credentials)
|
||||||
|
require.EqualValues(t, []string{"Content-Length", "Content-Range"}, cfg.CORS.ExposedHeaders)
|
||||||
|
require.EqualValues(t, []string{"Depth"}, cfg.CORS.AllowedHeaders)
|
||||||
|
require.EqualValues(t, []string{"http://localhost:8080"}, cfg.CORS.AllowedHosts)
|
||||||
|
require.EqualValues(t, []string{"GET"}, cfg.CORS.AllowedMethods)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user