grafana/pkg/util/encryption_test.go
Dan Cech b489e93d94 Config Array Syntax (#8204)
* refactor util encryption library so it doesn't have to import log

* add util.SplitString to handle space and/or comma-separated config lines

* go fmt
2017-04-25 09:14:29 +02:00

30 lines
667 B
Go

package util
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestEncryption(t *testing.T) {
Convey("When getting encryption key", t, func() {
key := encryptionKeyToBytes("secret", "salt")
So(len(key), ShouldEqual, 32)
key = encryptionKeyToBytes("a very long secret key that is larger then 32bytes", "salt")
So(len(key), ShouldEqual, 32)
})
Convey("When decrypting basic payload", t, func() {
encrypted, encryptErr := Encrypt([]byte("grafana"), "1234")
decrypted, decryptErr := Decrypt(encrypted, "1234")
So(encryptErr, ShouldBeNil)
So(decryptErr, ShouldBeNil)
So(string(decrypted), ShouldEqual, "grafana")
})
}