2018-02-01 18:09:48 +00:00
|
|
|
require 'helper'
|
2019-05-25 08:33:26 +00:00
|
|
|
require 'inspec/resource'
|
|
|
|
require 'resources/aws/aws_iam_groups'
|
2018-02-01 18:09:48 +00:00
|
|
|
|
2019-05-21 00:19:38 +00:00
|
|
|
require 'resource_support/aws'
|
|
|
|
require 'resources/aws/aws_iam_groups'
|
|
|
|
|
2018-02-01 18:09:48 +00:00
|
|
|
# MAIGPB = MockAwsIamGroupsPluralBackend
|
|
|
|
# Abbreviation not used outside this file
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Constructor Tests
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsIamGroupsConstructorTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsIamGroups::BackendFactory.select(MAIGPB::Empty)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_empty_params_ok
|
|
|
|
AwsIamGroups.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rejects_unrecognized_params
|
|
|
|
assert_raises(ArgumentError) { AwsIamGroups.new(shoe_size: 9) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Search / Recall
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsIamGroupsRecallEmptyTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsIamGroups::BackendFactory.select(MAIGPB::Empty)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_miss_via_empty_groups
|
2018-06-06 02:35:09 +00:00
|
|
|
refute AwsIamGroups.new.exist?
|
2018-02-01 18:09:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class AwsIamGroupsRecallBasicTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsIamGroups::BackendFactory.select(MAIGPB::Basic)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_hit_via_empty_query
|
2018-06-06 02:35:09 +00:00
|
|
|
assert AwsIamGroups.new.exist?
|
2018-02-01 18:09:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Test Fixtures
|
|
|
|
#=============================================================================#
|
|
|
|
module MAIGPB
|
2018-02-08 04:26:37 +00:00
|
|
|
class Empty < AwsBackendBase
|
2018-02-01 18:09:48 +00:00
|
|
|
def list_groups(query = {})
|
|
|
|
OpenStruct.new({ groups: [] })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
class Basic < AwsBackendBase
|
2018-02-01 18:09:48 +00:00
|
|
|
def list_groups(query = {})
|
|
|
|
fixtures = [
|
|
|
|
OpenStruct.new({
|
|
|
|
path: '/',
|
|
|
|
group_name: 'Administrator',
|
|
|
|
group_id: 'AGPAQWERQWERQWERQWERQ',
|
|
|
|
arn: 'arn:aws:iam::111111111111:group/Administrator',
|
|
|
|
create_date: DateTime.parse('2017-12-14 05:29:57 UTC')
|
|
|
|
}),
|
|
|
|
OpenStruct.new({
|
|
|
|
path: '/',
|
|
|
|
group_name: 'AmazonEC2ReadOnlyAccess',
|
|
|
|
group_id: 'AGPAASDFASDFASDFASDFA',
|
|
|
|
arn: 'arn:aws:iam::111111111111:group/AmazonEC2ReadOnlyAccess',
|
|
|
|
create_date: DateTime.parse('2017-12-15 17:37:14 UTC')
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
|
|
|
|
if query[:path_prefix].nil?
|
|
|
|
selected = fixtures
|
|
|
|
else
|
|
|
|
selected = fixtures.select do |group|
|
|
|
|
group[:path].start_with? query[:path_prefix]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
OpenStruct.new({ groups: selected })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|