encryption_test.go 568 B

12345678910111213141516171819202122232425262728
  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")
  9. So(len(key), ShouldEqual, 32)
  10. key = encryptionKeyToBytes("a very long secret key that is larger then 32bytes")
  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. }