mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
841de2b75d
Instead of checking the value of the cookie expiration we rely on the boolean stored in the user session to check whether inactivity timeout should be disabled.
85 lines
2.2 KiB
Go
85 lines
2.2 KiB
Go
package session
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/authelia/authelia/internal/authentication"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
|
)
|
|
|
|
func TestShouldInitializerSession(t *testing.T) {
|
|
ctx := &fasthttp.RequestCtx{}
|
|
configuration := schema.SessionConfiguration{}
|
|
configuration.Domain = "example.com"
|
|
configuration.Name = "my_session"
|
|
configuration.Expiration = 40
|
|
|
|
provider := NewProvider(configuration)
|
|
session, err := provider.GetSession(ctx)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, NewDefaultUserSession(), session)
|
|
}
|
|
|
|
func TestShouldUpdateSession(t *testing.T) {
|
|
ctx := &fasthttp.RequestCtx{}
|
|
configuration := schema.SessionConfiguration{}
|
|
configuration.Domain = "example.com"
|
|
configuration.Name = "my_session"
|
|
configuration.Expiration = 40
|
|
|
|
provider := NewProvider(configuration)
|
|
session, _ := provider.GetSession(ctx)
|
|
|
|
session.Username = "john"
|
|
session.AuthenticationLevel = authentication.TwoFactor
|
|
|
|
err := provider.SaveSession(ctx, session)
|
|
require.NoError(t, err)
|
|
|
|
session, err = provider.GetSession(ctx)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, UserSession{
|
|
Username: "john",
|
|
AuthenticationLevel: authentication.TwoFactor,
|
|
}, session)
|
|
}
|
|
|
|
func TestShouldDestroySessionAndWipeSessionData(t *testing.T) {
|
|
ctx := &fasthttp.RequestCtx{}
|
|
configuration := schema.SessionConfiguration{}
|
|
configuration.Domain = "example.com"
|
|
configuration.Name = "my_session"
|
|
configuration.Expiration = 40
|
|
|
|
provider := NewProvider(configuration)
|
|
session, err := provider.GetSession(ctx)
|
|
require.NoError(t, err)
|
|
|
|
session.Username = "john"
|
|
session.AuthenticationLevel = authentication.TwoFactor
|
|
|
|
err = provider.SaveSession(ctx, session)
|
|
require.NoError(t, err)
|
|
|
|
newUserSession, err := provider.GetSession(ctx)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "john", newUserSession.Username)
|
|
assert.Equal(t, authentication.TwoFactor, newUserSession.AuthenticationLevel)
|
|
|
|
err = provider.DestroySession(ctx)
|
|
require.NoError(t, err)
|
|
|
|
newUserSession, err = provider.GetSession(ctx)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "", newUserSession.Username)
|
|
assert.Equal(t, authentication.NotAuthenticated, newUserSession.AuthenticationLevel)
|
|
}
|