fix(configuration): cannot disable remember me (#2985)

This allows users to disable remember me again.
pull/2987/head^2
James Elliott 2022-03-10 09:01:04 +11:00 committed by GitHub
parent f439b85141
commit db6dd32151
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 8 deletions

View File

@ -461,7 +461,7 @@ session:
inactivity: 5m inactivity: 5m
## The time before the cookie expires and the session is destroyed if remember me IS selected. ## 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 remember_me_duration: 1M
## ##

View File

@ -461,7 +461,7 @@ session:
inactivity: 5m inactivity: 5m
## The time before the cookie expires and the session is destroyed if remember me IS selected. ## 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 remember_me_duration: 1M
## ##

View File

@ -35,7 +35,7 @@ func validateSession(config *schema.SessionConfiguration, validator *schema.Stru
config.Inactivity = schema.DefaultSessionConfiguration.Inactivity // 5 min. 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. config.RememberMeDuration = schema.DefaultSessionConfiguration.RememberMeDuration // 1 month.
} }

View File

@ -3,6 +3,7 @@ package validator
import ( import (
"fmt" "fmt"
"testing" "testing"
"time"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -37,12 +38,12 @@ func TestShouldSetDefaultSessionValuesWhenNegative(t *testing.T) {
validator := schema.NewStructValidator() validator := schema.NewStructValidator()
config := newDefaultSessionConfig() config := newDefaultSessionConfig()
config.Expiration, config.Inactivity, config.RememberMeDuration = -1, -1, -1 config.Expiration, config.Inactivity, config.RememberMeDuration = -1, -1, -2
ValidateSession(&config, validator) ValidateSession(&config, validator)
assert.False(t, validator.HasWarnings()) assert.Len(t, validator.Warnings(), 0)
assert.False(t, validator.HasErrors()) assert.Len(t, validator.Errors(), 0)
assert.Equal(t, schema.DefaultSessionConfiguration.Inactivity, config.Inactivity) assert.Equal(t, schema.DefaultSessionConfiguration.Inactivity, config.Inactivity)
assert.Equal(t, schema.DefaultSessionConfiguration.Expiration, config.Expiration) assert.Equal(t, schema.DefaultSessionConfiguration.Expiration, config.Expiration)
assert.Equal(t, schema.DefaultSessionConfiguration.RememberMeDuration, config.RememberMeDuration) 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() validator := schema.NewStructValidator()
config := newDefaultSessionConfig() config := newDefaultSessionConfig()
config.Inactivity = -1 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.Inactivity, config.Inactivity)
assert.Equal(t, schema.DefaultSessionConfiguration.Expiration, config.Expiration) 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) { func TestShouldSetDefaultRememberMeDuration(t *testing.T) {