fix(configuration): cannot disable remember me (#2985)
This allows users to disable remember me again.pull/2987/head^2
parent
f439b85141
commit
db6dd32151
|
@ -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
|
||||
|
||||
##
|
||||
|
|
|
@ -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
|
||||
|
||||
##
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue