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

bugfix: convert integer strings to integer #778

Merged
merged 1 commit into from
Mar 7, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions manifests/resource/mailhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
$listen_options = undef,
$ipv6_enable = false,
$ipv6_listen_ip = '::',
$ipv6_listen_port = '80',
$ipv6_listen_port = 80,
$ipv6_listen_options = 'default ipv6only=on',
$ssl = false,
$ssl_cert = undef,
Expand All @@ -69,7 +69,10 @@
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.')
}
validate_re($ensure, '^(present|absent)$',
Expand All @@ -84,7 +87,10 @@
if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
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.')
}
validate_string($ipv6_listen_options)
Expand All @@ -95,8 +101,13 @@
if ($ssl_key != undef) {
validate_string($ssl_key)
}
if ($ssl_port != undef) and (!is_integer($ssl_port)) {
fail('$ssl_port must be an integer.')
if $ssl_port != undef {
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)$',
"${starttls} is not supported for starttls. Allowed values are 'on', 'only' and 'off'.")
Expand Down Expand Up @@ -131,7 +142,7 @@
notify => Class['::nginx::service'],
}

if ($listen_port != $ssl_port) {
if (($ssl_port == undef) or ($listen_port + 0) != ($ssl_port + 0)) {
concat::fragment { "${name}-header":
target => $config_file,
content => template('nginx/mailhost/mailhost.erb'),
Expand Down
14 changes: 10 additions & 4 deletions manifests/resource/streamhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
define nginx::resource::streamhost (
$ensure = 'present',
$listen_ip = '*',
$listen_port = '80',
$listen_port = 80,
$listen_options = undef,
$ipv6_enable = false,
$ipv6_listen_ip = '::',
$ipv6_listen_port = '80',
$ipv6_listen_port = 80,
$ipv6_listen_options = 'default ipv6only=on',
$proxy = undef,
$proxy_read_timeout = $::nginx::config::proxy_read_timeout,
Expand All @@ -74,7 +74,10 @@
if !(is_array($listen_ip) or is_string($listen_ip)) {
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.')
}
if ($listen_options != undef) {
Expand All @@ -84,7 +87,10 @@
if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
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.')
}
validate_string($ipv6_listen_options)
Expand Down
11 changes: 9 additions & 2 deletions manifests/resource/upstream/member.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# ensure => present,
# upstream => 'proxypass',
# server => $::ipaddress,
# port => '3000',
# port => 3000,
# }
#
#
Expand All @@ -38,13 +38,20 @@
$upstream,
$server,
$ensure = 'present',
$port = '80',
$port = 80,
$upstream_fail_timeout = '10s',
) {

validate_re($ensure, '^(present|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 ? {
'absent' => absent,
default => present,
Expand Down
27 changes: 18 additions & 9 deletions manifests/resource/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
define nginx::resource::vhost (
$ensure = 'present',
$listen_ip = '*',
$listen_port = '80',
$listen_port = 80,
$listen_options = undef,
$listen_unix_socket_enable = false,
$listen_unix_socket = '/var/run/nginx.sock',
Expand All @@ -184,7 +184,7 @@
$location_deny = [],
$ipv6_enable = false,
$ipv6_listen_ip = '::',
$ipv6_listen_port = '80',
$ipv6_listen_port = 80,
$ipv6_listen_options = 'default ipv6only=on',
$add_header = undef,
$ssl = false,
Expand All @@ -193,7 +193,7 @@
$ssl_client_cert = undef,
$ssl_dhparam = undef,
$ssl_key = undef,
$ssl_port = '443',
$ssl_port = 443,
$ssl_protocols = 'TLSv1 TLSv1.1 TLSv1.2',
$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',
Expand Down Expand Up @@ -279,7 +279,10 @@
if !(is_array($listen_ip) or is_string($listen_ip)) {
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.')
}
if ($listen_options != undef) {
Expand All @@ -302,7 +305,10 @@
if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
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.')
}
validate_string($ipv6_listen_options)
Expand All @@ -326,7 +332,10 @@
if ($ssl_key != undef) {
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.')
}
validate_string($ssl_protocols)
Expand Down Expand Up @@ -553,7 +562,7 @@
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 {
# Create the default location reference for the vHost
Expand Down Expand Up @@ -617,7 +626,7 @@
}
}

if ($listen_port != $ssl_port) {
if (($listen_port + 0) != ($ssl_port + 0)) {
concat::fragment { "${name_sanitized}-header":
target => $config_file,
content => template('nginx/vhost/vhost_header.erb'),
Expand All @@ -626,7 +635,7 @@
}

# Create a proper file close stub.
if ($listen_port != $ssl_port) {
if (($listen_port + 0) != ($ssl_port + 0)) {
concat::fragment { "${name_sanitized}-footer":
target => $config_file,
content => template('nginx/vhost/vhost_footer.erb'),
Expand Down
18 changes: 18 additions & 0 deletions spec/defines/resource_mailhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,15 @@
it { is_expected.to contain_concat__fragment("#{title}-header") }
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
let :params do default_params.merge({
:listen_port => 80,
Expand All @@ -374,6 +383,15 @@
it { is_expected.not_to contain_concat__fragment("#{title}-header") }
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
let :params do default_params.merge({
:ensure => 'absent',
Expand Down
20 changes: 20 additions & 0 deletions spec/defines/resource_vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,16 @@
it { is_expected.not_to contain_concat__fragment("#{title}-footer") }
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
let :params do default_params.merge({
:listen_port => 80,
Expand All @@ -865,6 +875,16 @@
it { is_expected.to contain_concat__fragment("#{title}-footer") }
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
let :params do default_params.merge({
:ensure => 'absent',
Expand Down