mirror of
https://github.com/inspec/inspec
synced 2024-11-10 23:24:18 +00:00
[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:
parent
5c319ff056
commit
a1dc5e981e
2 changed files with 48 additions and 0 deletions
28
libraries/aws_iam_root_user.rb
Normal file
28
libraries/aws_iam_root_user.rb
Normal 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
|
20
test/unit/resources/aws_iam_root_user_test.rb
Normal file
20
test/unit/resources/aws_iam_root_user_test.rb
Normal 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
|
Loading…
Reference in a new issue