summaryrefslogtreecommitdiff
path: root/internal/configuration/provider_test.go
diff options
context:
space:
mode:
authorJames Elliott <james-d-elliott@users.noreply.github.com>2023-11-23 08:20:36 +1100
committerGitHub <noreply@github.com>2023-11-23 08:20:36 +1100
commitc49b973120c7fd755923a2b88afd794c7d320d6e (patch)
tree5fcef6de1a85568eee3c67470f73b790b294dda8 /internal/configuration/provider_test.go
parentfa141929a39e546f3f3ca6bcbc7bd72c64e575c8 (diff)
fix(configuration): illogical refresh interval default (#6319)
When using the file provider with watch enabled, the refresh interval should just be set to always default as the cost is minimal. Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
Diffstat (limited to 'internal/configuration/provider_test.go')
-rw-r--r--internal/configuration/provider_test.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/configuration/provider_test.go b/internal/configuration/provider_test.go
index 771e47316..b0714baaf 100644
--- a/internal/configuration/provider_test.go
+++ b/internal/configuration/provider_test.go
@@ -86,6 +86,24 @@ func TestShouldHaveNotifier(t *testing.T) {
assert.NotNil(t, config.Notifier)
}
+func TestShouldConfigureRefreshIntervalDisable(t *testing.T) {
+ testSetEnv(t, "SESSION_SECRET", "abc")
+ testSetEnv(t, "STORAGE_MYSQL_PASSWORD", "abc")
+ testSetEnv(t, "JWT_SECRET", "abc")
+ testSetEnv(t, "AUTHENTICATION_BACKEND_LDAP_PASSWORD", "abc")
+
+ val := schema.NewStructValidator()
+ _, config, err := Load(val, NewDefaultSources([]string{"./test_resources/config.yml"}, DefaultEnvPrefix, DefaultEnvDelimiter)...)
+
+ assert.NoError(t, err)
+ assert.Len(t, val.Errors(), 0)
+ assert.Len(t, val.Warnings(), 0)
+
+ require.NotNil(t, config.AuthenticationBackend.RefreshInterval)
+ assert.True(t, config.AuthenticationBackend.RefreshInterval.Never())
+ assert.False(t, config.AuthenticationBackend.RefreshInterval.Always())
+}
+
func TestShouldParseLargeIntegerDurations(t *testing.T) {
val := schema.NewStructValidator()
_, config, err := Load(val, NewDefaultSources([]string{"./test_resources/config.durations.yml"}, DefaultEnvPrefix, DefaultEnvDelimiter)...)
@@ -96,6 +114,11 @@ func TestShouldParseLargeIntegerDurations(t *testing.T) {
assert.Equal(t, durationMax, config.Regulation.FindTime)
assert.Equal(t, time.Second*1000, config.Regulation.BanTime)
+
+ require.NotNil(t, config.AuthenticationBackend.RefreshInterval)
+ assert.Equal(t, false, config.AuthenticationBackend.RefreshInterval.Always())
+ assert.Equal(t, false, config.AuthenticationBackend.RefreshInterval.Never())
+ assert.Equal(t, time.Minute*5, config.AuthenticationBackend.RefreshInterval.Value())
}
func TestShouldValidateConfigurationWithEnv(t *testing.T) {
@@ -671,6 +694,41 @@ func TestShouldDecodeSMTPSenderWithName(t *testing.T) {
assert.Equal(t, schema.RememberMeDisabled, config.Session.RememberMe)
}
+func TestShouldConfigureRefreshIntervalAlways(t *testing.T) {
+ val := schema.NewStructValidator()
+ keys, config, err := Load(val, NewDefaultSources([]string{"./test_resources/config_alt.yml"}, DefaultEnvPrefix, DefaultEnvDelimiter)...)
+
+ assert.NoError(t, err)
+
+ validator.ValidateKeys(keys, DefaultEnvPrefix, val)
+
+ assert.Len(t, val.Errors(), 0)
+ assert.Len(t, val.Warnings(), 0)
+
+ require.NotNil(t, config.AuthenticationBackend.RefreshInterval)
+ assert.False(t, config.AuthenticationBackend.RefreshInterval.Never())
+ assert.True(t, config.AuthenticationBackend.RefreshInterval.Always())
+}
+
+func TestShouldConfigureRefreshIntervalDefault(t *testing.T) {
+ val := schema.NewStructValidator()
+ keys, config, err := Load(val, NewDefaultSources([]string{"./test_resources/config.no-refresh.yml"}, DefaultEnvPrefix, DefaultEnvDelimiter)...)
+
+ assert.NoError(t, err)
+
+ validator.ValidateKeys(keys, DefaultEnvPrefix, val)
+
+ assert.Len(t, val.Errors(), 0)
+ assert.Len(t, val.Warnings(), 0)
+
+ validator.ValidateAuthenticationBackend(&config.AuthenticationBackend, val)
+
+ require.NotNil(t, config.AuthenticationBackend.RefreshInterval)
+ assert.False(t, config.AuthenticationBackend.RefreshInterval.Always())
+ assert.False(t, config.AuthenticationBackend.RefreshInterval.Never())
+ assert.Equal(t, time.Minute*5, config.AuthenticationBackend.RefreshInterval.Value())
+}
+
func TestShouldParseRegex(t *testing.T) {
val := schema.NewStructValidator()
keys, config, err := Load(val, NewDefaultSources([]string{"./test_resources/config_domain_regex.yml"}, DefaultEnvPrefix, DefaultEnvDelimiter)...)