diff --git a/lib/puppet/parser/functions/is_valid_mac_address.rb b/lib/puppet/parser/functions/is_valid_mac_address.rb index 0b91d0d..a00d874 100644 --- a/lib/puppet/parser/functions/is_valid_mac_address.rb +++ b/lib/puppet/parser/functions/is_valid_mac_address.rb @@ -12,6 +12,14 @@ module Puppet::Parser::Functions "given #{arguments.size} for 1") end + mac = arguments[0] + + if /^[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}$/.match(mac) then + return true + else + return false + end + end end diff --git a/spec/unit/parser/functions/is_valid_mac_address_spec.rb b/spec/unit/parser/functions/is_valid_mac_address_spec.rb index c4eb468..62e6fee 100644 --- a/spec/unit/parser/functions/is_valid_mac_address_spec.rb +++ b/spec/unit/parser/functions/is_valid_mac_address_spec.rb @@ -19,12 +19,17 @@ describe "the is_valid_mac_address function" do end it "should return true if a valid mac address" do - result = @scope.function_is_valid_mac_address("00:a0:1f:12:7f:a0") + result = @scope.function_is_valid_mac_address(["00:a0:1f:12:7f:a0"]) result.should(eq(true)) end + it "should return false if octets are out of range" do + result = @scope.function_is_valid_mac_address(["00:a0:1f:12:7f:g0"]) + result.should(eq(false)) + end + it "should return false if not valid" do - result = @scope.function_is_valid_mac_address("not valid") + result = @scope.function_is_valid_mac_address(["not valid"]) result.should(eq(false)) end