2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "resources/aws/aws_iam_role"
|
2017-12-14 03:34:52 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws"
|
|
|
|
require "resources/aws/aws_iam_role"
|
2019-05-21 00:19:38 +00:00
|
|
|
|
2017-12-14 03:34:52 +00:00
|
|
|
# MIRB = MockIamRoleBackend
|
|
|
|
# Abbreviation not used outside this file
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Constructor Tests
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsIamRoleConstructorTest < Minitest::Test
|
|
|
|
def setup
|
|
|
|
AwsIamRole::BackendFactory.select(AwsMIRB::Basic)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_some_args_required
|
|
|
|
assert_raises(ArgumentError) { AwsIamRole.new }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_accepts_scalar_role_name
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsIamRole.new("alpha")
|
2017-12-14 03:34:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_accepts_role_name_as_hash
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsIamRole.new(role_name: "alpha")
|
2017-12-14 03:34:52 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
2017-12-14 03:34:52 +00:00
|
|
|
def test_constructor_rejects_unrecognized_resource_params
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_raises(ArgumentError) { AwsIamRole.new(beep: "boop") }
|
2017-12-14 03:34:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Search / Recall
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsIamRoleRecallTest < Minitest::Test
|
|
|
|
# No setup here - each test needs to explicitly declare
|
|
|
|
# what they want from the backend.
|
|
|
|
|
|
|
|
def test_recall_no_match_is_no_exception
|
|
|
|
AwsIamRole::BackendFactory.select(AwsMIRB::Miss)
|
2019-06-11 22:24:35 +00:00
|
|
|
refute AwsIamRole.new("nonesuch").exists?
|
2017-12-14 03:34:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_recall_match_single_result_works
|
|
|
|
AwsIamRole::BackendFactory.select(AwsMIRB::Basic)
|
2019-06-11 22:24:35 +00:00
|
|
|
assert AwsIamRole.new("alpha").exists?
|
2017-12-14 03:34:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Properties
|
|
|
|
#=============================================================================#
|
|
|
|
|
|
|
|
class AwsIamRolePropertiesTest < Minitest::Test
|
|
|
|
def setup
|
|
|
|
AwsIamRole::BackendFactory.select(AwsMIRB::Basic)
|
|
|
|
end
|
|
|
|
|
|
|
|
#---------------------------------------
|
|
|
|
# description
|
|
|
|
#---------------------------------------
|
|
|
|
def test_property_description
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal("alpha role", AwsIamRole.new("alpha").description)
|
2017-12-14 03:34:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_prop_conf_sub_count_zero
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_empty(AwsIamRole.new("beta").description)
|
2017-12-14 03:34:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Test Fixtures
|
|
|
|
#=============================================================================#
|
|
|
|
module AwsMIRB
|
2018-02-08 04:26:37 +00:00
|
|
|
class Miss < AwsBackendBase
|
2017-12-14 03:34:52 +00:00
|
|
|
def get_role(query)
|
2019-06-11 22:24:35 +00:00
|
|
|
raise Aws::IAM::Errors::NoSuchEntity.new("Nope", "Nope")
|
2017-12-14 03:34:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
class Basic < AwsBackendBase
|
2017-12-14 03:34:52 +00:00
|
|
|
def get_role(query)
|
|
|
|
fixtures = {
|
2019-06-11 22:24:35 +00:00
|
|
|
"alpha" => OpenStruct.new({
|
|
|
|
role_name: "alpha",
|
|
|
|
description: "alpha role",
|
2017-12-14 03:34:52 +00:00
|
|
|
}),
|
2019-06-11 22:24:35 +00:00
|
|
|
"beta" => OpenStruct.new({
|
|
|
|
role_name: "beta",
|
|
|
|
description: "",
|
2017-12-14 03:34:52 +00:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
unless fixtures.key?(query[:role_name])
|
2019-06-11 22:24:35 +00:00
|
|
|
raise Aws::IAM::Errors::NoSuchEntity.new("Nope", "Nope")
|
2017-12-14 03:34:52 +00:00
|
|
|
end
|
2019-07-09 00:20:30 +00:00
|
|
|
|
2017-12-14 03:34:52 +00:00
|
|
|
OpenStruct.new({
|
2019-06-11 22:24:35 +00:00
|
|
|
role: fixtures[query[:role_name]],
|
2017-12-14 03:34:52 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2019-05-21 00:19:38 +00:00
|
|
|
end
|