2016-01-22 13:15:39 -06:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncryption(t *testing.T) {
|
|
|
|
|
|
|
|
Convey("When getting encryption key", t, func() {
|
|
|
|
|
2019-10-23 03:40:12 -05:00
|
|
|
key, err := encryptionKeyToBytes("secret", "salt")
|
|
|
|
So(err, ShouldBeNil)
|
2016-01-22 13:15:39 -06:00
|
|
|
So(len(key), ShouldEqual, 32)
|
|
|
|
|
2019-10-23 03:40:12 -05:00
|
|
|
key, err = encryptionKeyToBytes("a very long secret key that is larger then 32bytes", "salt")
|
|
|
|
So(err, ShouldBeNil)
|
2016-01-22 13:15:39 -06:00
|
|
|
So(len(key), ShouldEqual, 32)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("When decrypting basic payload", t, func() {
|
2017-04-25 02:14:29 -05:00
|
|
|
encrypted, encryptErr := Encrypt([]byte("grafana"), "1234")
|
|
|
|
decrypted, decryptErr := Decrypt(encrypted, "1234")
|
2016-01-22 13:15:39 -06:00
|
|
|
|
2017-04-25 02:14:29 -05:00
|
|
|
So(encryptErr, ShouldBeNil)
|
|
|
|
So(decryptErr, ShouldBeNil)
|
2016-01-22 13:15:39 -06:00
|
|
|
So(string(decrypted), ShouldEqual, "grafana")
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|