Skip to content

Commit

Permalink
Generate fake keys for testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmorgan committed Apr 8, 2024
1 parent e539451 commit 9e55a54
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ I was hoping to hack together some sort of reflection technique to auto-generate
aws s3 rm PATH # delete a PATH

aws sts decode-authorization-message MESSAGE # Decode an authorization MESSAGE
aws sts generate-fake-key # Generate fake keys for testing
aws sts get-access-key-info # Get info about access keys
aws sts get-caller-identity # Get current users details

Expand Down
17 changes: 17 additions & 0 deletions lib/awscli_sts.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'aws-sdk-core'
require 'securerandom'

require 'awscli_subcommand'

Expand Down Expand Up @@ -60,5 +61,21 @@ def get_access_key_info(key)
warn e.message
exit 1
end

desc 'generate-fake-key', 'Generate fake keys for testing'
# aws sts generate-fake-key
def generate_fake_key
resp = {
access_key: {
access_key_id: "AKIA#{Array.new(16) { [*'A'..'Z', *'2'..'7'].sample }.join}",
create_date: Time.new,
secret_access_key: SecureRandom.base64(30),
status: 'Active',
user_name: ENV.fetch('USER', 'awsrubycli')
}
}

puts JSON.pretty_generate(resp.to_h)
end
end
end
5 changes: 5 additions & 0 deletions spec/lib/awscli/sts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,10 @@
.to output(/account/).to_stdout
expect(sts_client).to have_received(:get_access_key_info).with({ access_key_id: 'AKIA1234567890ABCDEF' })
end

it 'calls generate_fake_key' do
expect { described_class.start(%w[generate_fake_key]) }
.to output(/AKIA[A-Z234567]{16}/).to_stdout
end
end
end

0 comments on commit 9e55a54

Please sign in to comment.