mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
8aade7f40e
* added regulation validator * made regulations find_time and ban_time values duration notation strings * added DefaultRegulationConfiguration for the validator * made session expiration and inactivity values duration notation strings * TOTP period does not need to be converted because adjustment should be discouraged * moved TOTP defaults to DefaultTOTPConfiguration and removed the consts * arranged the root config validator in configuration file order * adjusted tests for the changes * moved duration notation docs to root of configuration * added references to duration notation where applicable * project wide gofmt and goimports: * run gofmt * run goimports -local github.com/authelia/authelia -w on all files * Make jwt_secret error uniform and add tests * now at 100% coverage for internal/configuration/validator/configuration.go
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
package session
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/valyala/fasthttp"
|
|
|
|
"github.com/authelia/authelia/internal/authentication"
|
|
"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)
|
|
}
|