From 016eaa25f304cec435db047c4929938d92e3cba4 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 21 Mar 2022 14:54:28 +0300 Subject: [PATCH] [#1255] node/session: Add encryption tests Signed-off-by: Pavel Karpy --- .../storage/persistent/encryption_test.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 pkg/services/session/storage/persistent/encryption_test.go diff --git a/pkg/services/session/storage/persistent/encryption_test.go b/pkg/services/session/storage/persistent/encryption_test.go new file mode 100644 index 000000000..642fa4007 --- /dev/null +++ b/pkg/services/session/storage/persistent/encryption_test.go @@ -0,0 +1,29 @@ +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) +}