2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "resources/aws/aws_route_table"
|
2018-02-07 15:48:55 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws"
|
2019-05-21 00:19:38 +00:00
|
|
|
|
2018-02-07 15:48:55 +00:00
|
|
|
class EmptyAwsRouteTableTest < Minitest::Test
|
|
|
|
def setup
|
|
|
|
AwsRouteTable::BackendFactory.select(AwsMRtbB::Empty)
|
|
|
|
end
|
|
|
|
|
2019-01-21 21:05:46 +00:00
|
|
|
def test_search_hit_via_scalar_works_symbol
|
2019-06-11 22:24:35 +00:00
|
|
|
refute AwsRouteTable.new(route_table_id: "rtb-123abcde").exists?
|
2018-02-07 15:48:55 +00:00
|
|
|
end
|
|
|
|
|
2019-01-21 21:05:46 +00:00
|
|
|
def test_search_hit_via_scalar_works_string
|
2019-06-11 22:24:35 +00:00
|
|
|
refute AwsRouteTable.new("rtb-123abcde").exists?
|
2018-02-07 15:48:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class BasicAwsRouteTableTest2 < Minitest::Test
|
|
|
|
def setup
|
|
|
|
AwsRouteTable::BackendFactory.select(AwsMRtbB::Basic)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_hit
|
2019-06-11 22:24:35 +00:00
|
|
|
assert AwsRouteTable.new("rtb-05462d2278326a79c").exists?
|
|
|
|
assert AwsRouteTable.new("rtb-58508630").exists?
|
2018-03-29 16:50:40 +00:00
|
|
|
|
|
|
|
# not hexadecimal
|
|
|
|
assert_raises(ArgumentError) do
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsRouteTable.new("rtb-xyzxyzxy")
|
2018-03-29 16:50:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# not within length constraint
|
|
|
|
assert_raises(ArgumentError) do
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsRouteTable.new("rtb-abcdef012")
|
2018-03-29 16:50:40 +00:00
|
|
|
end
|
2018-02-07 15:48:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# MRtbB = Mock Routetable Backend
|
|
|
|
module AwsMRtbB
|
2018-02-08 04:26:37 +00:00
|
|
|
class Empty < AwsBackendBase
|
2018-02-07 15:48:55 +00:00
|
|
|
def describe_route_tables(query)
|
|
|
|
OpenStruct.new(route_tables: [])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
class Basic < AwsBackendBase
|
2018-02-07 15:48:55 +00:00
|
|
|
def describe_route_tables(query)
|
|
|
|
fixtures = [
|
2019-06-11 22:24:35 +00:00
|
|
|
OpenStruct.new({ associations: [],
|
|
|
|
propagating_vgws: [],
|
|
|
|
route_table_id: "rtb-05462d2278326a79c",
|
|
|
|
routes: [
|
|
|
|
{ destination_cidr_block: "172.32.1.0/24", gateway_id: "igw-4fb9e626", origin: "CreateRoute", state: "active" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ destination_cidr_block: "172.31.0.0/16", gateway_id: "local", origin: "CreateRouteTable", state: "active" },
|
2018-02-07 15:48:55 +00:00
|
|
|
],
|
2019-06-11 22:24:35 +00:00
|
|
|
tags: [{ key: "Name", value: "InSpec" }],
|
|
|
|
vpc_id: "vpc-169f777e",
|
2018-02-07 15:48:55 +00:00
|
|
|
}),
|
2019-06-11 22:24:35 +00:00
|
|
|
OpenStruct.new({ associations: [],
|
|
|
|
propagating_vgws: [],
|
|
|
|
route_table_id: "rtb-58508630",
|
|
|
|
routes: [
|
|
|
|
{ destination_cidr_block: "172.33.0.0/16", gateway_id: "local", origin: "CreateRouteTable", state: "active" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ destination_cidr_block: "0.0.0.0/0", gateway_id: "igw-4fb9e626", origin: "CreateRoute", state: "active" },
|
2018-02-07 15:48:55 +00:00
|
|
|
],
|
2019-06-11 22:24:35 +00:00
|
|
|
tags: [{ key: "Name", value: "InSpec" }],
|
|
|
|
vpc_id: "vpc-169f777e",
|
2019-07-09 00:20:30 +00:00
|
|
|
}),
|
2018-02-07 15:48:55 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
selected = fixtures.select do |rtb|
|
|
|
|
query[:filters].all? do |filter|
|
2019-06-11 22:24:35 +00:00
|
|
|
filter[:values].include?(rtb[filter[:name].tr("-", "_")])
|
2018-02-07 15:48:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
OpenStruct.new({ route_tables: selected })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|