2019-04-24 21:52:08 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-11-17 10:47:07 +00:00
|
|
|
"github.com/clems4ever/authelia/internal/configuration/schema"
|
2019-04-24 21:52:08 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newDefaultConfig() schema.Configuration {
|
|
|
|
config := schema.Configuration{}
|
2019-12-06 20:45:59 +00:00
|
|
|
config.Host = "127.0.0.1"
|
2019-04-24 21:52:08 +00:00
|
|
|
config.Port = 9090
|
|
|
|
config.LogsLevel = "info"
|
|
|
|
config.JWTSecret = "a_secret"
|
|
|
|
config.AuthenticationBackend.File = new(schema.FileAuthenticationBackendConfiguration)
|
|
|
|
config.AuthenticationBackend.File.Path = "/a/path"
|
|
|
|
config.Session = schema.SessionConfiguration{
|
|
|
|
Domain: "example.com",
|
|
|
|
Name: "authelia_session",
|
|
|
|
Secret: "secret",
|
|
|
|
}
|
2019-11-16 19:50:58 +00:00
|
|
|
config.Storage = &schema.StorageConfiguration{
|
|
|
|
Local: &schema.LocalStorageConfiguration{
|
|
|
|
Path: "abc",
|
|
|
|
},
|
|
|
|
}
|
2019-04-24 21:52:08 +00:00
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldNotUpdateConfig(t *testing.T) {
|
|
|
|
validator := schema.NewStructValidator()
|
|
|
|
config := newDefaultConfig()
|
|
|
|
|
|
|
|
Validate(&config, validator)
|
|
|
|
|
|
|
|
assert.Len(t, validator.Errors(), 0)
|
|
|
|
assert.Equal(t, 9090, config.Port)
|
|
|
|
assert.Equal(t, "info", config.LogsLevel)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldValidateAndUpdatePort(t *testing.T) {
|
|
|
|
validator := schema.NewStructValidator()
|
|
|
|
config := newDefaultConfig()
|
|
|
|
config.Port = 0
|
|
|
|
|
|
|
|
Validate(&config, validator)
|
|
|
|
|
|
|
|
assert.Len(t, validator.Errors(), 0)
|
|
|
|
assert.Equal(t, 8080, config.Port)
|
|
|
|
}
|
|
|
|
|
2019-12-06 20:45:59 +00:00
|
|
|
func TestShouldValidateAndUpdateHost(t *testing.T) {
|
|
|
|
validator := schema.NewStructValidator()
|
|
|
|
config := newDefaultConfig()
|
|
|
|
config.Host = ""
|
|
|
|
|
|
|
|
Validate(&config, validator)
|
|
|
|
|
|
|
|
assert.Len(t, validator.Errors(), 0)
|
|
|
|
assert.Equal(t, "0.0.0.0", config.Host)
|
|
|
|
}
|
|
|
|
|
2019-04-24 21:52:08 +00:00
|
|
|
func TestShouldValidateAndUpdateLogsLevel(t *testing.T) {
|
|
|
|
validator := schema.NewStructValidator()
|
|
|
|
config := newDefaultConfig()
|
|
|
|
config.LogsLevel = ""
|
|
|
|
|
|
|
|
Validate(&config, validator)
|
|
|
|
|
|
|
|
assert.Len(t, validator.Errors(), 0)
|
|
|
|
assert.Equal(t, "info", config.LogsLevel)
|
|
|
|
}
|