2017-12-14 03:36:23 +00:00
|
|
|
require 'helper'
|
|
|
|
|
2019-05-21 00:19:38 +00:00
|
|
|
require 'resource_support/aws'
|
|
|
|
require 'resources/aws/aws_security_groups'
|
|
|
|
|
2018-02-08 04:23:05 +00:00
|
|
|
# MESGB = MockSecurityGroupBackend
|
2017-12-14 03:36:23 +00:00
|
|
|
# Abbreviation not used outside this file
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Constructor Tests
|
|
|
|
#=============================================================================#
|
2018-02-08 04:23:05 +00:00
|
|
|
class AwsSGConstructor < Minitest::Test
|
2017-12-14 03:36:23 +00:00
|
|
|
def setup
|
2018-02-08 04:23:05 +00:00
|
|
|
AwsSecurityGroups::BackendFactory.select(AwsMESGB::Empty)
|
2017-12-14 03:36:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_no_args_ok
|
2018-02-08 04:23:05 +00:00
|
|
|
AwsSecurityGroups.new
|
2017-12-14 03:36:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_reject_unknown_resource_params
|
2018-02-08 04:23:05 +00:00
|
|
|
assert_raises(ArgumentError) { AwsSecurityGroups.new(beep: 'boop') }
|
2017-12-14 03:36:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Filter Criteria
|
|
|
|
#=============================================================================#
|
2018-02-08 04:23:05 +00:00
|
|
|
class AwsSGFilterCriteria < Minitest::Test
|
2017-12-14 03:36:23 +00:00
|
|
|
def setup
|
2018-02-08 04:23:05 +00:00
|
|
|
AwsSecurityGroups::BackendFactory.select(AwsMESGB::Basic)
|
2017-12-14 03:36:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter_vpc_id
|
2018-02-08 04:23:05 +00:00
|
|
|
hit = AwsSecurityGroups.new.where(vpc_id: 'vpc-12345678')
|
2017-12-14 03:36:23 +00:00
|
|
|
assert(hit.exists?)
|
|
|
|
|
2018-02-08 04:23:05 +00:00
|
|
|
miss = AwsSecurityGroups.new.where(vpc_id: 'vpc-87654321')
|
2017-12-14 03:36:23 +00:00
|
|
|
refute(miss.exists?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter_group_name
|
2018-02-08 04:23:05 +00:00
|
|
|
hit = AwsSecurityGroups.new.where(group_name: 'alpha')
|
2017-12-14 03:36:23 +00:00
|
|
|
assert(hit.exists?)
|
|
|
|
|
2018-02-08 04:23:05 +00:00
|
|
|
miss = AwsSecurityGroups.new.where(group_name: 'nonesuch')
|
2017-12-14 03:36:23 +00:00
|
|
|
refute(miss.exists?)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Properties
|
|
|
|
#=============================================================================#
|
2018-02-08 04:23:05 +00:00
|
|
|
class AwsSGProperties < Minitest::Test
|
2017-12-14 03:36:23 +00:00
|
|
|
def setup
|
2018-02-08 04:23:05 +00:00
|
|
|
AwsSecurityGroups::BackendFactory.select(AwsMESGB::Basic)
|
2017-12-14 03:36:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_group_ids
|
2018-02-08 04:23:05 +00:00
|
|
|
basic = AwsSecurityGroups.new
|
2017-12-14 03:36:23 +00:00
|
|
|
assert_kind_of(Array, basic.group_ids)
|
|
|
|
assert(basic.group_ids.include?('sg-aaaabbbb'))
|
|
|
|
refute(basic.group_ids.include?(nil))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Test Fixtures
|
|
|
|
#=============================================================================#
|
|
|
|
|
|
|
|
module AwsMESGB
|
2018-02-08 04:26:37 +00:00
|
|
|
class Empty < AwsBackendBase
|
2017-12-14 03:36:23 +00:00
|
|
|
def describe_security_groups(_query)
|
|
|
|
OpenStruct.new({
|
|
|
|
security_groups: [],
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
class Basic < AwsBackendBase
|
2017-12-14 03:36:23 +00:00
|
|
|
def describe_security_groups(query)
|
|
|
|
fixtures = [
|
|
|
|
OpenStruct.new({
|
|
|
|
group_id: 'sg-aaaabbbb',
|
|
|
|
group_name: 'alpha',
|
|
|
|
vpc_id: 'vpc-aaaabbbb',
|
|
|
|
}),
|
|
|
|
OpenStruct.new({
|
|
|
|
group_id: 'sg-12345678',
|
|
|
|
group_name: 'beta',
|
|
|
|
vpc_id: 'vpc-12345678',
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
|
|
|
|
selected = fixtures.select do |sg|
|
|
|
|
query.keys.all? do |criterion|
|
|
|
|
query[criterion] == sg[criterion]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
OpenStruct.new({ security_groups: selected })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|