Skip to content

Commit

Permalink
Fixes #16913 - Add validation for the dhcp range
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Oct 11, 2017
1 parent 11708ed commit d5e7b6d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion manifests/pool.pp
Expand Up @@ -3,7 +3,7 @@
String $mask,
Optional[String] $gateway = undef,
Variant[Array[String], Optional[String]] $pool_parameters = undef,
Variant[Array[String], Optional[String], Boolean] $range = undef,
Variant[Array[Dhcp::Range], Optional[Dhcp::Range], Boolean] $range = undef,
Optional[String] $failover = undef,
Variant[Array[String], Optional[String]] $options = undef,
Variant[Array[String], Optional[String]] $parameters = undef,
Expand Down
35 changes: 35 additions & 0 deletions spec/aliases/range_spec.rb
@@ -0,0 +1,35 @@
require 'spec_helper'

describe 'test_module::range', type: :class do
describe 'valid handling' do
[
'192.0.2.100',
'192.0.2.100 192.0.2.200',
'1.1.1.1 255.255.255.255',
'dynamic-bootp 192.0.2.100 192.0.2.200',
].each do |value|
describe value.inspect do
let(:params) {{ value: value }}
it { is_expected.to compile }
end
end
end

describe 'invalid value handling' do
context 'garbage inputs' do
[
nil,
"all",
"all all",
"1 192.0.2.183",
"192.0.2.100 1",
].each do |value|
describe value.inspect do
let(:params) {{ value: value }}
it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Dhcp::Range/) }
end
end
end

end
end
6 changes: 6 additions & 0 deletions spec/static_fixtures/test_module/manifests/range.pp
@@ -0,0 +1,6 @@
# Class to test the dhcp::Range type
class test_module::range(
Dhcp::Range $value,
) {
notice('Success')
}
1 change: 1 addition & 0 deletions types/range.pp
@@ -0,0 +1 @@
type Dhcp::Range= Pattern[/^(dynamic-bootp )?((([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]){3}([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d)))(\/((([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]){3}([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))|[0-9]+))?( ((([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]){3}([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d)))(\/((([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]){3}([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))|[0-9]+))?)?$/]

0 comments on commit d5e7b6d

Please sign in to comment.