Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #16913 - Add validation for the dhcp range #112

Merged
merged 2 commits into from Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .fixtures.yml
Expand Up @@ -6,3 +6,4 @@ fixtures:

symlinks:
dhcp: "#{source_dir}"
test_module: "#{source_dir}/spec/static_fixtures/test_module"
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], Enum[''], Boolean] $range = undef,
Optional[String] $failover = undef,
Variant[Array[String], Optional[String]] $options = undef,
Variant[Array[String], Optional[String]] $parameters = undef,
Expand Down
59 changes: 59 additions & 0 deletions spec/aliases/macaddress_spec.rb
@@ -0,0 +1,59 @@
require 'spec_helper'

describe 'test_module::macaddress', type: :class do
describe 'valid handling' do
[
'a:a:a:a:a:a',
'00:00:00:00:00:00',
'11:11:11:11:11:11',
'22:22:22:22:22:22',
'33:33:33:33:33:33',
'44:44:44:44:44:44',
'55:55:55:55:55:55',
'66:66:66:66:66:66',
'77:77:77:77:77:77',
'88:88:88:88:88:88',
'99:99:99:99:99:99',
'aa:aa:aa:aa:aa:aa',
'bb:bb:bb:bb:bb:bb',
'cc:cc:cc:cc:cc:cc',
'dd:dd:dd:dd:dd:dd',
'ee:ee:ee:ee:ee:ee',
'ff:ff:ff:ff:ff:ff',
'AA:AA:AA:AA:AA:AA',
'BB:BB:BB:BB:BB:BB',
'CC:CC:CC:CC:CC:CC',
'DD:DD:DD:DD:DD:DD',
'EE:EE:EE:EE:EE:EE',
'FF:FF:FF:FF:FF:FF',
].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,
"aa:aa:aa:aa:aa",
"aaa:aa:aa:aa:aa:aa",
"aa:aaa:aa:aa:aa:aa",
"aa:aa:aaa:aa:aa:aa",
"aa:aa:aa:aaa:aa:aa",
"aa:aa:aa:aa:aaa:aa",
"aa:aa:aa:aa:aa:aaa",
"aa:aa:aa:aa:aa:aa:aa",
"gg:gg:gg:gg:gg:gg",
].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::Macaddress/) }
end
end
end

end
end
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
43 changes: 43 additions & 0 deletions spec/aliases/staticroute_spec.rb
@@ -0,0 +1,43 @@
require 'spec_helper'

describe 'test_module::staticroute', type: :class do
describe 'valid handling' do
[
{
'mask' => '255.255.255.0',
'gateway' => '192.0.2.1',
},
{
'mask' => '255.255.255.0',
'gateway' => '192.0.2.1',
'network' => '192.0.2.0',
},
].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,
{},
{
'mask' => '255.255.255.0',
},
{
'gateway' => '192.0.2.1',
},
].each do |value|
describe value.inspect do
let(:params) {{ value: value }}
it { is_expected.to compile.and_raise_error(/parameter 'value' expects/) }
end
end
end

end
end
14 changes: 7 additions & 7 deletions spec/defines/pool_spec.rb
Expand Up @@ -32,7 +32,7 @@
let :params do {
:network => '10.0.0.0',
:mask => '255.255.255.0',
:range => '10.0.0.10 - 10.0.0.50',
:range => '10.0.0.10 10.0.0.50',
:failover => '10.1.1.20',
} end

Expand All @@ -42,7 +42,7 @@
' pool',
' {',
' failover peer "10.1.1.20";',
' range 10.0.0.10 - 10.0.0.50;',
' range 10.0.0.10 10.0.0.50;',
' }',
' option subnet-mask 255.255.255.0;',
'}',
Expand Down Expand Up @@ -70,16 +70,16 @@
let :params do {
:network => '10.0.0.0',
:mask => '255.255.255.0',
:range => ['10.0.0.10 - 10.0.0.50','10.0.0.100 - 10.0.0.150'],
:range => ['10.0.0.10 10.0.0.50','10.0.0.100 10.0.0.150'],
} end

it {
verify_concat_fragment_exact_contents(catalogue, 'dhcp.conf+70_mypool.dhcp', [
'subnet 10.0.0.0 netmask 255.255.255.0 {',
' pool',
' {',
' range 10.0.0.10 - 10.0.0.50;',
' range 10.0.0.100 - 10.0.0.150;',
' range 10.0.0.10 10.0.0.50;',
' range 10.0.0.100 10.0.0.150;',
' }',
' option subnet-mask 255.255.255.0;',
'}',
Expand Down Expand Up @@ -109,7 +109,7 @@
:network => '10.0.0.0',
:mask => '255.255.255.0',
:pool_parameters => 'allow members of "some-class"',
:range => '10.0.0.10 - 10.0.0.50',
:range => '10.0.0.10 10.0.0.50',
:gateway => '10.0.0.1',
:options => 'ntp-servers 10.0.0.2',
:parameters => 'max-lease-time 300',
Expand All @@ -132,7 +132,7 @@
" pool",
" {",
" allow members of \"some-class\";",
" range 10.0.0.10 - 10.0.0.50;",
" range 10.0.0.10 10.0.0.50;",
" }",
" option domain-name \"example.org\";",
" option subnet-mask 255.255.255.0;",
Expand Down
6 changes: 6 additions & 0 deletions spec/static_fixtures/test_module/manifests/macaddress.pp
@@ -0,0 +1,6 @@
# Class to test the dhcp::Macaddress type
class test_module::macaddress(
Dhcp::Macaddress $value,
) {
notice('Success')
}
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')
}
6 changes: 6 additions & 0 deletions spec/static_fixtures/test_module/manifests/staticroute.pp
@@ -0,0 +1,6 @@
# Class to test the dhcp::StaticRoute type
class test_module::staticroute(
Dhcp::StaticRoute $value,
) {
notice('Success')
}
2 changes: 1 addition & 1 deletion types/macaddress.pp
@@ -1 +1 @@
type Dhcp::Macaddress = Pattern[/[0-9A-Fa-f]{1,2}(:[0-9A-Fa-f]{1,2}){5}/]
type Dhcp::Macaddress = Pattern[/^[0-9A-Fa-f]{1,2}(:[0-9A-Fa-f]{1,2}){5}$/]
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]+))?)?$/]