mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
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:
parent
57c36790a3
commit
a40f857e2b
2 changed files with 15 additions and 3 deletions
|
@ -26,9 +26,11 @@ 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' \
|
||||
' format "rtb-" followed by 8 hexadecimal characters.'
|
||||
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
|
||||
|
||||
validated_params
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue