2019-04-24 21:52:08 +00:00
|
|
|
package session
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-12-24 02:14:52 +00:00
|
|
|
"github.com/authelia/authelia/internal/authentication"
|
2019-04-24 21:52:08 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
|
2019-12-24 02:14:52 +00:00
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
2019-04-24 21:52:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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, _ := provider.GetSession(ctx)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
_ = provider.SaveSession(ctx, session)
|
|
|
|
|
|
|
|
session, _ = provider.GetSession(ctx)
|
|
|
|
|
|
|
|
assert.Equal(t, UserSession{
|
|
|
|
Username: "john",
|
|
|
|
AuthenticationLevel: authentication.TwoFactor,
|
|
|
|
}, session)
|
|
|
|
}
|