-
Notifications
You must be signed in to change notification settings - Fork 3
/
ejsonkms_test.go
56 lines (49 loc) · 1.6 KB
/
ejsonkms_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package ejsonkms
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
// type mockKMSClient struct {
// kmsiface.KMSAPI
// }
// func (m *mockKMSClient) Encrypt(input *kms.EncryptInput) (*kms.EncryptOutput, error) {
// output := &kms.EncryptOutput{
// CiphertextBlob: input.Plaintext,
// }
// return output, nil
// }
// func (m *mockKMSClient) Decrypt(input *kms.DecryptInput) (*kms.DecryptOutput, error) {
// output := &kms.DecryptOutput{
// Plaintext: input.CiphertextBlob,
// }
// return output, nil
// }
func TestKeygen(t *testing.T) {
Convey("Keygen", t, func() {
ejsonKmsKeys, err := Keygen("bc436485-5092-42b8-92a3-0aa8b93536dc", "us-east-1")
Convey("should return three strings that look key-like", func() {
So(err, ShouldBeNil)
So(ejsonKmsKeys.PublicKey, ShouldNotEqual, ejsonKmsKeys.PrivateKey)
So(ejsonKmsKeys.PublicKey, ShouldNotContainSubstring, "00000")
So(ejsonKmsKeys.PrivateKey, ShouldNotContainSubstring, "00000")
So(ejsonKmsKeys.PrivateKeyEnc, ShouldNotContainSubstring, "00000")
})
})
}
func TestDecrypt(t *testing.T) {
Convey("Decrypt", t, func() {
decrypted, err := Decrypt("testdata/test.ejson", "us-east-1")
Convey("should return decrypted values", func() {
So(err, ShouldBeNil)
json := string(decrypted[:])
So(json, ShouldContainSubstring, `"my_secret": "secret123"`)
})
})
Convey("Decrypt with no private key", t, func() {
_, err := Decrypt("testdata/test_no_private_key.ejson", "us-east-1")
Convey("should fail", func() {
So(err, ShouldNotBeNil)
So(err.Error(), ShouldContainSubstring, "missing _private_key_enc")
})
})
}