From 9bab17305fbd94c4289a9dca972b13b2f6e2d829 Mon Sep 17 00:00:00 2001 From: Nate Potter Date: Mon, 17 Oct 2016 14:32:04 -0700 Subject: [PATCH 1/3] (MODULES-3980) Fix ipv4 regex validator The current pattern for stdlib::compat::ipv4 is incorrect, and will return true for any four numbers separated with periods. This commit improves the regex to validate that the IP octets are between 1 and 255. --- spec/aliases/ipv4_spec.rb | 2 ++ types/compat/ipv4.pp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/aliases/ipv4_spec.rb b/spec/aliases/ipv4_spec.rb index e767b45b8..f9022a411 100644 --- a/spec/aliases/ipv4_spec.rb +++ b/spec/aliases/ipv4_spec.rb @@ -20,6 +20,8 @@ 'nope', '77', '4.4.4', + '9999.9999.9999.9999', + '192.168.256.1', '2001:0db8:85a3:0000:0000:8a2e:0370:73342001:0db8:85a3:0000:0000:8a2e:0370:7334' ].each do |value| describe value.inspect do diff --git a/types/compat/ipv4.pp b/types/compat/ipv4.pp index 1d72ebd09..c0ddbfed9 100644 --- a/types/compat/ipv4.pp +++ b/types/compat/ipv4.pp @@ -1,2 +1,2 @@ # Emulate the validate_ipv4_address and is_ipv4_address functions -type Stdlib::Compat::Ipv4 = Pattern[/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/] +type Stdlib::Compat::Ipv4 = Pattern[/^(([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]?){4}$/] From 8ef45bfc33eae887daea98b44b477854ece08468 Mon Sep 17 00:00:00 2001 From: Nate Potter Date: Tue, 18 Oct 2016 10:16:40 -0700 Subject: [PATCH 2/3] Use parallel_tests 2.9.0 for ruby < 2.0.0 Parallel_tests 2.10.0 requires ruby >= 2.0.0, so for jobs with ruby < 2.0.0 parallel_tests 2.9.0 should be used. --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 0a7542d09..e4ed0cd65 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,7 @@ group :development, :unit_tests do gem 'mocha', '< 1.2.0' gem 'rspec-puppet-facts' gem 'simplecov' - gem 'parallel_tests' + gem 'parallel_tests', '2.9.0' if RUBY_VERSION < '2.0.0' gem 'rubocop', '0.41.2' if RUBY_VERSION < '2.0.0' gem 'rubocop' if RUBY_VERSION >= '2.0.0' gem 'rubocop-rspec', '~> 1.6' if RUBY_VERSION >= '2.3.0' From 2b5d922146da4405fd178867e47ec23492b4cdf6 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 21 Oct 2016 15:53:46 -0700 Subject: [PATCH 3/3] Add specs --- spec/aliases/ipv4_spec.rb | 2 ++ spec/functions/is_ipv4_address_spec.rb | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/spec/aliases/ipv4_spec.rb b/spec/aliases/ipv4_spec.rb index f9022a411..b6f6af1e1 100644 --- a/spec/aliases/ipv4_spec.rb +++ b/spec/aliases/ipv4_spec.rb @@ -7,6 +7,7 @@ '224.0.0.0', '255.255.255.255', '0.0.0.0', + '10.10.10.10', '192.88.99.0' ].each do |value| describe value.inspect do @@ -21,6 +22,7 @@ '77', '4.4.4', '9999.9999.9999.9999', + '10.010.10.10', '192.168.256.1', '2001:0db8:85a3:0000:0000:8a2e:0370:73342001:0db8:85a3:0000:0000:8a2e:0370:7334' ].each do |value| diff --git a/spec/functions/is_ipv4_address_spec.rb b/spec/functions/is_ipv4_address_spec.rb index e39d93bf8..9d5dd070e 100644 --- a/spec/functions/is_ipv4_address_spec.rb +++ b/spec/functions/is_ipv4_address_spec.rb @@ -7,6 +7,10 @@ it { is_expected.to run.with_params('1.2.3.4').and_return(true) } it { is_expected.to run.with_params('1.2.3.255').and_return(true) } it { is_expected.to run.with_params('1.2.3').and_return(false) } + it { is_expected.to run.with_params('10.10.10.10').and_return(true) } + it { is_expected.to run.with_params('10.010.10.10').and_return(false) } + it { is_expected.to run.with_params('9999.9999.9999.9999').and_return(false) } + it { is_expected.to run.with_params('192.168.256.1').and_return(false) } it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) } it { is_expected.to run.with_params('').and_return(false) } it { is_expected.to run.with_params('one').and_return(false) }