mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
3c81e75d79
This adds an access-control command that checks the policy enforcement for a given criteria using a configuration file and refactors the configuration validation command to include all configuration sources.
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package validator
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
|
)
|
|
|
|
type Theme struct {
|
|
suite.Suite
|
|
config *schema.Configuration
|
|
validator *schema.StructValidator
|
|
}
|
|
|
|
func (suite *Theme) SetupTest() {
|
|
suite.validator = schema.NewStructValidator()
|
|
suite.config = &schema.Configuration{
|
|
Theme: "light",
|
|
}
|
|
}
|
|
|
|
func (suite *Theme) TestShouldValidateCompleteConfiguration() {
|
|
ValidateTheme(suite.config, suite.validator)
|
|
|
|
suite.Assert().False(suite.validator.HasWarnings())
|
|
suite.Assert().False(suite.validator.HasErrors())
|
|
}
|
|
|
|
func (suite *Theme) TestShouldRaiseErrorWhenInvalidThemeProvided() {
|
|
suite.config.Theme = "invalid"
|
|
|
|
ValidateTheme(suite.config, suite.validator)
|
|
|
|
suite.Assert().False(suite.validator.HasWarnings())
|
|
suite.Require().Len(suite.validator.Errors(), 1)
|
|
|
|
suite.Assert().EqualError(suite.validator.Errors()[0], "option 'theme' must be one of 'light', 'dark', 'grey', 'auto' but it is configured as 'invalid'")
|
|
}
|
|
|
|
func TestThemes(t *testing.T) {
|
|
suite.Run(t, new(Theme))
|
|
}
|