Skip to content

Instantly share code, notes, and snippets.

@atomaka
Created April 10, 2020 13:53
Show Gist options
  • Save atomaka/65207d3a57e149bfd4fc4495ff8d4cc1 to your computer and use it in GitHub Desktop.
Save atomaka/65207d3a57e149bfd4fc4495ff8d4cc1 to your computer and use it in GitHub Desktop.
# 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