From 8d37c059d23434ca1f249aef5ffd5d07220e49fc Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Wed, 14 Dec 2016 15:21:03 -0700 Subject: [PATCH] Fix os_transport_url with single hosts array If an array with a single host is passed into the hosts param, the function was erroring because the host was getting converted to a string when it was checking for bracketing for ipv6. This change checks the type and fixes the case where a single host is being passed so it continues to function. Change-Id: I91b9959a6f71b4e6885e55a568116cc28cf16ddd Closes-Bug: #1650042 --- lib/puppet/parser/functions/os_transport_url.rb | 3 +++ spec/functions/os_transport_url_spec.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/puppet/parser/functions/os_transport_url.rb b/lib/puppet/parser/functions/os_transport_url.rb index a19c7cc4..33636eb7 100644 --- a/lib/puppet/parser/functions/os_transport_url.rb +++ b/lib/puppet/parser/functions/os_transport_url.rb @@ -113,6 +113,9 @@ EOS if v.include?('hosts') hosts = function_normalize_ip_for_uri([v['hosts']]) + # normalize_ip_for_uri may return a string, so check that we still have an + # array + hosts = [hosts] if hosts.kind_of?(String) hosts = hosts.map{ |h| "#{h}:#{v['port']}" } if v.include?('port') if parts.include?(:userinfo) parts[:hostinfo] = hosts.map { |h| "#{parts[:userinfo]}@#{h}" }.join(',') diff --git a/spec/functions/os_transport_url_spec.rb b/spec/functions/os_transport_url_spec.rb index 888dfe53..bf13c87a 100644 --- a/spec/functions/os_transport_url_spec.rb +++ b/spec/functions/os_transport_url_spec.rb @@ -37,6 +37,19 @@ describe 'os_transport_url' do context 'creates the correct transport URI' do + it 'with a single host array for hosts' do + is_expected.to run.with_params({ + 'transport' => 'rabbit', + 'hosts' => [ '127.0.0.1' ], + 'port' => '5672', + 'username' => 'guest', + 'password' => 's3cr3t', + 'virtual_host' => 'virt', + 'ssl' => '1', + 'query' => { 'read_timeout' => '60' }, + }).and_return('rabbit://guest:s3cr3t@127.0.0.1:5672/virt?read_timeout=60&ssl=1') + end + it 'with all params for a single host' do is_expected.to run.with_params({ 'transport' => 'rabbit',