Skip to content

Commit 88a998b

Browse files
committed
authorize uri for severname with use_servername_for_filenames
fix rubocop fix rspec fix rubocop fix rubocop
1 parent 74898ed commit 88a998b

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
@@ -1516,6 +1516,102 @@
15161516
)
15171517
}
15181518
end
1519+
context 'vhost with scheme and port in servername and use_servername_for_filenames' do
1520+
let :params do
1521+
{
1522+
'port' => '80',
1523+
'ip' => '127.0.0.1',
1524+
'ip_based' => true,
1525+
'servername' => 'https://www.example.com:443',
1526+
'docroot' => '/var/www/html',
1527+
'add_listen' => true,
1528+
'ensure' => 'present',
1529+
'use_servername_for_filenames' => true
1530+
}
1531+
end
1532+
1533+
it { is_expected.to compile }
1534+
it {
1535+
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
1536+
content: %r{^\s+ServerName https:\/\/www\.example\.com:443$},
1537+
)
1538+
}
1539+
it {
1540+
is_expected.to contain_concat('25-www.example.com.conf')
1541+
}
1542+
end
1543+
context 'vhost with scheme in servername and use_servername_for_filenames' do
1544+
let :params do
1545+
{
1546+
'port' => '80',
1547+
'ip' => '127.0.0.1',
1548+
'ip_based' => true,
1549+
'servername' => 'https://www.example.com',
1550+
'docroot' => '/var/www/html',
1551+
'add_listen' => true,
1552+
'ensure' => 'present',
1553+
'use_servername_for_filenames' => true
1554+
}
1555+
end
1556+
1557+
it { is_expected.to compile }
1558+
it {
1559+
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
1560+
content: %r{^\s+ServerName https:\/\/www\.example\.com$},
1561+
)
1562+
}
1563+
it {
1564+
is_expected.to contain_concat('25-www.example.com.conf')
1565+
}
1566+
end
1567+
context 'vhost with port in servername and use_servername_for_filenames' do
1568+
let :params do
1569+
{
1570+
'port' => '80',
1571+
'ip' => '127.0.0.1',
1572+
'ip_based' => true,
1573+
'servername' => 'www.example.com:443',
1574+
'docroot' => '/var/www/html',
1575+
'add_listen' => true,
1576+
'ensure' => 'present',
1577+
'use_servername_for_filenames' => true
1578+
}
1579+
end
1580+
1581+
it { is_expected.to compile }
1582+
it {
1583+
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
1584+
content: %r{^\s+ServerName www\.example\.com:443$},
1585+
)
1586+
}
1587+
it {
1588+
is_expected.to contain_concat('25-www.example.com.conf')
1589+
}
1590+
end
1591+
context 'vhost with servername and use_servername_for_filenames' do
1592+
let :params do
1593+
{
1594+
'port' => '80',
1595+
'ip' => '127.0.0.1',
1596+
'ip_based' => true,
1597+
'servername' => 'www.example.com',
1598+
'docroot' => '/var/www/html',
1599+
'add_listen' => true,
1600+
'ensure' => 'present',
1601+
'use_servername_for_filenames' => true
1602+
}
1603+
end
1604+
1605+
it { is_expected.to compile }
1606+
it {
1607+
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
1608+
content: %r{^\s+ServerName www\.example\.com$},
1609+
)
1610+
}
1611+
it {
1612+
is_expected.to contain_concat('25-www.example.com.conf')
1613+
}
1614+
end
15191615
context 'vhost with multiple ip addresses' do
15201616
let :params do
15211617
{

0 commit comments

Comments
 (0)