Skip to content

Commit 67a35d3

Browse files
committed
Use a stricter data type on apache::vhost::aliases
This also implements a real test on the rendered template. It appears it was passing in something invalid ever since it was introduced in f1d64a0.
1 parent 77d3e6c commit 67a35d3

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

manifests/vhost.pp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@
18031803
Optional[Array[Hash]] $access_logs = undef,
18041804
Boolean $use_servername_for_filenames = false,
18051805
Boolean $use_port_for_filenames = false,
1806-
Optional[Variant[Array[Hash],Hash,String]] $aliases = undef,
1806+
Array[Hash[String[1], String[1]]] $aliases = [],
18071807
Optional[Variant[Hash, Array[Variant[Array,Hash]]]] $directories = undef,
18081808
Boolean $error_log = true,
18091809
Optional[String] $error_log_file = undef,
@@ -2222,7 +2222,6 @@
22222222

22232223
# Load mod_alias if needed and not yet loaded
22242224
if ($scriptalias or $scriptaliases != [])
2225-
or ($aliases and $aliases != [])
22262225
or ($redirect_source and $redirect_dest)
22272226
or ($redirectmatch_regexp or $redirectmatch_status or $redirectmatch_dest) {
22282227
if ! defined(Class['apache::mod::alias']) and ($ensure == 'present') {
@@ -2376,7 +2375,9 @@
23762375

23772376
# Template uses:
23782377
# - $aliases
2379-
if $aliases and ! empty($aliases) {
2378+
if ! empty($aliases) and $ensure == 'present' {
2379+
include apache::mod::alias
2380+
23802381
concat::fragment { "${name}-aliases":
23812382
target => "${priority_real}${filename}.conf",
23822383
order => 20,

spec/acceptance/default_mods_spec.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ class { 'apache':
3838
}
3939
apache::vhost { 'defaults.example.com':
4040
docroot => '#{apache_hash['doc_root']}/defaults',
41-
aliases => {
42-
alias => '/css',
43-
path => '#{apache_hash['doc_root']}/css',
44-
},
41+
aliases => [
42+
{
43+
alias => '/css',
44+
path => '#{apache_hash['doc_root']}/css',
45+
},
46+
],
4547
directories => [
4648
{
4749
'path' => "#{apache_hash['doc_root']}/admin",
@@ -76,10 +78,12 @@ class { 'apache':
7678
}
7779
apache::vhost { 'defaults.example.com':
7880
docroot => '#{apache_hash['doc_root']}/defaults',
79-
aliases => {
80-
alias => '/css',
81-
path => '#{apache_hash['doc_root']}/css',
82-
},
81+
aliases => [
82+
{
83+
alias => '/css',
84+
path => '#{apache_hash['doc_root']}/css',
85+
},
86+
],
8387
setenv => 'TEST1 one',
8488
}
8589
MANIFEST

spec/defines/vhost_spec.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@
109109
'access_log_syslog' => true,
110110
'access_log_format' => '%h %l %u %t \"%r\" %>s %b',
111111
'access_log_env_var' => '',
112-
'aliases' => '/image',
112+
'aliases' => [
113+
{
114+
'alias' => '/image',
115+
'path' => '/rspec/image',
116+
},
117+
],
113118
'directories' => [
114119
{
115120
'path' => '/var/www/files',
@@ -619,7 +624,11 @@
619624
)
620625
}
621626
it { is_expected.to contain_concat__fragment('rspec.example.com-docroot') }
622-
it { is_expected.to contain_concat__fragment('rspec.example.com-aliases') }
627+
it {
628+
is_expected.to contain_concat__fragment('rspec.example.com-aliases').with(
629+
content: %r{^\s+Alias /image "/rspec/image"$},
630+
)
631+
}
623632
it { is_expected.to contain_concat__fragment('rspec.example.com-itk') }
624633
it { is_expected.to contain_concat__fragment('rspec.example.com-fallbackresource') }
625634
it { is_expected.to contain_concat__fragment('rspec.example.com-directories') }

templates/vhost/_aliases.erb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
<% if @aliases and ! @aliases.empty? -%>
21
## Alias declarations for resources outside the DocumentRoot
3-
<%- [@aliases].flatten.compact.each do |alias_statement| -%>
4-
<%- if alias_statement["path"] != '' -%>
5-
<%- if alias_statement["alias"] and alias_statement["alias"] != '' -%>
2+
<%- @aliases.each do |alias_statement| -%>
3+
<%- if alias_statement["path"] -%>
4+
<%- if alias_statement["alias"] -%>
65
Alias <%= alias_statement["alias"] %> "<%= alias_statement["path"] %>"
7-
<%- elsif alias_statement["aliasmatch"] and alias_statement["aliasmatch"] != '' -%>
6+
<%- elsif alias_statement["aliasmatch"] -%>
87
AliasMatch <%= alias_statement["aliasmatch"] %> "<%= alias_statement["path"] %>"
9-
<%- elsif alias_statement["scriptalias"] and alias_statement["scriptalias"] != '' -%>
8+
<%- elsif alias_statement["scriptalias"] -%>
109
ScriptAlias <%= alias_statement["scriptalias"] %> "<%= alias_statement["path"] %>"
11-
<%- elsif alias_statement["scriptaliasmatch"] and alias_statement["scriptaliasmatch"] != '' -%>
10+
<%- elsif alias_statement["scriptaliasmatch"] -%>
1211
ScriptAliasMatch <%= alias_statement["scriptaliasmatch"] %> "<%= alias_statement["path"] %>"
1312
<%- end -%>
1413
<%- end -%>
1514
<%- end -%>
16-
<% end -%>

0 commit comments

Comments
 (0)