Add 17 hexadecimal characters support aws_vpc (#3518) (#3564)

aws_vpc: accept 17 hexadecimal characters for vpc_id 

Signed-off-by kchistova <kchistova@gmail.com>
This commit is contained in:
Ksenia 2018-11-05 17:01:16 +02:00 committed by Jared Quick
parent f976796ba9
commit c07ec59070
3 changed files with 22 additions and 6 deletions

View file

@ -37,7 +37,7 @@ An `aws_vpc` resource block identifies a VPC by id. If no VPC ID is provided, th
end
# Find a VPC by ID
describe aws_vpc('vpc-12345678') do
describe aws_vpc('vpc-12345678987654321') do
it { should exist }
end
@ -58,6 +58,10 @@ The following examples show how to use this InSpec audit resource.
it { should_not exist }
end
describe aws_vpc('vpc-abcd123454321dcba') do
it { should_not exist }
end
### Test the CIDR of a named VPC
describe aws_vpc('vpc-87654321') do

View file

@ -30,8 +30,8 @@ class AwsVpc < Inspec.resource(1)
allowed_scalar_type: String,
)
if validated_params.key?(:vpc_id) && validated_params[:vpc_id] !~ /^vpc\-[0-9a-f]{8}/
raise ArgumentError, 'aws_vpc VPC ID must be in the format "vpc-" followed by 8 hexadecimal characters.'
if validated_params.key?(:vpc_id) && validated_params[:vpc_id] !~ /^vpc\-([0-9a-f]{8})|(^vpc\-[0-9a-f]{17})$/
raise ArgumentError, 'aws_vpc VPC ID must be in the format "vpc-" followed by 8 or 17 hexadecimal characters.'
end
validated_params

View file

@ -16,14 +16,22 @@ class AwsVpcConstructorTest < Minitest::Test
AwsVpc.new
end
def test_accepts_vpc_id_as_scalar
def test_accepts_vpc_id_as_scalar_eight_sign
AwsVpc.new('vpc-12345678')
end
def test_accepts_vpc_id_as_hash
def test_accepts_vpc_id_as_scalar
AwsVpc.new('vpc-12345678987654321')
end
def test_accepts_vpc_id_as_hash_eight_sign
AwsVpc.new(vpc_id: 'vpc-1234abcd')
end
def test_accepts_vpc_id_as_hash
AwsVpc.new(vpc_id: 'vpc-abcd123454321dcba')
end
def test_rejects_unrecognized_params
assert_raises(ArgumentError) { AwsVpc.new(shoe_size: 9) }
end
@ -55,9 +63,13 @@ class AwsVpcRecallTest < Minitest::Test
assert AwsVpc.new(vpc_id: 'vpc-12344321').exists?
end
def test_search_miss_is_not_an_exception
def test_search_miss_is_not_an_exception_eight_sign
refute AwsVpc.new(vpc_id: 'vpc-00000000').exists?
end
def test_search_miss_is_not_an_exception
refute AwsVpc.new(vpc_id: 'vpc-00000000000000000').exists?
end
end
#=============================================================================#