mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 16:52:36 +08:00
add encryption util functions
This commit is contained in:
28
pkg/util/encryption_test.go
Normal file
28
pkg/util/encryption_test.go
Normal file
@ -0,0 +1,28 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestEncryption(t *testing.T) {
|
||||
|
||||
Convey("When getting encryption key", t, func() {
|
||||
|
||||
key := encryptionKeyToBytes("secret")
|
||||
So(len(key), ShouldEqual, 32)
|
||||
|
||||
key = encryptionKeyToBytes("a very long secret key that is larger then 32bytes")
|
||||
So(len(key), ShouldEqual, 32)
|
||||
|
||||
})
|
||||
|
||||
Convey("When decrypting basic payload", t, func() {
|
||||
encrypted := Encrypt([]byte("grafana"), "1234")
|
||||
decrypted := Decrypt(encrypted, "1234")
|
||||
|
||||
So(string(decrypted), ShouldEqual, "grafana")
|
||||
})
|
||||
|
||||
}
|
Reference in New Issue
Block a user