[ISSUE-39] - Cover Recommendation 1.12 (#49)

* Adding resource aws_iam_root_user

Signed-off-by: Miles Tjandrawidjaja <miles@tjandrawidjaja.com>

* Adding to_s method to class aws_iam_root_user

Signed-off-by: Miles Tjandrawidjaja <miles@tjandrawidjaja.com>

* Cleaner to_s result for aws_iam_root_user

Signed-off-by: Miles Tjandrawidjaja <miles@tjandrawidjaja.com>
This commit is contained in:
Miles Tjandrawidjaja 2017-06-13 01:44:11 -04:00 committed by Christoph Hartmann
parent 5c319ff056
commit a1dc5e981e
2 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,28 @@
# author: Miles Tjandrawidjaja
class AwsIamRootUser < Inspec.resource(1)
name 'aws_iam_root_user'
desc 'Verifies settings for AWS root account'
example "
describe aws_iam_root_user do
its('access_key_count') { should eq 0 }
end
"
def initialize(conn = AWSConnection.new)
@client = conn.iam_client
end
def access_key_count
summary_account['AccountAccessKeysPresent']
end
def to_s
'AWS Root-User'
end
private
def summary_account
@summary_account ||= @client.get_account_summary.summary_map
end
end

View file

@ -0,0 +1,20 @@
# author: Miles Tjandrawidjaja
require 'helper'
require 'aws_iam_root_user'
class AwsIamRootUserTest < Minitest::Test
def setup
@mockConn = Minitest::Mock.new
@mockClient = Minitest::Mock.new
@mockConn.expect :iam_client, @mockClient
end
def test_access_key_count_returns_from_summary_account
expectedKeys = 2
summaryMap = OpenStruct.new(summary_map: {'AccountAccessKeysPresent' => expectedKeys})
@mockClient.expect :get_account_summary, summaryMap
assert_equal expectedKeys, AwsIamRootUser.new(@mockConn).access_key_count
end
end