frostfs-node/pkg/services/session/storage/persistent/encryption_test.go
Pavel Karpy 016eaa25f3 [#1255] node/session: Add encryption tests
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2022-03-29 09:35:10 +03:00

29 lines
674 B
Go

package persistent
import (
"bytes"
"path/filepath"
"testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/stretchr/testify/require"
)
func TestTokenStore_Encryption(t *testing.T) {
pk, err := keys.NewPrivateKey()
require.NoError(t, err)
ts, err := NewTokenStore(filepath.Join(t.TempDir(), ".storage"), WithEncryptionKey(&pk.PrivateKey))
require.NoError(t, err)
data := []byte("nice encryption, awesome tests")
encryptedData, err := ts.encrypt(data)
require.NoError(t, err)
require.False(t, bytes.Equal(data, encryptedData))
decryptedData, err := ts.decrypt(encryptedData)
require.NoError(t, err)
require.Equal(t, data, decryptedData)
}