encryption_test.go 667 B

1234567891011121314151617181920212223242526272829
  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, encryptErr := Encrypt([]byte("grafana"), "1234")
  15. decrypted, decryptErr := Decrypt(encrypted, "1234")
  16. So(encryptErr, ShouldBeNil)
  17. So(decryptErr, ShouldBeNil)
  18. So(string(decrypted), ShouldEqual, "grafana")
  19. })
  20. }