diff options
| author | Janusz Bialy <janusz.bialy@qlik.com> | 2019-03-22 15:00:57 -0400 |
|---|---|---|
| committer | Janusz Bialy <janusz.bialy@qlik.com> | 2019-03-23 15:04:21 -0400 |
| commit | ca4f7a1330c12a49c042d6eba67383a21be883c3 (patch) | |
| tree | 21488a3e9f2b9d74e23f69caf71ba1f2bfcdf4cf /aws | |
| parent | 07f37d7f3c36ceee92c06b93111627d06e872664 (diff) | |
add tests
Diffstat (limited to 'aws')
| -rw-r--r-- | aws/kms_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/aws/kms_test.go b/aws/kms_test.go new file mode 100644 index 00000000..9475a4bf --- /dev/null +++ b/aws/kms_test.go @@ -0,0 +1,52 @@ +package aws + +import ( + "strings" + "testing" + + "github.com/aws/aws-sdk-go/service/kms" + b64 "github.com/hairyhenderson/gomplate/base64" + "github.com/stretchr/testify/assert" +) + +// MockKMS is a mock KMSAPI implementation +type MockKMS struct{} + +// Mocks Encrypt operation returns an upper case version of plaintext +func (m *MockKMS) Encrypt(input *kms.EncryptInput) (*kms.EncryptOutput, error) { + return &kms.EncryptOutput{ + CiphertextBlob: []byte(strings.ToUpper(string(input.Plaintext))), + }, nil +} + +// Mocks Decrypt operation +func (m *MockKMS) Decrypt(input *kms.DecryptInput) (*kms.DecryptOutput, error) { + s := []byte(strings.ToLower(string(input.CiphertextBlob))) + return &kms.DecryptOutput{ + Plaintext: s, + }, nil +} + +func TestEncrypt(t *testing.T) { + // create a mock KMS client + c := &MockKMS{} + kmsClient := &KMS{Client: c} + + // Success + resp, err := kmsClient.Encrypt("dummykey", "plaintextvalue") + assert.NoError(t, err) + expectedResp, _ := b64.Encode([]byte("PLAINTEXTVALUE")) + assert.EqualValues(t, expectedResp, resp) +} + +func TestDecrypt(t *testing.T) { + // create a mock KMS client + c := &MockKMS{} + kmsClient := &KMS{Client: c} + encodedCiphertextBlob, _ := b64.Encode([]byte("CIPHERVALUE")) + + // Success + resp, err := kmsClient.Decrypt(encodedCiphertextBlob) + assert.NoError(t, err) + assert.EqualValues(t, "ciphervalue", resp) +} |
