Skip to content

Commit d237c5f

Browse files
authored
Merge pull request #2150 from francetv/main
support for uri for severname with use_servername_for_filenames
2 parents 854698c + 88a998b commit d237c5f

File tree

2 files changed

+106
-2
lines changed

2 files changed

+106
-2
lines changed

manifests/vhost.pp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,14 @@
20642064
$priority_real = '25-'
20652065
}
20662066

2067+
# https://httpd.apache.org/docs/2.4/fr/mod/core.html#servername
2068+
# Syntax: ServerName [scheme://]domain-name|ip-address[:port]
2069+
# Sometimes, the server runs behind a device that processes SSL, such as a reverse proxy, load balancer or SSL offload
2070+
# appliance.
2071+
# When this is the case, specify the https:// scheme and the port number to which the clients connect in the ServerName
2072+
# directive to make sure that the server generates the correct self-referential URLs.
2073+
$normalized_servername = regsubst($servername, '(https?:\/\/)?([a-z0-9\/%_+.,#?!@&=-]+)(:?\d+)?', '\2', 'G')
2074+
20672075
# IAC-1186: A number of configuration and log file names are generated using the $name parameter. It is possible for
20682076
# the $name parameter to contain spaces, which could then be transferred to the log / config filenames. Although
20692077
# POSIX compliant, this can be cumbersome.
@@ -2085,8 +2093,8 @@
20852093
# and use the sanitized value of $servername for default log / config filenames.
20862094
$filename = $use_servername_for_filenames ? {
20872095
true => $use_port_for_filenames ? {
2088-
true => regsubst("${servername}-${port}", ' ', '_', 'G'),
2089-
false => regsubst($servername, ' ', '_', 'G'),
2096+
true => regsubst("${normalized_servername}-${port}", ' ', '_', 'G'),
2097+
false => regsubst($normalized_servername, ' ', '_', 'G'),
20902098
},
20912099
false => $name,
20922100
}

spec/defines/vhost_spec.rb

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,102 @@
15211521
)
15221522
}
15231523
end
1524+
context 'vhost with scheme and port in servername and use_servername_for_filenames' do
1525+
let :params do
1526+
{
1527+
'port' => '80',
1528+
'ip' => '127.0.0.1',
1529+
'ip_based' => true,
1530+
'servername' => 'https://www.example.com:443',
1531+
'docroot' => '/var/www/html',
1532+
'add_listen' => true,
1533+
'ensure' => 'present',
1534+
'use_servername_for_filenames' => true
1535+
}
1536+
end
1537+
1538+
it { is_expected.to compile }
1539+
it {
1540+
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
1541+
content: %r{^\s+ServerName https:\/\/www\.example\.com:443$},
1542+
)
1543+
}
1544+
it {
1545+
is_expected.to contain_concat('25-www.example.com.conf')
1546+
}
1547+
end
1548+
context 'vhost with scheme in servername and use_servername_for_filenames' do
1549+
let :params do
1550+
{
1551+
'port' => '80',
1552+
'ip' => '127.0.0.1',
1553+
'ip_based' => true,
1554+
'servername' => 'https://www.example.com',
1555+
'docroot' => '/var/www/html',
1556+
'add_listen' => true,
1557+
'ensure' => 'present',
1558+
'use_servername_for_filenames' => true
1559+
}
1560+
end
1561+
1562+
it { is_expected.to compile }
1563+
it {
1564+
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
1565+
content: %r{^\s+ServerName https:\/\/www\.example\.com$},
1566+
)
1567+
}
1568+
it {
1569+
is_expected.to contain_concat('25-www.example.com.conf')
1570+
}
1571+
end
1572+
context 'vhost with port in servername and use_servername_for_filenames' do
1573+
let :params do
1574+
{
1575+
'port' => '80',
1576+
'ip' => '127.0.0.1',
1577+
'ip_based' => true,
1578+
'servername' => 'www.example.com:443',
1579+
'docroot' => '/var/www/html',
1580+
'add_listen' => true,
1581+
'ensure' => 'present',
1582+
'use_servername_for_filenames' => true
1583+
}
1584+
end
1585+
1586+
it { is_expected.to compile }
1587+
it {
1588+
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
1589+
content: %r{^\s+ServerName www\.example\.com:443$},
1590+
)
1591+
}
1592+
it {
1593+
is_expected.to contain_concat('25-www.example.com.conf')
1594+
}
1595+
end
1596+
context 'vhost with servername and use_servername_for_filenames' do
1597+
let :params do
1598+
{
1599+
'port' => '80',
1600+
'ip' => '127.0.0.1',
1601+
'ip_based' => true,
1602+
'servername' => 'www.example.com',
1603+
'docroot' => '/var/www/html',
1604+
'add_listen' => true,
1605+
'ensure' => 'present',
1606+
'use_servername_for_filenames' => true
1607+
}
1608+
end
1609+
1610+
it { is_expected.to compile }
1611+
it {
1612+
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
1613+
content: %r{^\s+ServerName www\.example\.com$},
1614+
)
1615+
}
1616+
it {
1617+
is_expected.to contain_concat('25-www.example.com.conf')
1618+
}
1619+
end
15241620
context 'vhost with multiple ip addresses' do
15251621
let :params do
15261622
{

0 commit comments

Comments
 (0)