]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/spec/classes/mod/status_spec.rb
add Openstack modules to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / apache / spec / classes / mod / status_spec.rb
1 require 'spec_helper'
2
3 # Helper function for testing the contents of `status.conf`
4 def status_conf_spec(allow_from, extended_status, status_path)
5   it do
6     is_expected.to contain_file("status.conf").with_content(
7       "<Location #{status_path}>\n"\
8       "    SetHandler server-status\n"\
9       "    Order deny,allow\n"\
10       "    Deny from all\n"\
11       "    Allow from #{Array(allow_from).join(' ')}\n"\
12       "</Location>\n"\
13       "ExtendedStatus #{extended_status}\n"\
14       "\n"\
15       "<IfModule mod_proxy.c>\n"\
16       "    # Show Proxy LoadBalancer status in mod_status\n"\
17       "    ProxyStatus On\n"\
18       "</IfModule>\n"
19     )
20   end
21 end
22
23 describe 'apache::mod::status', :type => :class do
24   let :pre_condition do
25     'include apache'
26   end
27
28   context "on a Debian OS with default params" do
29     let :facts do
30       {
31         :osfamily               => 'Debian',
32         :operatingsystemrelease => '6',
33         :concat_basedir         => '/dne',
34         :lsbdistcodename        => 'squeeze',
35         :operatingsystem        => 'Debian',
36         :id                     => 'root',
37         :kernel                 => 'Linux',
38         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
39         :is_pe                  => false,
40       }
41     end
42
43     it { is_expected.to contain_apache__mod("status") }
44
45     status_conf_spec(["127.0.0.1", "::1"], "On", "/server-status")
46
47     it { is_expected.to contain_file("status.conf").with({
48       :ensure => 'file',
49       :path   => '/etc/apache2/mods-available/status.conf',
50     } ) }
51
52     it { is_expected.to contain_file("status.conf symlink").with({
53       :ensure => 'link',
54       :path   => '/etc/apache2/mods-enabled/status.conf',
55     } ) }
56
57   end
58
59   context "on a RedHat OS with default params" do
60     let :facts do
61       {
62         :osfamily               => 'RedHat',
63         :operatingsystemrelease => '6',
64         :concat_basedir         => '/dne',
65         :operatingsystem        => 'RedHat',
66         :id                     => 'root',
67         :kernel                 => 'Linux',
68         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
69         :is_pe                  => false,
70       }
71     end
72
73     it { is_expected.to contain_apache__mod("status") }
74
75     status_conf_spec(["127.0.0.1", "::1"], "On", "/server-status")
76
77     it { is_expected.to contain_file("status.conf").with_path("/etc/httpd/conf.d/status.conf") }
78
79   end
80
81   context "with custom parameters $allow_from => ['10.10.10.10','11.11.11.11'], $extended_status => 'Off', $status_path => '/custom-status'" do
82     let :facts do
83       {
84         :osfamily               => 'Debian',
85         :operatingsystemrelease => '6',
86         :concat_basedir         => '/dne',
87         :lsbdistcodename        => 'squeeze',
88         :operatingsystem        => 'Debian',
89         :id                     => 'root',
90         :kernel                 => 'Linux',
91         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
92         :is_pe                  => false,
93       }
94     end
95     let :params do
96       {
97         :allow_from => ['10.10.10.10','11.11.11.11'],
98         :extended_status => 'Off',
99         :status_path => '/custom-status',
100       }
101     end
102
103     status_conf_spec(["10.10.10.10", "11.11.11.11"], "Off", "/custom-status")
104
105   end
106
107   context "with valid parameter type $allow_from => ['10.10.10.10']" do
108     let :facts do
109       {
110         :osfamily               => 'Debian',
111         :operatingsystemrelease => '6',
112         :concat_basedir         => '/dne',
113         :lsbdistcodename        => 'squeeze',
114         :operatingsystem        => 'Debian',
115         :id                     => 'root',
116         :kernel                 => 'Linux',
117         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
118         :is_pe                  => false,
119       }
120     end
121     let :params do
122       { :allow_from => ['10.10.10.10'] }
123     end
124     it 'should expect to succeed array validation' do
125       expect {
126         is_expected.to contain_file("status.conf")
127       }.not_to raise_error()
128     end
129   end
130
131   context "with invalid parameter type $allow_from => '10.10.10.10'" do
132     let :facts do
133       {
134         :osfamily               => 'Debian',
135         :operatingsystemrelease => '6',
136         :concat_basedir         => '/dne',
137         :operatingsystem        => 'Debian',
138         :id                     => 'root',
139         :kernel                 => 'Linux',
140         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
141         :is_pe                  => false,
142       }
143     end
144     let :params do
145       { :allow_from => '10.10.10.10' }
146     end
147     it 'should expect to fail array validation' do
148       expect {
149         is_expected.to contain_file("status.conf")
150       }.to raise_error(Puppet::Error)
151     end
152   end
153
154   # Only On or Off are valid options
155   ['On', 'Off'].each do |valid_param|
156     context "with valid value $extended_status => '#{valid_param}'" do
157       let :facts do
158         {
159           :osfamily               => 'Debian',
160           :operatingsystemrelease => '6',
161           :concat_basedir         => '/dne',
162           :lsbdistcodename        => 'squeeze',
163           :operatingsystem        => 'Debian',
164           :id                     => 'root',
165           :kernel                 => 'Linux',
166           :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
167           :is_pe                  => false,
168         }
169       end
170       let :params do
171         { :extended_status => valid_param }
172       end
173       it 'should expect to succeed regular expression validation' do
174         expect {
175           is_expected.to contain_file("status.conf")
176         }.not_to raise_error()
177       end
178     end
179   end
180
181   ['Yes', 'No'].each do |invalid_param|
182     context "with invalid value $extended_status => '#{invalid_param}'" do
183       let :facts do
184         {
185           :osfamily               => 'Debian',
186           :operatingsystemrelease => '6',
187           :concat_basedir         => '/dne',
188           :operatingsystem        => 'Debian',
189           :id                     => 'root',
190           :kernel                 => 'Linux',
191           :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
192           :is_pe                  => false,
193         }
194       end
195       let :params do
196         { :extended_status => invalid_param }
197       end
198       it 'should expect to fail regular expression validation' do
199         expect {
200           is_expected.to contain_file("status.conf")
201         }.to raise_error(Puppet::Error)
202       end
203     end
204   end
205
206 end