Skip to content
Snippets Groups Projects
Commit 10456575 authored by Christian Kaenzig's avatar Christian Kaenzig Committed by GitHub
Browse files

Merge pull request #154 from ckaenzig/fix-params-validation

Fix params validation + specs
parents 9048b697 4fa44f58
No related branches found
No related tags found
No related merge requests found
...@@ -56,7 +56,6 @@ define postfix::conffile ( ...@@ -56,7 +56,6 @@ define postfix::conffile (
validate_absolute_path($path) validate_absolute_path($path)
if !is_string($source) and !is_array($source) { fail("value for source should be either String type or Array type got ${source}") } if !is_string($source) and !is_array($source) { fail("value for source should be either String type or Array type got ${source}") }
if !is_string($content) { fail("value for content should be String type; got ${content}") } if !is_string($content) { fail("value for content should be String type; got ${content}") }
validate_string($ensure)
validate_re($ensure, ['present', 'absent', 'directory'], validate_re($ensure, ['present', 'absent', 'directory'],
"\$ensure must be either 'present', 'absent' or 'directory', got '${ensure}'") "\$ensure must be either 'present', 'absent' or 'directory', got '${ensure}'")
validate_hash($options) validate_hash($options)
......
...@@ -29,11 +29,9 @@ ...@@ -29,11 +29,9 @@
# #
define postfix::config ($value = undef, $ensure = 'present') { define postfix::config ($value = undef, $ensure = 'present') {
validate_string($ensure)
validate_re($ensure, ['present', 'absent', 'blank'], validate_re($ensure, ['present', 'absent', 'blank'],
"\$ensure must be either 'present', 'absent' or 'blank', got '${ensure}'") "\$ensure must be either 'present', 'absent' or 'blank', got '${ensure}'")
if ($ensure == 'present') { if ($ensure == 'present') {
validate_string($value)
validate_re($value, '^.+$', validate_re($value, '^.+$',
'$value can not be empty if ensure = present') '$value can not be empty if ensure = present')
} }
......
...@@ -5,6 +5,8 @@ class postfix::files { ...@@ -5,6 +5,8 @@ class postfix::files {
$inet_interfaces = $postfix::inet_interfaces $inet_interfaces = $postfix::inet_interfaces
$mail_user = $postfix::mail_user $mail_user = $postfix::mail_user
$manage_conffiles = $postfix::manage_conffiles $manage_conffiles = $postfix::manage_conffiles
$maincf_source = $postfix::maincf_source
$mastercf_source = $postfix::mastercf_source
$master_smtp = $postfix::master_smtp $master_smtp = $postfix::master_smtp
$master_smtps = $postfix::master_smtps $master_smtps = $postfix::master_smtps
$master_submission = $postfix::master_submission $master_submission = $postfix::master_submission
...@@ -17,6 +19,10 @@ class postfix::files { ...@@ -17,6 +19,10 @@ class postfix::files {
$use_schleuder = $postfix::use_schleuder $use_schleuder = $postfix::use_schleuder
$use_sympa = $postfix::use_sympa $use_sympa = $postfix::use_sympa
validate_string($mastercf_source)
validate_string($master_smtp)
validate_string($master_smtps)
File { File {
replace => $manage_conffiles, replace => $manage_conffiles,
} }
...@@ -45,7 +51,7 @@ class postfix::files { ...@@ -45,7 +51,7 @@ class postfix::files {
} }
# Config files # Config files
if $postfix::mastercf_source { if $mastercf_source {
$mastercf_content = undef $mastercf_content = undef
} else { } else {
$mastercf_content = template( $mastercf_content = template(
...@@ -61,7 +67,7 @@ class postfix::files { ...@@ -61,7 +67,7 @@ class postfix::files {
mode => '0644', mode => '0644',
owner => 'root', owner => 'root',
seltype => $postfix::params::seltype, seltype => $postfix::params::seltype,
source => $postfix::mastercf_source, source => $mastercf_source,
} }
# Config files # Config files
...@@ -72,7 +78,7 @@ class postfix::files { ...@@ -72,7 +78,7 @@ class postfix::files {
owner => 'root', owner => 'root',
replace => false, replace => false,
seltype => $postfix::params::seltype, seltype => $postfix::params::seltype,
source => $postfix::maincf_source, source => $maincf_source,
} }
::postfix::config { ::postfix::config {
......
...@@ -31,11 +31,8 @@ define postfix::hash ( ...@@ -31,11 +31,8 @@ define postfix::hash (
include ::postfix::params include ::postfix::params
validate_absolute_path($name) validate_absolute_path($name)
# validate_string($source)
# validate_string($content)
if !is_string($source) and !is_array($source) { fail("value for source should be either String type or Array type got ${source}") } if !is_string($source) and !is_array($source) { fail("value for source should be either String type or Array type got ${source}") }
if !is_string($content) and !is_array($content) { fail("value for source should be either String type or Array type got ${content}") } if !is_string($content) and !is_array($content) { fail("value for source should be either String type or Array type got ${content}") }
validate_string($ensure)
validate_re($ensure, ['present', 'absent'], validate_re($ensure, ['present', 'absent'],
"\$ensure must be either 'present' or 'absent', got '${ensure}'") "\$ensure must be either 'present' or 'absent', got '${ensure}'")
......
...@@ -118,14 +118,7 @@ class postfix ( ...@@ -118,14 +118,7 @@ class postfix (
validate_string($alias_maps) validate_string($alias_maps)
validate_string($inet_interfaces) validate_string($inet_interfaces)
validate_string($ldap_base)
validate_string($ldap_host)
validate_string($ldap_options)
validate_string($mail_user) validate_string($mail_user)
validate_string($maincf_source)
validate_string($mastercf_source)
validate_string($master_smtp)
validate_string($master_smtps)
validate_string($mydestination) validate_string($mydestination)
validate_string($mynetworks) validate_string($mynetworks)
validate_string($myorigin) validate_string($myorigin)
......
...@@ -14,6 +14,11 @@ ...@@ -14,6 +14,11 @@
# include postfix::ldap # include postfix::ldap
# #
class postfix::ldap { class postfix::ldap {
validate_string($postfix::ldap_base)
validate_string($postfix::ldap_host)
validate_string($postfix::ldap_options)
if $::osfamily == 'Debian' { if $::osfamily == 'Debian' {
package {'postfix-ldap': package {'postfix-ldap':
before => File['/etc/postfix/ldap-aliases.cf'], before => File['/etc/postfix/ldap-aliases.cf'],
......
...@@ -36,11 +36,8 @@ define postfix::map ( ...@@ -36,11 +36,8 @@ define postfix::map (
include ::postfix::params include ::postfix::params
validate_absolute_path($path) validate_absolute_path($path)
# validate_string($source)
# validate_string($content)
if !is_string($source) and !is_array($source) { fail("value for source should be either String type or Array type got ${source}") } if !is_string($source) and !is_array($source) { fail("value for source should be either String type or Array type got ${source}") }
if !is_string($content) and !is_array($content) { fail("value for source should be either String type or Array type got ${content}") } if !is_string($content) and !is_array($content) { fail("value for source should be either String type or Array type got ${content}") }
validate_string($ensure)
validate_re($ensure, ['present', 'absent'], validate_re($ensure, ['present', 'absent'],
"\$ensure must be either 'present' or 'absent', got '${ensure}'") "\$ensure must be either 'present' or 'absent', got '${ensure}'")
......
...@@ -20,7 +20,7 @@ describe 'postfix::conffile' do ...@@ -20,7 +20,7 @@ describe 'postfix::conffile' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_file('postfix conffile foo') is_expected.to contain_file('postfix conffile foo')
}.to raise_error(Puppet::Error, /\["present"\] is not a string/) }.to raise_error
end end
end end
......
...@@ -17,7 +17,7 @@ describe 'postfix::config' do ...@@ -17,7 +17,7 @@ describe 'postfix::config' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_augeas("set postfix 'foo'") is_expected.to contain_augeas("set postfix 'foo'")
}.to raise_error(Puppet::Error, /value can not be empty/) }.to raise_error
end end
end end
...@@ -28,7 +28,7 @@ describe 'postfix::config' do ...@@ -28,7 +28,7 @@ describe 'postfix::config' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_augeas("set postfix 'foo'") is_expected.to contain_augeas("set postfix 'foo'")
}.to raise_error(Puppet::Error, /\["bar"\] is not a string/) }.to raise_error
end end
end end
...@@ -40,7 +40,7 @@ describe 'postfix::config' do ...@@ -40,7 +40,7 @@ describe 'postfix::config' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_augeas("set postfix 'foo'") is_expected.to contain_augeas("set postfix 'foo'")
}.to raise_error(Puppet::Error, /\["present"\] is not a string/) }.to raise_error
end end
end end
......
...@@ -20,7 +20,7 @@ describe 'postfix::hash' do ...@@ -20,7 +20,7 @@ describe 'postfix::hash' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_file('/tmp/foo') is_expected.to contain_file('/tmp/foo')
}.to raise_error(Puppet::Error, /\["present"\] is not a string/) }.to raise_error
end end
end end
......
...@@ -20,7 +20,7 @@ describe 'postfix::map' do ...@@ -20,7 +20,7 @@ describe 'postfix::map' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_file('postfix map foo') is_expected.to contain_file('postfix map foo')
}.to raise_error(Puppet::Error, /\["present"\] is not a string/) }.to raise_error
end end
end end
......
...@@ -24,7 +24,7 @@ describe 'postfix::transport' do ...@@ -24,7 +24,7 @@ describe 'postfix::transport' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_augeas('Postfix transport - foo') is_expected.to contain_augeas('Postfix transport - foo')
}.to raise_error(Puppet::Error, /\["bar"\] is not a string/) }.to raise_error
end end
end end
...@@ -37,7 +37,7 @@ describe 'postfix::transport' do ...@@ -37,7 +37,7 @@ describe 'postfix::transport' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_augeas('Postfix transport - foo') is_expected.to contain_augeas('Postfix transport - foo')
}.to raise_error(Puppet::Error, /\["baz"\] is not a string/) }.to raise_error
end end
end end
...@@ -50,7 +50,7 @@ describe 'postfix::transport' do ...@@ -50,7 +50,7 @@ describe 'postfix::transport' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_augeas('Postfix transport - foo') is_expected.to contain_augeas('Postfix transport - foo')
}.to raise_error(Puppet::Error, /\["baz"\] is not a string/) }.to raise_error
end end
end end
...@@ -76,7 +76,7 @@ describe 'postfix::transport' do ...@@ -76,7 +76,7 @@ describe 'postfix::transport' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_augeas('Postfix transport - foo') is_expected.to contain_augeas('Postfix transport - foo')
}.to raise_error(Puppet::Error, /\["baz"\] is not a string/) }.to raise_error
end end
end end
......
...@@ -32,7 +32,7 @@ describe 'postfix::virtual' do ...@@ -32,7 +32,7 @@ describe 'postfix::virtual' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_augeas('Postfix virtual - foo') is_expected.to contain_augeas('Postfix virtual - foo')
}.to raise_error(Puppet::Error, /\["bar"\] is not a string/) }.to raise_error
end end
end end
...@@ -45,7 +45,7 @@ describe 'postfix::virtual' do ...@@ -45,7 +45,7 @@ describe 'postfix::virtual' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_augeas('Postfix virtual - foo') is_expected.to contain_augeas('Postfix virtual - foo')
}.to raise_error(Puppet::Error, /\["baz"\] is not a string/) }.to raise_error
end end
end end
...@@ -71,7 +71,7 @@ describe 'postfix::virtual' do ...@@ -71,7 +71,7 @@ describe 'postfix::virtual' do
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_augeas('Postfix virtual - foo') is_expected.to contain_augeas('Postfix virtual - foo')
}.to raise_error(Puppet::Error, /\["baz"\] is not a string/) }.to raise_error
end end
end end
......
...@@ -24,6 +24,8 @@ require 'pathname' ...@@ -24,6 +24,8 @@ require 'pathname'
dir = Pathname.new(__FILE__).parent dir = Pathname.new(__FILE__).parent
Puppet[:modulepath] = File.join(dir, 'fixtures', 'modules') Puppet[:modulepath] = File.join(dir, 'fixtures', 'modules')
RSpec::Expectations.configuration.on_potential_false_positives = :nothing
# There's no real need to make this version dependent, but it helps find # There's no real need to make this version dependent, but it helps find
# regressions in Puppet # regressions in Puppet
# #
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment