From a33b43270fc34dbc9bc1a00a9981aa2cec0c8635 Mon Sep 17 00:00:00 2001 From: jbond Date: Tue, 7 Oct 2025 19:05:30 +0200 Subject: [PATCH 1/2] http_port: Add support for IPv6 addresses When using an ipv6 address in the host we need to wrap the addresses win square brackets. --- manifests/http_port.pp | 8 ++++---- spec/defines/http_port_spec.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/manifests/http_port.pp b/manifests/http_port.pp index 7042eb2..24bdd13 100644 --- a/manifests/http_port.pp +++ b/manifests/http_port.pp @@ -61,10 +61,10 @@ fail('port parameter was not specified and could not be determined from title') } - if $_host != undef { - $_host_port = "${_host}:${_port}" - } else { - $_host_port = String($_port) + $_host_port = $_host ? { + undef => String($_port), + Stdlib::IP::Address::V6 => "[${_host}]:${_port}", + default => "${_host}:${_port}", } $protocol = $ssl ? { diff --git a/spec/defines/http_port_spec.rb b/spec/defines/http_port_spec.rb index 7e2a7db..d53354b 100644 --- a/spec/defines/http_port_spec.rb +++ b/spec/defines/http_port_spec.rb @@ -71,6 +71,19 @@ it { is_expected.to contain_concat_fragment('squid_http_port_host:1650').with_content(%r{^http_port\s+1650$}) } end + context 'with IPv6' do + let(:title) { 'ipv6_host' } + let(:params) do + { + host: '2001:db8::1', + port: 1650, + } + end + + # Wrap IPv6addresses in square brackets + it { is_expected.to contain_concat_fragment('squid_http_port_ipv6_host').with_content(%r{^http_port\s+\[2001:db8::1\]:1650$}) } + end + context 'without a port specified' do let(:title) { 'garbage' } let(:params) do From f3cd061f70b3513d4d9c493f9b05b6555d835841 Mon Sep 17 00:00:00 2001 From: John Bond Date: Wed, 8 Oct 2025 14:05:56 +0200 Subject: [PATCH 2/2] Update spec/defines/http_port_spec.rb Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- spec/defines/http_port_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/defines/http_port_spec.rb b/spec/defines/http_port_spec.rb index d53354b..500812f 100644 --- a/spec/defines/http_port_spec.rb +++ b/spec/defines/http_port_spec.rb @@ -80,7 +80,7 @@ } end - # Wrap IPv6addresses in square brackets + # Wrap IPv6 addresses in square brackets it { is_expected.to contain_concat_fragment('squid_http_port_ipv6_host').with_content(%r{^http_port\s+\[2001:db8::1\]:1650$}) } end