mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 13:39:19 -06:00
62689ec804
* Add secrets service * Revert accidental changes in util encryption * Make minor changes Move functional options to models Revert renaming types to models * Add context * Minor change in GetDataKey * Use CreateDataKeyWithDBSession in CreateDataKey * Handle empty DEK name in DeleteDataKey * Rename defaultProvider * Remove secrets store service
38 lines
923 B
Go
38 lines
923 B
Go
package util
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestEncryption(t *testing.T) {
|
|
t.Run("getting encryption key", func(t *testing.T) {
|
|
key, err := encryptionKeyToBytes("secret", "salt")
|
|
require.NoError(t, err)
|
|
assert.Len(t, key, 32)
|
|
|
|
key, err = encryptionKeyToBytes("a very long secret key that is larger then 32bytes", "salt")
|
|
require.NoError(t, err)
|
|
assert.Len(t, key, 32)
|
|
})
|
|
|
|
t.Run("decrypting basic payload", func(t *testing.T) {
|
|
encrypted, err := Encrypt([]byte("grafana"), "1234")
|
|
require.NoError(t, err)
|
|
|
|
decrypted, err := Decrypt(encrypted, "1234")
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, []byte("grafana"), decrypted)
|
|
})
|
|
|
|
t.Run("decrypting empty payload should fail", func(t *testing.T) {
|
|
_, err := Decrypt([]byte(""), "1234")
|
|
require.Error(t, err)
|
|
|
|
assert.Equal(t, "unable to compute salt", err.Error())
|
|
})
|
|
}
|