encryption_test.go 583 B

123456789101112131415161718192021222324252627
  1. package util
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. )
  6. func TestEncryption(t *testing.T) {
  7. Convey("When getting encryption key", t, func() {
  8. key := encryptionKeyToBytes("secret", "salt")
  9. So(len(key), ShouldEqual, 32)
  10. key = encryptionKeyToBytes("a very long secret key that is larger then 32bytes", "salt")
  11. So(len(key), ShouldEqual, 32)
  12. })
  13. Convey("When decrypting basic payload", t, func() {
  14. encrypted := Encrypt([]byte("grafana"), "1234")
  15. decrypted := Decrypt(encrypted, "1234")
  16. So(string(decrypted), ShouldEqual, "grafana")
  17. })
  18. }