Created
April 10, 2020 13:53
-
-
Save atomaka/c273a647e3d2bdf9f888e5d87e4814d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'aws_kms_client' | |
# Client that interfaces with the AWS KMS API | |
class FakeKmsClient < AwsKmsClient | |
class << self | |
def iv | |
'o' * 12 | |
end | |
def key | |
'a' * 32 | |
end | |
def encrypted_kms_key_fixture | |
Base64.encode64([FakeKmsClient.key].pack('H*')) | |
end | |
end | |
def initialize(opts = {}) | |
@default_key_id = 'key' | |
@key_spec = 'AES-256' | |
@client = Aws::KMS::Client.new(stub_responses: stubs) | |
end | |
private | |
def stubs | |
{ | |
decrypt: { | |
key_id: fake_arn, | |
plaintext: FakeKmsClient.key, | |
encryption_algorithm: "SYMMETRIC_DEFAULT" | |
}, | |
generate_data_key: { | |
ciphertext_blob: FakeKmsClient.encrypted_kms_key_fixture, | |
plaintext: FakeKmsClient.key, | |
key_id: fake_arn | |
} | |
} | |
end | |
def fake_arn | |
'arn:aws:kms:us-east-1:000000000000:key/85d5c6c5-2360-4079-8258-b03141a03ff2' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment