mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
4dce8f9496
* adjust session refresh to always occur (for disabled users) * feat: adds filtering option for Request Method in ACL's * simplify flow of internal/authorization/authorizer.go's methods * implement query string checking * utilize authorizer.Object fully * make matchers uniform * add tests * add missing request methods * add frontend enhancements to handle request method * add request method to 1FA Handler Suite * add internal ACL representations (preparsing) * expand on access_control next * add docs * remove unnecessary slice for network names and instead just use a plain string * add warning for ineffectual bypass policy (due to subjects) * add user/group wildcard support * fix(authorization): allow subject rules to match anonymous users * feat(api): add new params * docs(api): wording adjustments * test: add request method into testing and proxy docs * test: add several checks and refactor schema validation for ACL * test: add integration test for methods acl * refactor: apply suggestions from code review * docs(authorization): update description
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package validator
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
|
)
|
|
|
|
func newDefaultRegulationConfig() schema.RegulationConfiguration {
|
|
config := schema.RegulationConfiguration{}
|
|
return config
|
|
}
|
|
|
|
func TestShouldSetDefaultRegulationBanTime(t *testing.T) {
|
|
validator := schema.NewStructValidator()
|
|
config := newDefaultRegulationConfig()
|
|
|
|
ValidateRegulation(&config, validator)
|
|
|
|
assert.Len(t, validator.Errors(), 0)
|
|
assert.Equal(t, schema.DefaultRegulationConfiguration.BanTime, config.BanTime)
|
|
}
|
|
|
|
func TestShouldSetDefaultRegulationFindTime(t *testing.T) {
|
|
validator := schema.NewStructValidator()
|
|
config := newDefaultRegulationConfig()
|
|
|
|
ValidateRegulation(&config, validator)
|
|
|
|
assert.Len(t, validator.Errors(), 0)
|
|
assert.Equal(t, schema.DefaultRegulationConfiguration.FindTime, config.FindTime)
|
|
}
|
|
|
|
func TestShouldRaiseErrorWhenFindTimeLessThanBanTime(t *testing.T) {
|
|
validator := schema.NewStructValidator()
|
|
config := newDefaultRegulationConfig()
|
|
config.FindTime = "1m"
|
|
config.BanTime = "10s"
|
|
|
|
ValidateRegulation(&config, validator)
|
|
|
|
assert.Len(t, validator.Errors(), 1)
|
|
assert.EqualError(t, validator.Errors()[0], "find_time cannot be greater than ban_time")
|
|
}
|
|
|
|
func TestShouldRaiseErrorOnBadDurationStrings(t *testing.T) {
|
|
validator := schema.NewStructValidator()
|
|
config := newDefaultRegulationConfig()
|
|
config.FindTime = "a year"
|
|
config.BanTime = "forever"
|
|
|
|
ValidateRegulation(&config, validator)
|
|
|
|
assert.Len(t, validator.Errors(), 2)
|
|
assert.EqualError(t, validator.Errors()[0], "Error occurred parsing regulation find_time string: Could not convert the input string of a year into a duration")
|
|
assert.EqualError(t, validator.Errors()[1], "Error occurred parsing regulation ban_time string: Could not convert the input string of forever into a duration")
|
|
}
|