Skip to content

Commit

Permalink
Add Allow and ExtendedStatus support to mod_status
Browse files Browse the repository at this point in the history
I've extended the apache::mod::status class to accept an `$allow_from`
parameter similar to the existing apache::mod::info class, as well as
added an `$extended_status` parameter to control the ExtendedStatus
directive.

Added full testing support as well as updated the README.md to indicate
that the status class accepts additional parameters.
  • Loading branch information
dbeckham committed Oct 24, 2013
1 parent 132007c commit 555e0f7
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ There are many `apache::mod::[name]` classes within this module that can be decl
* `reqtimeout`
* `setenvif`
* `ssl`* (see [apache::mod::ssl](#class-apachemodssl) below)
* `status`
* `status`*
* `suphp`
* `userdir`*
* `worker`*
Expand Down
9 changes: 7 additions & 2 deletions manifests/mod/status.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
class apache::mod::status {
class apache::mod::status (
$allow_from = ['127.0.0.1','::1'],
$extended_status = 'On',
){
validate_array($allow_from)
validate_re(downcase($extended_status), '^(on|off)$', "${extended_status} is not supported for extended_status. Allowed values are 'On' and 'Off'.")
apache::mod { 'status': }
# Template uses no variables
# Template uses $allow_from, $extended_status
file { 'status.conf':
ensure => file,
path => "${apache::mod_dir}/status.conf",
Expand Down
133 changes: 133 additions & 0 deletions spec/classes/mod/status_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# This function is called inside the OS specific contexts
def general_status_specs
it { should contain_apache__mod("status") }

it do
should contain_file("status.conf").with_content(
"<Location /server-status>\n"\
" SetHandler server-status\n"\
" Order deny,allow\n"\
" Deny from all\n"\
" Allow from 127.0.0.1 ::1\n"\
"</Location>\n"\
"ExtendedStatus On\n"\
"\n"\
"<IfModule mod_proxy.c>\n"\
" # Show Proxy LoadBalancer status in mod_status\n"\
" ProxyStatus On\n"\
"</IfModule>\n"
)
end
end

describe 'apache::mod::status', :type => :class do
let :pre_condition do
'include apache'
end

context "on a Debian OS with default params" do
let :facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end

# Load the more generic tests for this context
general_status_specs()

it { should contain_file("status.conf").with({
:ensure => 'file',
:path => '/etc/apache2/mods-available/status.conf',
} ) }
it { should contain_file("status.conf symlink").with({
:ensure => 'link',
:path => '/etc/apache2/mods-enabled/status.conf',
} ) }
end

context "on a RedHat OS with default params" do
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end

# Load the more generic tests for this context
general_status_specs()

it { should contain_file("status.conf").with_path("/etc/httpd/conf.d/status.conf") }
end

context "with $allow_from => ['10.10.10.10','11.11.11.11'], $extended_status => 'Off'" do
let :facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end
let :params do
{
:allow_from => ['10.10.10.10','11.11.11.11'],
:extended_status => 'Off',
}
end
it do
should contain_file("status.conf").with_content(
"<Location /server-status>\n"\
" SetHandler server-status\n"\
" Order deny,allow\n"\
" Deny from all\n"\
" Allow from 10.10.10.10 11.11.11.11\n"\
"</Location>\n"\
"ExtendedStatus Off\n"\
"\n"\
"<IfModule mod_proxy.c>\n"\
" # Show Proxy LoadBalancer status in mod_status\n"\
" ProxyStatus On\n"\
"</IfModule>\n"
)
end
end

context "with $allow_from => '10.10.10.10'" do
let :facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end
let :params do
{ :allow_from => '10.10.10.10' }
end
it 'should expect to fail array validation' do
expect {
should contain_file("status.conf")
}.to raise_error(Puppet::Error)
end
end

context "with $extended_status => 'Yes'" do
let :facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end
let :params do
{ :extended_status => 'Yes' }
end
it 'should expect to fail regular expression validation' do
expect {
should contain_file("status.conf")
}.to raise_error(Puppet::Error)
end
end

end
4 changes: 2 additions & 2 deletions templates/mod/status.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1 ::1
Allow from <%= Array(@allow_from).join(" ") %>
</Location>
ExtendedStatus On
ExtendedStatus <%= @extended_status %>

<IfModule mod_proxy.c>
# Show Proxy LoadBalancer status in mod_status
Expand Down

0 comments on commit 555e0f7

Please sign in to comment.