Change route_table_id regexp for correctness (#2885)

Without the terminating character ($), it just accepted any characters
at all after the initial matching set.

Also add some tests to assure we're raising appropriately.

Co-authored-by: Trevor Bramble <tbramble@chef.io>
Co-authored-by: Joshua Padgett <jpadgett@chef.io>

Signed-off-by: Trevor Bramble <tbramble@chef.io>
This commit is contained in:
Trevor Bramble 2018-03-29 09:50:40 -07:00 committed by Jared Quick
parent 57c36790a3
commit a40f857e2b
2 changed files with 15 additions and 3 deletions

View file

@ -26,8 +26,10 @@ class AwsRouteTable < Inspec.resource(1)
allowed_scalar_type: String,
)
if validated_params.key?(:route_table_id) && validated_params[:route_table_id] !~ /^rtb\-[0-9a-f]{8}/
raise ArgumentError, 'aws_route_table Route Table ID must be in the' \
if validated_params.key?(:route_table_id) &&
validated_params[:route_table_id] !~ /^rtb\-[0-9a-f]{8}$/
raise ArgumentError,
'aws_route_table Route Table ID must be in the' \
' format "rtb-" followed by 8 hexadecimal characters.'
end

View file

@ -22,6 +22,16 @@ class BasicAwsRouteTableTest2 < Minitest::Test
def test_search_hit
assert AwsRouteTable.new('rtb-2c60ec44').exists?
assert AwsRouteTable.new('rtb-58508630').exists?
# not hexadecimal
assert_raises(ArgumentError) do
AwsRouteTable.new('rtb-xyzxyzxy')
end
# not within length constraint
assert_raises(ArgumentError) do
AwsRouteTable.new('rtb-abcdef012')
end
end
end