2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "resources/aws/aws_iam_group"
|
2018-02-01 20:55:54 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws"
|
|
|
|
require "resources/aws/aws_iam_group"
|
2019-05-21 00:19:38 +00:00
|
|
|
|
2018-02-01 20:55:54 +00:00
|
|
|
# MAIGSB = MockAwsIamGroupSingularBackend
|
|
|
|
# Abbreviation not used outside this file
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Constructor Tests
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsIamGroupConstructorTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsIamGroup::BackendFactory.select(MAIGSB::Empty)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rejects_empty_params
|
|
|
|
assert_raises(ArgumentError) { AwsIamGroup.new }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_accepts_group_name_as_scalar
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsIamGroup.new("Whatever")
|
2018-02-01 20:55:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_accepts_group_name_as_hash
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsIamGroup.new(group_name: "Whatever")
|
2018-02-01 20:55:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rejects_unrecognized_params
|
|
|
|
assert_raises(ArgumentError) { AwsIamGroup.new(shoe_size: 9) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Search / Recall
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsIamGroupRecallTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsIamGroup::BackendFactory.select(MAIGSB::Basic)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_hit_via_scalar_works
|
2019-06-11 22:24:35 +00:00
|
|
|
assert AwsIamGroup.new("Administrator").exists?
|
2018-02-01 20:55:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_hit_via_hash_works
|
2019-06-11 22:24:35 +00:00
|
|
|
assert AwsIamGroup.new(group_name: "Administrator").exists?
|
2018-02-01 20:55:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_miss_is_not_an_exception
|
2019-06-11 22:24:35 +00:00
|
|
|
refute AwsIamGroup.new(group_name: "Whatever").exists?
|
2018-02-01 20:55:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-06 18:04:13 +00:00
|
|
|
#=============================================================================#
|
|
|
|
# Properties
|
|
|
|
#=============================================================================#
|
2019-01-21 21:05:46 +00:00
|
|
|
class AwsIamGroupPropertiesTest < Minitest::Test
|
2018-04-06 18:04:13 +00:00
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsIamGroup::BackendFactory.select(MAIGSB::Basic)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_users
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal(%w{user1 user2}, AwsIamGroup.new("Administrator").users)
|
|
|
|
assert_nil(AwsIamGroup.new("nonexistent").users)
|
2018-04-06 18:04:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-01 20:55:54 +00:00
|
|
|
#=============================================================================#
|
|
|
|
# Test Fixtures
|
|
|
|
#=============================================================================#
|
|
|
|
module MAIGSB
|
2018-02-08 04:26:37 +00:00
|
|
|
class Empty < AwsBackendBase
|
2018-02-01 20:55:54 +00:00
|
|
|
def get_group(query = {})
|
2019-06-11 22:24:35 +00:00
|
|
|
raise Aws::IAM::Errors::NoSuchEntity.new(nil, nil)
|
2018-02-01 20:55:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
class Basic < AwsBackendBase
|
2018-02-01 20:55:54 +00:00
|
|
|
def get_group(query = {})
|
|
|
|
fixtures = [
|
|
|
|
OpenStruct.new({
|
2019-06-11 22:24:35 +00:00
|
|
|
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"),
|
2018-04-06 18:04:13 +00:00
|
|
|
users: [
|
|
|
|
OpenStruct.new({
|
2019-06-11 22:24:35 +00:00
|
|
|
user_name: "user1",
|
2018-04-06 18:04:13 +00:00
|
|
|
}),
|
|
|
|
OpenStruct.new({
|
2019-06-11 22:24:35 +00:00
|
|
|
user_name: "user2",
|
2018-04-06 18:04:13 +00:00
|
|
|
}),
|
2019-06-11 22:24:35 +00:00
|
|
|
],
|
2018-02-01 20:55:54 +00:00
|
|
|
}),
|
|
|
|
OpenStruct.new({
|
2019-06-11 22:24:35 +00:00
|
|
|
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"),
|
2018-02-01 20:55:54 +00:00
|
|
|
}),
|
|
|
|
]
|
|
|
|
|
|
|
|
selected = fixtures.select do |group|
|
|
|
|
group[:group_name].eql? query[:group_name]
|
|
|
|
end
|
|
|
|
|
|
|
|
if selected.empty?
|
2019-06-11 22:24:35 +00:00
|
|
|
raise Aws::IAM::Errors::NoSuchEntity.new(nil, nil)
|
2018-02-01 20:55:54 +00:00
|
|
|
end
|
|
|
|
|
2018-04-06 18:04:13 +00:00
|
|
|
OpenStruct.new({ group: selected[0], users: selected[0].users })
|
2018-02-01 20:55:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|