mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
2763aefe81
* [BUGFIX] Static Session Expiration Key * keys for session expiration are random for each instance of Authelia * this is caused by upstream setting it to a random value * using a temporary bugfix fork of github.com/fasthttp/session to resolve locally * add some misc doc additions
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package session
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/authelia/session/v2"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestShouldEncryptAndDecrypt(t *testing.T) {
|
|
payload := session.Dict{}
|
|
payload.Set("key", "value")
|
|
|
|
dst, err := payload.MarshalMsg(nil)
|
|
require.NoError(t, err)
|
|
|
|
serializer := NewEncryptingSerializer("asecret")
|
|
encryptedDst, err := serializer.Encode(payload)
|
|
require.NoError(t, err)
|
|
|
|
assert.NotEqual(t, dst, encryptedDst)
|
|
|
|
decodedPayload := session.Dict{}
|
|
err = serializer.Decode(&decodedPayload, encryptedDst)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "value", decodedPayload.Get("key"))
|
|
}
|
|
|
|
func TestShouldSupportUnencryptedSessionForBackwardCompatibility(t *testing.T) {
|
|
payload := session.Dict{}
|
|
payload.Set("key", "value")
|
|
|
|
dst, err := payload.MarshalMsg(nil)
|
|
require.NoError(t, err)
|
|
|
|
serializer := NewEncryptingSerializer("asecret")
|
|
|
|
decodedPayload := session.Dict{}
|
|
err = serializer.Decode(&decodedPayload, dst)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "value", decodedPayload.Get("key"))
|
|
}
|