Merge pull request #778 from vicinus/master

bugfix: convert integer strings to integer
This commit is contained in:
Matthew Haughton 2016-03-07 10:18:55 -05:00
commit 56e1c591bf
6 changed files with 92 additions and 21 deletions

View file

@ -48,7 +48,7 @@ define nginx::resource::mailhost (
$listen_options = undef, $listen_options = undef,
$ipv6_enable = false, $ipv6_enable = false,
$ipv6_listen_ip = '::', $ipv6_listen_ip = '::',
$ipv6_listen_port = '80', $ipv6_listen_port = 80,
$ipv6_listen_options = 'default ipv6only=on', $ipv6_listen_options = 'default ipv6only=on',
$ssl = false, $ssl = false,
$ssl_cert = undef, $ssl_cert = undef,
@ -69,7 +69,10 @@ define nginx::resource::mailhost (
mode => '0644', mode => '0644',
} }
if !is_integer($listen_port) { if is_string($listen_port) {
warning('DEPRECATION: String $listen_port must be converted to an integer. Integer string support will be removed in a future release.')
}
elsif !is_integer($listen_port) {
fail('$listen_port must be an integer.') fail('$listen_port must be an integer.')
} }
validate_re($ensure, '^(present|absent)$', validate_re($ensure, '^(present|absent)$',
@ -84,7 +87,10 @@ define nginx::resource::mailhost (
if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) { if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
fail('$ipv6_listen_ip must be a string or array.') fail('$ipv6_listen_ip must be a string or array.')
} }
if !is_integer($ipv6_listen_port) { if is_string($ipv6_listen_port) {
warning('DEPRECATION: String $ipv6_listen_port must be converted to an integer. Integer string support will be removed in a future release.')
}
elsif !is_integer($ipv6_listen_port) {
fail('$ipv6_listen_port must be an integer.') fail('$ipv6_listen_port must be an integer.')
} }
validate_string($ipv6_listen_options) validate_string($ipv6_listen_options)
@ -95,8 +101,13 @@ define nginx::resource::mailhost (
if ($ssl_key != undef) { if ($ssl_key != undef) {
validate_string($ssl_key) validate_string($ssl_key)
} }
if ($ssl_port != undef) and (!is_integer($ssl_port)) { if $ssl_port != undef {
fail('$ssl_port must be an integer.') if is_string($ssl_port) {
warning('DEPRECATION: String $ssl_port must be converted to an integer. Integer string support will be removed in a future release.')
}
elsif !is_integer($ssl_port) {
fail('$ssl_port must be an integer.')
}
} }
validate_re($starttls, '^(on|only|off)$', validate_re($starttls, '^(on|only|off)$',
"${starttls} is not supported for starttls. Allowed values are 'on', 'only' and 'off'.") "${starttls} is not supported for starttls. Allowed values are 'on', 'only' and 'off'.")
@ -131,7 +142,7 @@ define nginx::resource::mailhost (
notify => Class['::nginx::service'], notify => Class['::nginx::service'],
} }
if ($listen_port != $ssl_port) { if (($ssl_port == undef) or ($listen_port + 0) != ($ssl_port + 0)) {
concat::fragment { "${name}-header": concat::fragment { "${name}-header":
target => $config_file, target => $config_file,
content => template('nginx/mailhost/mailhost.erb'), content => template('nginx/mailhost/mailhost.erb'),

View file

@ -51,11 +51,11 @@
define nginx::resource::streamhost ( define nginx::resource::streamhost (
$ensure = 'present', $ensure = 'present',
$listen_ip = '*', $listen_ip = '*',
$listen_port = '80', $listen_port = 80,
$listen_options = undef, $listen_options = undef,
$ipv6_enable = false, $ipv6_enable = false,
$ipv6_listen_ip = '::', $ipv6_listen_ip = '::',
$ipv6_listen_port = '80', $ipv6_listen_port = 80,
$ipv6_listen_options = 'default ipv6only=on', $ipv6_listen_options = 'default ipv6only=on',
$proxy = undef, $proxy = undef,
$proxy_read_timeout = $::nginx::config::proxy_read_timeout, $proxy_read_timeout = $::nginx::config::proxy_read_timeout,
@ -74,7 +74,10 @@ define nginx::resource::streamhost (
if !(is_array($listen_ip) or is_string($listen_ip)) { if !(is_array($listen_ip) or is_string($listen_ip)) {
fail('$listen_ip must be a string or array.') fail('$listen_ip must be a string or array.')
} }
if !is_integer($listen_port) { if is_string($listen_port) {
warning('DEPRECATION: String $listen_port must be converted to an integer. Integer string support will be removed in a future release.')
}
elsif !is_integer($listen_port) {
fail('$listen_port must be an integer.') fail('$listen_port must be an integer.')
} }
if ($listen_options != undef) { if ($listen_options != undef) {
@ -84,7 +87,10 @@ define nginx::resource::streamhost (
if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) { if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
fail('$ipv6_listen_ip must be a string or array.') fail('$ipv6_listen_ip must be a string or array.')
} }
if !is_integer($ipv6_listen_port) { if is_string($ipv6_listen_port) {
warning('DEPRECATION: String $ipv6_listen_port must be converted to an integer. Integer string support will be removed in a future release.')
}
elsif !is_integer($ipv6_listen_port) {
fail('$ipv6_listen_port must be an integer.') fail('$ipv6_listen_port must be an integer.')
} }
validate_string($ipv6_listen_options) validate_string($ipv6_listen_options)

View file

@ -24,7 +24,7 @@
# ensure => present, # ensure => present,
# upstream => 'proxypass', # upstream => 'proxypass',
# server => $::ipaddress, # server => $::ipaddress,
# port => '3000', # port => 3000,
# } # }
# #
# #
@ -38,13 +38,20 @@ define nginx::resource::upstream::member (
$upstream, $upstream,
$server, $server,
$ensure = 'present', $ensure = 'present',
$port = '80', $port = 80,
$upstream_fail_timeout = '10s', $upstream_fail_timeout = '10s',
) { ) {
validate_re($ensure, '^(present|absent)$', validate_re($ensure, '^(present|absent)$',
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.") "${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
if is_string($port) {
warning('DEPRECATION: String $port must be converted to an integer. Integer string support will be removed in a future release.')
}
elsif !is_integer($port) {
fail('$port must be an integer.')
}
$ensure_real = $ensure ? { $ensure_real = $ensure ? {
'absent' => absent, 'absent' => absent,
default => present, default => present,

View file

@ -174,7 +174,7 @@
define nginx::resource::vhost ( define nginx::resource::vhost (
$ensure = 'present', $ensure = 'present',
$listen_ip = '*', $listen_ip = '*',
$listen_port = '80', $listen_port = 80,
$listen_options = undef, $listen_options = undef,
$listen_unix_socket_enable = false, $listen_unix_socket_enable = false,
$listen_unix_socket = '/var/run/nginx.sock', $listen_unix_socket = '/var/run/nginx.sock',
@ -184,7 +184,7 @@ define nginx::resource::vhost (
$location_deny = [], $location_deny = [],
$ipv6_enable = false, $ipv6_enable = false,
$ipv6_listen_ip = '::', $ipv6_listen_ip = '::',
$ipv6_listen_port = '80', $ipv6_listen_port = 80,
$ipv6_listen_options = 'default ipv6only=on', $ipv6_listen_options = 'default ipv6only=on',
$add_header = undef, $add_header = undef,
$ssl = false, $ssl = false,
@ -193,7 +193,7 @@ define nginx::resource::vhost (
$ssl_client_cert = undef, $ssl_client_cert = undef,
$ssl_dhparam = undef, $ssl_dhparam = undef,
$ssl_key = undef, $ssl_key = undef,
$ssl_port = '443', $ssl_port = 443,
$ssl_protocols = 'TLSv1 TLSv1.1 TLSv1.2', $ssl_protocols = 'TLSv1 TLSv1.1 TLSv1.2',
$ssl_buffer_size = undef, $ssl_buffer_size = undef,
$ssl_ciphers = 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA', $ssl_ciphers = 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA',
@ -279,7 +279,10 @@ define nginx::resource::vhost (
if !(is_array($listen_ip) or is_string($listen_ip)) { if !(is_array($listen_ip) or is_string($listen_ip)) {
fail('$listen_ip must be a string or array.') fail('$listen_ip must be a string or array.')
} }
if !is_integer($listen_port) { if is_string($listen_port) {
warning('DEPRECATION: String $listen_port must be converted to an integer. Integer string support will be removed in a future release.')
}
elsif !is_integer($listen_port) {
fail('$listen_port must be an integer.') fail('$listen_port must be an integer.')
} }
if ($listen_options != undef) { if ($listen_options != undef) {
@ -302,7 +305,10 @@ define nginx::resource::vhost (
if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) { if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
fail('$ipv6_listen_ip must be a string or array.') fail('$ipv6_listen_ip must be a string or array.')
} }
if !is_integer($ipv6_listen_port) { if is_string($ipv6_listen_port) {
warning('DEPRECATION: String $ipv6_listen_port must be converted to an integer. Integer string support will be removed in a future release.')
}
elsif !is_integer($ipv6_listen_port) {
fail('$ipv6_listen_port must be an integer.') fail('$ipv6_listen_port must be an integer.')
} }
validate_string($ipv6_listen_options) validate_string($ipv6_listen_options)
@ -326,7 +332,10 @@ define nginx::resource::vhost (
if ($ssl_key != undef) { if ($ssl_key != undef) {
validate_string($ssl_key) validate_string($ssl_key)
} }
if !is_integer($ssl_port) { if is_string($ssl_port) {
warning('DEPRECATION: String $ssl_port must be converted to an integer. Integer string support will be removed in a future release.')
}
elsif !is_integer($ssl_port) {
fail('$ssl_port must be an integer.') fail('$ssl_port must be an integer.')
} }
validate_string($ssl_protocols) validate_string($ssl_protocols)
@ -553,7 +562,7 @@ define nginx::resource::vhost (
notify => Class['::nginx::service'], notify => Class['::nginx::service'],
} }
$ssl_only = ($ssl == true) and ($ssl_port == $listen_port) $ssl_only = ($ssl == true) and (($ssl_port + 0) == ($listen_port + 0))
if $use_default_location == true { if $use_default_location == true {
# Create the default location reference for the vHost # Create the default location reference for the vHost
@ -617,7 +626,7 @@ define nginx::resource::vhost (
} }
} }
if ($listen_port != $ssl_port) { if (($listen_port + 0) != ($ssl_port + 0)) {
concat::fragment { "${name_sanitized}-header": concat::fragment { "${name_sanitized}-header":
target => $config_file, target => $config_file,
content => template('nginx/vhost/vhost_header.erb'), content => template('nginx/vhost/vhost_header.erb'),
@ -626,7 +635,7 @@ define nginx::resource::vhost (
} }
# Create a proper file close stub. # Create a proper file close stub.
if ($listen_port != $ssl_port) { if (($listen_port + 0) != ($ssl_port + 0)) {
concat::fragment { "${name_sanitized}-footer": concat::fragment { "${name_sanitized}-footer":
target => $config_file, target => $config_file,
content => template('nginx/vhost/vhost_footer.erb'), content => template('nginx/vhost/vhost_footer.erb'),

View file

@ -365,6 +365,15 @@ describe 'nginx::resource::mailhost' do
it { is_expected.to contain_concat__fragment("#{title}-header") } it { is_expected.to contain_concat__fragment("#{title}-header") }
end end
context 'when listen_port != "ssl_port"' do
let :params do default_params.merge({
:listen_port => 80,
:ssl_port => '443',
}) end
it { is_expected.to contain_concat__fragment("#{title}-header") }
end
context 'when listen_port == ssl_port' do context 'when listen_port == ssl_port' do
let :params do default_params.merge({ let :params do default_params.merge({
:listen_port => 80, :listen_port => 80,
@ -374,6 +383,15 @@ describe 'nginx::resource::mailhost' do
it { is_expected.not_to contain_concat__fragment("#{title}-header") } it { is_expected.not_to contain_concat__fragment("#{title}-header") }
end end
context 'when listen_port == "ssl_port"' do
let :params do default_params.merge({
:listen_port => 80,
:ssl_port => '80',
}) end
it { is_expected.not_to contain_concat__fragment("#{title}-header") }
end
context 'when ssl => true' do context 'when ssl => true' do
let :params do default_params.merge({ let :params do default_params.merge({
:ensure => 'absent', :ensure => 'absent',

View file

@ -855,6 +855,16 @@ describe 'nginx::resource::vhost' do
it { is_expected.not_to contain_concat__fragment("#{title}-footer") } it { is_expected.not_to contain_concat__fragment("#{title}-footer") }
end end
context 'when listen_port == "ssl_port"' do
let :params do default_params.merge({
:listen_port => 80,
:ssl_port => '80',
}) end
it { is_expected.not_to contain_concat__fragment("#{title}-header") }
it { is_expected.not_to contain_concat__fragment("#{title}-footer") }
end
context 'when listen_port != ssl_port' do context 'when listen_port != ssl_port' do
let :params do default_params.merge({ let :params do default_params.merge({
:listen_port => 80, :listen_port => 80,
@ -865,6 +875,16 @@ describe 'nginx::resource::vhost' do
it { is_expected.to contain_concat__fragment("#{title}-footer") } it { is_expected.to contain_concat__fragment("#{title}-footer") }
end end
context 'when listen_port != "ssl_port"' do
let :params do default_params.merge({
:listen_port => 80,
:ssl_port => '443',
}) end
it { is_expected.to contain_concat__fragment("#{title}-header") }
it { is_expected.to contain_concat__fragment("#{title}-footer") }
end
context 'when ensure => absent' do context 'when ensure => absent' do
let :params do default_params.merge({ let :params do default_params.merge({
:ensure => 'absent', :ensure => 'absent',