2018-02-01 03:45:02 +00:00
|
|
|
require 'helper'
|
2019-05-25 08:33:26 +00:00
|
|
|
require 'inspec/resource'
|
|
|
|
require 'resources/aws/aws_iam_policies'
|
2018-02-01 03:45:02 +00:00
|
|
|
|
2019-05-21 00:19:38 +00:00
|
|
|
require 'resource_support/aws'
|
|
|
|
require 'resources/aws/aws_iam_policies'
|
|
|
|
|
2018-02-01 03:45:02 +00:00
|
|
|
# MAIPPB = MockAwsIamPoliciesPluralBackend
|
|
|
|
# Abbreviation not used outside this file
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Constructor Tests
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsIamPoliciesConstructorTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsIamPolicies::BackendFactory.select(MAIPPB::Empty)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_empty_params_ok
|
|
|
|
AwsIamPolicies.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rejects_unrecognized_params
|
|
|
|
assert_raises(ArgumentError) { AwsIamPolicies.new(shoe_size: 9) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Search / Recall
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsIamPoliciesRecallEmptyTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsIamPolicies::BackendFactory.select(MAIPPB::Empty)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_miss_policy_empty_policy_list
|
|
|
|
refute AwsIamPolicies.new.exists?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class AwsIamPoliciesRecallBasicTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsIamPolicies::BackendFactory.select(MAIPPB::Basic)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_hit_via_empty_filter
|
|
|
|
assert AwsIamPolicies.new.exists?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Properties
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsIamPoliciesProperties < Minitest::Test
|
|
|
|
def setup
|
|
|
|
AwsIamPolicies::BackendFactory.select(MAIPPB::Basic)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_policy_names
|
|
|
|
basic = AwsIamPolicies.new
|
|
|
|
assert_kind_of(Array, basic.policy_names)
|
|
|
|
assert(basic.policy_names.include?('test-policy-1'))
|
|
|
|
refute(basic.policy_names.include?(nil))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_arns
|
|
|
|
basic = AwsIamPolicies.new
|
|
|
|
assert_kind_of(Array, basic.arns)
|
|
|
|
assert(basic.arns.include?('arn:aws:iam::aws:policy/test-policy-1'))
|
|
|
|
refute(basic.arns.include?(nil))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
#=============================================================================#
|
|
|
|
# Test Fixtures
|
|
|
|
#=============================================================================#
|
|
|
|
module MAIPPB
|
2018-02-08 04:26:37 +00:00
|
|
|
class Empty < AwsBackendBase
|
2018-02-01 03:45:02 +00:00
|
|
|
def list_policies(query = {})
|
|
|
|
OpenStruct.new({ policies: [] })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
class Basic < AwsBackendBase
|
2018-02-01 03:45:02 +00:00
|
|
|
def list_policies(query = {})
|
|
|
|
fixtures = [
|
|
|
|
OpenStruct.new({
|
|
|
|
policy_name: 'test-policy-1',
|
|
|
|
arn: 'arn:aws:iam::aws:policy/test-policy-1',
|
|
|
|
default_version_id: 'v1',
|
|
|
|
attachment_count: 3,
|
|
|
|
is_attachable: true,
|
|
|
|
}),
|
|
|
|
OpenStruct.new({
|
|
|
|
policy_name: 'test-policy-2',
|
|
|
|
arn: 'arn:aws:iam::aws:policy/test-policy-2',
|
|
|
|
default_version_id: 'v2',
|
|
|
|
attachment_count: 0,
|
|
|
|
is_attachable: false,
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
|
|
|
|
OpenStruct.new({ policies: fixtures })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|