validations for nginx::resource::mailhost
This commit is contained in:
parent
d683fae9ff
commit
10a1691b9e
2 changed files with 59 additions and 13 deletions
|
@ -43,7 +43,7 @@
|
|||
# }
|
||||
define nginx::resource::mailhost (
|
||||
$listen_port,
|
||||
$ensure = 'enable',
|
||||
$ensure = 'present',
|
||||
$listen_ip = '*',
|
||||
$listen_options = undef,
|
||||
$ipv6_enable = false,
|
||||
|
@ -65,6 +65,40 @@ define nginx::resource::mailhost (
|
|||
mode => '0644',
|
||||
}
|
||||
|
||||
if !is_integer($listen_port) {
|
||||
fail('$listen_port must be an integer.')
|
||||
}
|
||||
validate_re($ensure, '^(present|absent)$',
|
||||
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
|
||||
validate_string($listen_ip)
|
||||
if ($listen_options != undef) {
|
||||
validate_string($listen_options)
|
||||
}
|
||||
validate_bool($ipv6_enable)
|
||||
validate_string($ipv6_listen_ip)
|
||||
if !is_integer($ipv6_listen_port) {
|
||||
fail('$ipv6_listen_port must be an integer.')
|
||||
}
|
||||
validate_string($ipv6_listen_options)
|
||||
validate_bool($ssl)
|
||||
if ($ssl_cert != undef) {
|
||||
validate_string($ssl_cert)
|
||||
}
|
||||
if ($ssl_key != undef) {
|
||||
validate_string($ssl_key)
|
||||
}
|
||||
if ($ssl_port != undef) and (!is_integer($ssl_port)) {
|
||||
fail('$ssl_port must be an integer.')
|
||||
}
|
||||
validate_re($starttls, '^(on|only|off)$',
|
||||
"${starttls} is not supported for starttls. Allowed values are 'on', 'only' and 'off'.")
|
||||
if ($protocol != undef) {
|
||||
validate_string($protocol)
|
||||
}
|
||||
if ($auth_http != undef) {
|
||||
validate_string($auth_http)
|
||||
}
|
||||
validate_string($xclient)
|
||||
validate_array($server_name)
|
||||
|
||||
$config_file = "${nginx::config::nx_conf_dir}/conf.mail.d/${name}.conf"
|
||||
|
|
|
@ -48,7 +48,7 @@ describe 'nginx::resource::mailhost' do
|
|||
{
|
||||
:title => 'should set the IPv4 listen port',
|
||||
:attr => 'listen_port',
|
||||
:value => '45',
|
||||
:value => 45,
|
||||
:match => ' listen *:45;',
|
||||
},
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ describe 'nginx::resource::mailhost' do
|
|||
{
|
||||
:title => 'should set the IPv6 listen port',
|
||||
:attr => 'ipv6_listen_port',
|
||||
:value => '45',
|
||||
:value => 45,
|
||||
:match => ' listen [::]:45 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
|
@ -87,12 +87,6 @@ describe 'nginx::resource::mailhost' do
|
|||
:value => 'spdy',
|
||||
:match => ' listen [::]:80 spdy ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should not set the IPv6 listen options',
|
||||
:attr => 'ipv6_listen_options',
|
||||
:value => false,
|
||||
:match => ' listen [::]:80 ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set servername(s)',
|
||||
:attr => 'server_name',
|
||||
|
@ -120,11 +114,29 @@ describe 'nginx::resource::mailhost' do
|
|||
{
|
||||
:title => 'should set starttls',
|
||||
:attr => 'starttls',
|
||||
:value => 'test-starttls',
|
||||
:match => ' starttls test-starttls;',
|
||||
:value => 'on',
|
||||
:match => ' starttls on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set starttls',
|
||||
:attr => 'starttls',
|
||||
:value => 'only',
|
||||
:match => ' starttls only;',
|
||||
},
|
||||
{
|
||||
:title => 'should not enable SSL',
|
||||
:attr => 'starttls',
|
||||
:value => 'off',
|
||||
:notmatch => / ssl_session_timeout 5m;/,
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :default_params do {
|
||||
:listen_port => 25,
|
||||
:ipv6_enable => true,
|
||||
:ssl_cert => 'dummy.crt',
|
||||
:ssl_key => 'dummy.key',
|
||||
} end
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-header") }
|
||||
|
@ -156,7 +168,7 @@ describe 'nginx::resource::mailhost' do
|
|||
{
|
||||
:title => 'should not enable SSL',
|
||||
:attr => 'starttls',
|
||||
:value => false,
|
||||
:value => 'off',
|
||||
:notmatch => / ssl_session_timeout 5m;/,
|
||||
},
|
||||
{
|
||||
|
@ -222,7 +234,7 @@ describe 'nginx::resource::mailhost' do
|
|||
{
|
||||
:title => 'should set the IPv6 listen port',
|
||||
:attr => 'ipv6_listen_port',
|
||||
:value => '45',
|
||||
:value => 45,
|
||||
:match => ' listen [::]:45 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue