diff --git a/config.template.yml b/config.template.yml index 95c16da83..e03bbf241 100644 --- a/config.template.yml +++ b/config.template.yml @@ -461,7 +461,7 @@ session: inactivity: 5m ## The time before the cookie expires and the session is destroyed if remember me IS selected. - ## Value of 0 disables remember me. + ## Value of -1 disables remember me. remember_me_duration: 1M ## diff --git a/internal/configuration/config.template.yml b/internal/configuration/config.template.yml index 95c16da83..e03bbf241 100644 --- a/internal/configuration/config.template.yml +++ b/internal/configuration/config.template.yml @@ -461,7 +461,7 @@ session: inactivity: 5m ## The time before the cookie expires and the session is destroyed if remember me IS selected. - ## Value of 0 disables remember me. + ## Value of -1 disables remember me. remember_me_duration: 1M ## diff --git a/internal/configuration/validator/session.go b/internal/configuration/validator/session.go index 7286eb6a0..ddc076891 100644 --- a/internal/configuration/validator/session.go +++ b/internal/configuration/validator/session.go @@ -35,7 +35,7 @@ func validateSession(config *schema.SessionConfiguration, validator *schema.Stru config.Inactivity = schema.DefaultSessionConfiguration.Inactivity // 5 min. } - if config.RememberMeDuration <= 0 { + if config.RememberMeDuration <= 0 && config.RememberMeDuration != -1 { config.RememberMeDuration = schema.DefaultSessionConfiguration.RememberMeDuration // 1 month. } diff --git a/internal/configuration/validator/session_test.go b/internal/configuration/validator/session_test.go index 37588ae5f..b09f155a3 100644 --- a/internal/configuration/validator/session_test.go +++ b/internal/configuration/validator/session_test.go @@ -3,6 +3,7 @@ package validator import ( "fmt" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -37,12 +38,12 @@ func TestShouldSetDefaultSessionValuesWhenNegative(t *testing.T) { validator := schema.NewStructValidator() config := newDefaultSessionConfig() - config.Expiration, config.Inactivity, config.RememberMeDuration = -1, -1, -1 + config.Expiration, config.Inactivity, config.RememberMeDuration = -1, -1, -2 ValidateSession(&config, validator) - assert.False(t, validator.HasWarnings()) - assert.False(t, validator.HasErrors()) + assert.Len(t, validator.Warnings(), 0) + assert.Len(t, validator.Errors(), 0) assert.Equal(t, schema.DefaultSessionConfiguration.Inactivity, config.Inactivity) assert.Equal(t, schema.DefaultSessionConfiguration.Expiration, config.Expiration) assert.Equal(t, schema.DefaultSessionConfiguration.RememberMeDuration, config.RememberMeDuration) @@ -406,7 +407,7 @@ func TestShouldNotRaiseErrorWhenSameSiteSetCorrectly(t *testing.T) { } } -func TestShouldSetDefaultWhenNegativeInactivityAndExpirationSet(t *testing.T) { +func TestShouldSetDefaultWhenNegativeAndNotOverrideDisabledRememberMe(t *testing.T) { validator := schema.NewStructValidator() config := newDefaultSessionConfig() config.Inactivity = -1 @@ -420,7 +421,7 @@ func TestShouldSetDefaultWhenNegativeInactivityAndExpirationSet(t *testing.T) { assert.Equal(t, schema.DefaultSessionConfiguration.Inactivity, config.Inactivity) assert.Equal(t, schema.DefaultSessionConfiguration.Expiration, config.Expiration) - assert.Equal(t, schema.DefaultSessionConfiguration.RememberMeDuration, config.RememberMeDuration) + assert.Equal(t, time.Duration(-1), config.RememberMeDuration) } func TestShouldSetDefaultRememberMeDuration(t *testing.T) {