Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
s12v committed Dec 9, 2018
1 parent 96cfbba commit 0f487a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions provider/awskms/awskms.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ func (p *KmsProvider) Match(val string) bool {
func (p *KmsProvider) Decode(val string) (string, error) {
blob, err := base64.StdEncoding.DecodeString(val[len(prefix):])
if err != nil {
return val, err
return "", err
}

input := &kms.DecryptInput{CiphertextBlob: blob}
if err = input.Validate(); err != nil {
return val, nil
return "", err
}

if output, err := decrypt(p.awsKmsClient, input); err != nil {
return val, err
return "", err
} else {
return string(output.Plaintext), nil
}
Expand Down
7 changes: 7 additions & 0 deletions provider/awskms/awskms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ func TestKmsProvider_Decode(t *testing.T) {
t.Fatalf("unexpected plaintext %v", r)
}
}

func TestKmsProvider_DecodeInvalid(t *testing.T) {
kmsProvider := KmsProvider{}
if _, err := kmsProvider.Decode("{aws-kms}"); err == nil {
t.Fatal("expected an error")
}
}

0 comments on commit 0f487a1

Please sign in to comment.