2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "resources/aws/aws_elb"
|
2018-06-07 19:06:05 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws"
|
|
|
|
require "resources/aws/aws_elb"
|
2019-05-21 00:19:38 +00:00
|
|
|
|
2018-06-07 19:06:05 +00:00
|
|
|
# MAESB = MockAwsElbSingularBackend
|
|
|
|
# Abbreviation not used outside this file
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Constructor Tests
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsElbConstructorTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsElb::BackendFactory.select(MAESB::Empty)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_empty_params_rejected
|
2019-01-21 21:05:46 +00:00
|
|
|
assert_raises(ArgumentError) { AwsElb.new }
|
2018-06-07 19:06:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_string_accepted
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsElb.new "my-elb"
|
2018-06-07 19:06:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_hash_accepted
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsElb.new elb_name: "my-elb"
|
2018-06-07 19:06:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rejects_unrecognized_params
|
|
|
|
assert_raises(ArgumentError) { AwsElb.new(shoe_size: 9) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Search / Recall
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsElbFilterCriteriaTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsElb::BackendFactory.select(MAESB::Basic)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_miss
|
2019-06-11 22:24:35 +00:00
|
|
|
refute AwsElb.new("nonesuch").exists?
|
2018-06-07 19:06:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_recall_when_provided_a_string
|
2019-06-11 22:24:35 +00:00
|
|
|
elb = AwsElb.new "kangaroo"
|
2018-06-07 19:06:05 +00:00
|
|
|
assert elb.exists?
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal("kangaroo", elb.elb_name)
|
2018-06-07 19:06:05 +00:00
|
|
|
end
|
|
|
|
|
2019-01-21 21:05:46 +00:00
|
|
|
def test_recall_when_provided_a_symbol
|
2019-06-11 22:24:35 +00:00
|
|
|
elb = AwsElb.new elb_name: "kang-the-alien"
|
2018-06-07 19:06:05 +00:00
|
|
|
assert elb.exists?
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal("kang-the-alien", elb.elb_name)
|
2018-06-07 19:06:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Properties
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsElbProperties < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsElb::BackendFactory.select(MAESB::Basic)
|
2019-06-11 22:24:35 +00:00
|
|
|
@roo = AwsElb.new("kangaroo")
|
|
|
|
@kang = AwsElb.new("kang-the-alien")
|
|
|
|
@gamma = AwsElb.new("gamma")
|
|
|
|
@miss = AwsElb.new("nonesuch")
|
2018-06-07 19:06:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_with_availability_zones
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes(@roo.availability_zones, "us-east-1b")
|
|
|
|
assert_includes(@roo.availability_zones, "us-east-1c")
|
2018-06-07 19:06:05 +00:00
|
|
|
assert_equal(2, @roo.availability_zones.count)
|
|
|
|
refute_includes(@roo.availability_zones, nil)
|
|
|
|
assert_kind_of(Array, @miss.availability_zones)
|
|
|
|
assert_empty(@miss.availability_zones)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_with_dns_name
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal(@gamma.dns_name, "999999.us-east-1.aws.amazon.com")
|
|
|
|
assert_equal(@roo.dns_name, "12345678.us-east-2.aws.amazon.com")
|
2018-06-07 19:06:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_with_external_ports
|
|
|
|
assert_includes(@kang.external_ports, 80)
|
|
|
|
assert_includes(@gamma.external_ports, 631)
|
|
|
|
assert_equal(1, @roo.external_ports.count)
|
|
|
|
refute_includes(@roo.external_ports, nil)
|
|
|
|
assert_kind_of(Array, @miss.external_ports)
|
|
|
|
assert_empty(@miss.external_ports)
|
|
|
|
end
|
2019-01-21 21:05:46 +00:00
|
|
|
|
2018-06-07 19:06:05 +00:00
|
|
|
def test_property_with_instance_ids
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes(@roo.instance_ids, "i-87654321")
|
|
|
|
assert_includes(@kang.instance_ids, "i-12345678")
|
2018-06-07 19:06:05 +00:00
|
|
|
assert_equal(2, @kang.instance_ids.count)
|
|
|
|
assert_equal(0, @gamma.instance_ids.count)
|
|
|
|
refute_includes(@kang.instance_ids, nil)
|
|
|
|
assert_kind_of(Array, @miss.instance_ids)
|
|
|
|
assert_empty(@miss.instance_ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_with_internal_ports
|
|
|
|
assert_includes(@gamma.internal_ports, 80)
|
|
|
|
assert_includes(@roo.internal_ports, 1001)
|
|
|
|
assert_equal(1, @roo.internal_ports.count)
|
|
|
|
refute_includes(@roo.internal_ports, nil)
|
|
|
|
assert_kind_of(Array, @miss.internal_ports)
|
|
|
|
assert_empty(@miss.internal_ports)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_with_security_group_ids
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes(@kang.security_group_ids, "sg-12345678")
|
|
|
|
assert_includes(@kang.security_group_ids, "sg-99998888")
|
2018-06-07 19:06:05 +00:00
|
|
|
assert_equal(3, @kang.security_group_ids.count)
|
|
|
|
refute_includes(@kang.security_group_ids, nil)
|
|
|
|
assert_kind_of(Array, @miss.security_group_ids)
|
|
|
|
assert_empty(@miss.security_group_ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_with_subnet_ids
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes(@gamma.subnet_ids, "subnet-ccccdddd")
|
|
|
|
assert_includes(@kang.subnet_ids, "subnet-12345678")
|
2018-06-07 19:06:05 +00:00
|
|
|
assert_equal(2, @gamma.subnet_ids.count)
|
|
|
|
refute_includes(@gamma.subnet_ids, nil)
|
|
|
|
assert_kind_of(Array, @miss.subnet_ids)
|
|
|
|
assert_empty(@miss.subnet_ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_vpc_id
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal(@gamma.vpc_id, "vpc-87654321")
|
2018-06-07 19:06:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
#=============================================================================#
|
|
|
|
# Test Fixtures
|
|
|
|
#=============================================================================#
|
|
|
|
module MAESB
|
|
|
|
class Empty < AwsBackendBase
|
|
|
|
def describe_load_balancers(query = {})
|
|
|
|
raise Aws::ElasticLoadBalancing::Errors::LoadBalancerNotFound.new(nil, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Basic < AwsBackendBase
|
|
|
|
def describe_load_balancers(query = {})
|
|
|
|
data = 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
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
if query[:load_balancer_names]
|
|
|
|
result = data.load_balancer_descriptions.select do |lbd|
|
2019-01-21 21:05:46 +00:00
|
|
|
query[:load_balancer_names].include? lbd.load_balancer_name
|
2018-06-07 19:06:05 +00:00
|
|
|
end
|
|
|
|
if result.empty?
|
|
|
|
raise Aws::ElasticLoadBalancing::Errors::LoadBalancerNotFound.new(nil, nil)
|
2019-01-21 21:05:46 +00:00
|
|
|
else
|
2018-06-07 19:06:05 +00:00
|
|
|
Aws::ElasticLoadBalancing::Types::DescribeAccessPointsOutput.new(
|
|
|
|
load_balancer_descriptions: result
|
|
|
|
)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
data
|
2019-01-21 21:05:46 +00:00
|
|
|
end
|
2018-06-07 19:06:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|