Skip to content

Commit

Permalink
Merge pull request #2518 from ekohl/fix-serveralias-string
Browse files Browse the repository at this point in the history
Correct handling of $serveraliases as string
  • Loading branch information
smortex authored Jan 10, 2024
2 parents 61b7ceb + 6da804a commit 928f91d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,7 @@
concat::fragment { "${name}-serveralias":
target => "${priority_real}${filename}.conf",
order => 210,
content => epp('apache/vhost/_serveralias.epp', { 'serveraliases' => $serveraliases }),
content => epp('apache/vhost/_serveralias.epp', { 'serveraliases' => [$serveraliases].flatten }),
}
}

Expand Down
24 changes: 23 additions & 1 deletion spec/defines/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@
}

it { is_expected.to contain_concat__fragment('rspec.example.com-scriptalias') }
it { is_expected.to contain_concat__fragment('rspec.example.com-serveralias') }
it { is_expected.to contain_concat__fragment('rspec.example.com-serveralias').with_content(%r{^ ServerAlias test-example\.com$}) }

it {
expect(subject).to contain_concat__fragment('rspec.example.com-setenv')
Expand Down Expand Up @@ -1221,6 +1221,28 @@
it { is_expected.not_to contain_concat__fragment('NameVirtualHost 127.0.0.1:8080') }
end

describe 'serveraliases parameter' do
let(:params) { default_params.merge(serveraliases: serveraliases) }

context 'with a string' do
let(:serveraliases) { 'alias.example.com' }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_concat__fragment('rspec.example.com-serveralias').with_content(%r{^ ServerAlias alias\.example\.com$}) }
end

context 'with an array' do
let(:serveraliases) { ['alias1.example.com', 'alias2.example.com'] }

it { is_expected.to compile.with_all_deps }
it do
expect(subject).to contain_concat__fragment('rspec.example.com-serveralias')
.with_content(%r{^ ServerAlias alias1\.example\.com$})
.with_content(%r{^ ServerAlias alias2\.example\.com$})
end
end
end

context 'vhost with multiple ip addresses, multiple ports' do
let :params do
{
Expand Down
3 changes: 2 additions & 1 deletion templates/vhost/_serveralias.epp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<%- | Array[String] $serveraliases | -%>
<% unless $serveraliases.empty { -%>

## Server aliases
<%- Array($serveraliases).each |$serveralias| { -%>
<%- $serveraliases.each |$serveralias| { -%>
ServerAlias <%= $serveralias %>
<%- } -%>
<% } -%>

0 comments on commit 928f91d

Please sign in to comment.