2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "resources/aws/aws_elbs"
|
2018-06-07 19:06:05 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws"
|
|
|
|
require "resources/aws/aws_elbs"
|
2019-05-21 00:19:38 +00:00
|
|
|
|
2018-06-07 19:06:05 +00:00
|
|
|
# MAEPB = MockAwsELBsPluralBackend
|
|
|
|
# Abbreviation not used outside this file
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Constructor Tests
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsElbsConstructorTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsElbs::BackendFactory.select(MAEPB::Empty)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_empty_params_ok
|
|
|
|
AwsElbs.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rejects_unrecognized_params
|
|
|
|
assert_raises(ArgumentError) { AwsElbs.new(shoe_size: 9) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Filter Criteria
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsElbsFilterCriteriaTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsElbs::BackendFactory.select(MAEPB::Basic)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter_with_no_criteria
|
|
|
|
assert AwsElbs.new.exists?
|
|
|
|
assert_equal(3, AwsElbs.new.count)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter_with_availability_zones
|
2019-06-11 22:24:35 +00:00
|
|
|
hit = AwsElbs.new.where { availability_zones.include? "us-east-1c" }
|
2018-06-07 19:06:05 +00:00
|
|
|
assert(hit.exists?)
|
|
|
|
assert_equal(2, hit.count)
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
miss = AwsElbs.new.where { availability_zones.include? "us-east-1g" }
|
2018-06-07 19:06:05 +00:00
|
|
|
refute(miss.exists?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter_with_dns_name
|
2019-06-11 22:24:35 +00:00
|
|
|
hit = AwsElbs.new.where(dns_name: /us-east-1\.aws/)
|
2018-06-07 19:06:05 +00:00
|
|
|
assert(hit.exists?)
|
|
|
|
assert_equal(2, hit.count)
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
miss = AwsElbs.new.where(dns_name: "bananas")
|
2018-06-07 19:06:05 +00:00
|
|
|
refute(miss.exists?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter_with_elb_name
|
2019-06-11 22:24:35 +00:00
|
|
|
hit = AwsElbs.new.where(elb_name: /kang/)
|
2018-06-07 19:06:05 +00:00
|
|
|
assert(hit.exists?)
|
|
|
|
assert_equal(2, hit.count)
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
miss = AwsElbs.new.where(elb_name: "kodos")
|
2018-06-07 19:06:05 +00:00
|
|
|
refute(miss.exists?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter_with_external_ports
|
|
|
|
hit = AwsElbs.new.where { external_ports.include? 631 }
|
|
|
|
assert(hit.exists?)
|
|
|
|
assert_equal(1, hit.count)
|
|
|
|
|
|
|
|
miss = AwsElbs.new.where { external_ports.include? 22000 }
|
|
|
|
refute(miss.exists?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter_with_instance_ids
|
2019-06-11 22:24:35 +00:00
|
|
|
hit = AwsElbs.new.where { instance_ids.include? "i-12345678" }
|
2018-06-07 19:06:05 +00:00
|
|
|
assert(hit.exists?)
|
|
|
|
assert_equal(1, hit.count)
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
miss = AwsElbs.new.where { instance_ids.include? "i-deadbeef" }
|
2018-06-07 19:06:05 +00:00
|
|
|
refute(miss.exists?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter_with_internal_ports
|
|
|
|
hit = AwsElbs.new.where { internal_ports.include? 80 }
|
|
|
|
assert(hit.exists?)
|
|
|
|
assert_equal(2, hit.count)
|
|
|
|
|
|
|
|
miss = AwsElbs.new.where { internal_ports.include? 93 }
|
|
|
|
refute(miss.exists?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter_with_security_group_ids
|
2019-06-11 22:24:35 +00:00
|
|
|
hit = AwsElbs.new.where { security_group_ids.include? "sg-12345678" }
|
2018-06-07 19:06:05 +00:00
|
|
|
assert(hit.exists?)
|
|
|
|
assert_equal(3, hit.count)
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
miss = AwsElbs.new.where { security_group_ids.include? "sg-99999999" }
|
2018-06-07 19:06:05 +00:00
|
|
|
refute(miss.exists?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter_with_subnet_ids
|
2019-06-11 22:24:35 +00:00
|
|
|
hit = AwsElbs.new.where { subnet_ids.include? "subnet-12345678" }
|
2018-06-07 19:06:05 +00:00
|
|
|
assert(hit.exists?)
|
|
|
|
assert_equal(2, hit.count)
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
miss = AwsElbs.new.where { subnet_ids.include? "subnet-99999999" }
|
2018-06-07 19:06:05 +00:00
|
|
|
refute(miss.exists?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter_with_vpc_id
|
2019-06-11 22:24:35 +00:00
|
|
|
hit = AwsElbs.new.where(vpc_id: "vpc-12345678")
|
2018-06-07 19:06:05 +00:00
|
|
|
assert(hit.exists?)
|
|
|
|
assert_equal(2, hit.count)
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
miss = AwsElbs.new.where(vpc_id: "vpc-09876543")
|
2018-06-07 19:06:05 +00:00
|
|
|
refute(miss.exists?)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Properties
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsElbsProperties < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsElbs::BackendFactory.select(MAEPB::Basic)
|
|
|
|
@elbs = AwsElbs.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_properties_with_availability_zones
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes(@elbs.availability_zones, "us-east-1a")
|
|
|
|
assert_includes(@elbs.availability_zones, "us-east-1e")
|
2018-06-07 19:06:05 +00:00
|
|
|
assert_equal(4, @elbs.availability_zones.count)
|
|
|
|
refute_includes(@elbs.availability_zones, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_properties_with_dns_names
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes(@elbs.dns_names, "999999.us-east-1.aws.amazon.com")
|
|
|
|
assert_includes(@elbs.dns_names, "12345678.us-east-2.aws.amazon.com")
|
2018-06-07 19:06:05 +00:00
|
|
|
assert_equal(3, @elbs.dns_names.count)
|
|
|
|
refute_includes(@elbs.dns_names, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_properties_with_elb_names
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes(@elbs.elb_names, "kang-the-alien")
|
|
|
|
assert_includes(@elbs.elb_names, "kangaroo")
|
2018-06-07 19:06:05 +00:00
|
|
|
assert_equal(3, @elbs.elb_names.count)
|
|
|
|
refute_includes(@elbs.elb_names, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_properties_with_external_ports
|
|
|
|
assert_includes(@elbs.external_ports, 80)
|
|
|
|
assert_includes(@elbs.external_ports, 631)
|
|
|
|
assert_equal(3, @elbs.external_ports.count)
|
|
|
|
refute_includes(@elbs.external_ports, nil)
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
2018-06-07 19:06:05 +00:00
|
|
|
def test_properties_with_instance_ids
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes(@elbs.instance_ids, "i-87654321")
|
|
|
|
assert_includes(@elbs.instance_ids, "i-12345678")
|
2018-06-07 19:06:05 +00:00
|
|
|
assert_equal(3, @elbs.instance_ids.count)
|
|
|
|
refute_includes(@elbs.instance_ids, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_properties_with_internal_ports
|
|
|
|
assert_includes(@elbs.internal_ports, 80)
|
|
|
|
assert_includes(@elbs.internal_ports, 1001)
|
|
|
|
assert_equal(2, @elbs.internal_ports.count)
|
|
|
|
refute_includes(@elbs.internal_ports, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_properties_with_security_group_ids
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes(@elbs.security_group_ids, "sg-12345678")
|
|
|
|
assert_includes(@elbs.security_group_ids, "sg-99998888")
|
2018-06-07 19:06:05 +00:00
|
|
|
assert_equal(4, @elbs.security_group_ids.count)
|
|
|
|
refute_includes(@elbs.security_group_ids, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_properties_with_subnet_ids
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes(@elbs.subnet_ids, "subnet-ccccdddd")
|
|
|
|
assert_includes(@elbs.subnet_ids, "subnet-12345678")
|
2018-06-07 19:06:05 +00:00
|
|
|
assert_equal(3, @elbs.subnet_ids.count)
|
|
|
|
refute_includes(@elbs.subnet_ids, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_vpc_ids
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes(@elbs.vpc_ids, "vpc-87654321")
|
|
|
|
assert_includes(@elbs.vpc_ids, "vpc-12345678")
|
|
|
|
assert_equal(2, @elbs.vpc_ids.count)
|
2018-06-07 19:06:05 +00:00
|
|
|
refute_includes(@elbs.vpc_ids, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
#=============================================================================#
|
|
|
|
# Test Fixtures
|
|
|
|
#=============================================================================#
|
|
|
|
module MAEPB
|
|
|
|
class Empty < AwsBackendBase
|
|
|
|
def describe_load_balancers(query = {})
|
|
|
|
Aws::ElasticLoadBalancing::Types::DescribeAccessPointsOutput.new(
|
|
|
|
load_balancer_descriptions: []
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Basic < AwsBackendBase
|
|
|
|
def describe_load_balancers(query = {})
|
|
|
|
Aws::ElasticLoadBalancing::Types::DescribeAccessPointsOutput.new(
|
|
|
|
load_balancer_descriptions: [
|
|
|
|
Aws::ElasticLoadBalancing::Types::LoadBalancerDescription.new(
|
2019-07-03 21:24:41 +00:00
|
|
|
availability_zones: %w{
|
|
|
|
us-east-1a
|
|
|
|
us-east-1c
|
|
|
|
},
|
2019-06-11 22:24:35 +00:00
|
|
|
dns_name: "12345678.us-east-1.aws.amazon.com",
|
|
|
|
load_balancer_name: "kang-the-alien",
|
2018-06-07 19:06:05 +00:00
|
|
|
listener_descriptions: [
|
|
|
|
Aws::ElasticLoadBalancing::Types::ListenerDescription.new(
|
|
|
|
listener: Aws::ElasticLoadBalancing::Types::Listener.new(
|
2019-06-11 22:24:35 +00:00
|
|
|
protocol: "http",
|
2018-06-07 19:06:05 +00:00
|
|
|
load_balancer_port: 80,
|
2019-06-11 22:24:35 +00:00
|
|
|
instance_protocol: "http",
|
|
|
|
instance_port: 80
|
2018-06-07 19:06:05 +00:00
|
|
|
)
|
2019-07-09 00:20:30 +00:00
|
|
|
),
|
2018-06-07 19:06:05 +00:00
|
|
|
],
|
|
|
|
instances: [
|
2019-06-11 22:24:35 +00:00
|
|
|
Aws::ElasticLoadBalancing::Types::Instance.new(instance_id: "i-12345678"),
|
|
|
|
Aws::ElasticLoadBalancing::Types::Instance.new(instance_id: "i-aaaabbbb"),
|
2018-06-07 19:06:05 +00:00
|
|
|
],
|
2019-07-03 21:24:41 +00:00
|
|
|
security_groups: %w{
|
|
|
|
sg-12345678
|
|
|
|
sg-aaaabbbb
|
|
|
|
sg-99998888
|
|
|
|
},
|
|
|
|
subnets: %w{
|
|
|
|
subnet-12345678
|
|
|
|
subnet-aaaabbbb
|
|
|
|
},
|
2019-06-11 22:24:35 +00:00
|
|
|
vpc_id: "vpc-12345678"
|
2018-06-07 19:06:05 +00:00
|
|
|
),
|
|
|
|
Aws::ElasticLoadBalancing::Types::LoadBalancerDescription.new(
|
2019-07-03 21:24:41 +00:00
|
|
|
availability_zones: %w{
|
|
|
|
us-east-1b
|
|
|
|
us-east-1c
|
|
|
|
},
|
2019-06-11 22:24:35 +00:00
|
|
|
dns_name: "12345678.us-east-2.aws.amazon.com",
|
|
|
|
load_balancer_name: "kangaroo",
|
2018-06-07 19:06:05 +00:00
|
|
|
listener_descriptions: [
|
|
|
|
Aws::ElasticLoadBalancing::Types::ListenerDescription.new(
|
|
|
|
listener: Aws::ElasticLoadBalancing::Types::Listener.new(
|
2019-06-11 22:24:35 +00:00
|
|
|
protocol: "tcp",
|
2018-06-07 19:06:05 +00:00
|
|
|
load_balancer_port: 1001,
|
2019-06-11 22:24:35 +00:00
|
|
|
instance_protocol: "tcp",
|
|
|
|
instance_port: 1001
|
2018-06-07 19:06:05 +00:00
|
|
|
)
|
2019-07-09 00:20:30 +00:00
|
|
|
),
|
2018-06-07 19:06:05 +00:00
|
|
|
],
|
|
|
|
instances: [
|
2019-06-11 22:24:35 +00:00
|
|
|
Aws::ElasticLoadBalancing::Types::Instance.new(instance_id: "i-87654321"),
|
2018-06-07 19:06:05 +00:00
|
|
|
],
|
2019-07-03 21:24:41 +00:00
|
|
|
security_groups: %w{
|
|
|
|
sg-12345678
|
|
|
|
sg-99998888
|
|
|
|
},
|
|
|
|
subnets: %w{
|
|
|
|
subnet-12345678
|
|
|
|
subnet-aaaabbbb
|
|
|
|
},
|
2019-06-11 22:24:35 +00:00
|
|
|
vpc_id: "vpc-12345678"
|
2018-06-07 19:06:05 +00:00
|
|
|
),
|
|
|
|
Aws::ElasticLoadBalancing::Types::LoadBalancerDescription.new(
|
2019-07-03 21:24:41 +00:00
|
|
|
availability_zones: %w{
|
|
|
|
us-east-1a
|
|
|
|
us-east-1e
|
|
|
|
},
|
2019-06-11 22:24:35 +00:00
|
|
|
dns_name: "999999.us-east-1.aws.amazon.com",
|
|
|
|
load_balancer_name: "gamma",
|
2018-06-07 19:06:05 +00:00
|
|
|
listener_descriptions: [
|
|
|
|
Aws::ElasticLoadBalancing::Types::ListenerDescription.new(
|
|
|
|
listener: Aws::ElasticLoadBalancing::Types::Listener.new(
|
2019-06-11 22:24:35 +00:00
|
|
|
protocol: "http",
|
2018-06-07 19:06:05 +00:00
|
|
|
load_balancer_port: 631,
|
2019-06-11 22:24:35 +00:00
|
|
|
instance_protocol: "http",
|
|
|
|
instance_port: 80
|
2018-06-07 19:06:05 +00:00
|
|
|
)
|
2019-07-09 00:20:30 +00:00
|
|
|
),
|
2018-06-07 19:06:05 +00:00
|
|
|
],
|
|
|
|
instances: [
|
|
|
|
],
|
2019-07-03 21:24:41 +00:00
|
|
|
security_groups: %w{
|
|
|
|
sg-12345678
|
|
|
|
sg-99998888
|
|
|
|
sg-01010101
|
|
|
|
},
|
|
|
|
subnets: %w{
|
|
|
|
subnet-ccccdddd
|
|
|
|
subnet-aaaabbbb
|
|
|
|
},
|
2019-06-11 22:24:35 +00:00
|
|
|
vpc_id: "vpc-87654321"
|
2019-07-09 00:20:30 +00:00
|
|
|
),
|
2018-06-07 19:06:05 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|