]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/spec/acceptance/mod_security_spec.rb
add Openstack modules to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / apache / spec / acceptance / mod_security_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'apache::mod::security class', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) or (fact('osfamily') == 'Debian' and (fact('lsbdistcodename') == 'squeeze' or fact('lsbdistcodename') == 'lucid' or fact('lsbdistcodename') == 'precise'))) do
4   case fact('osfamily')
5   when 'Debian'
6     mod_dir      = '/etc/apache2/mods-available'
7     service_name = 'apache2'
8     package_name = 'apache2'
9   when 'RedHat'
10     mod_dir      = '/etc/httpd/conf.d'
11     service_name = 'httpd'
12     package_name = 'httpd'
13   end
14
15   context "default mod_security config" do
16     if fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') =~ /(5|6)/
17       it 'adds epel' do
18         pp = "class { 'epel': }"
19         apply_manifest(pp, :catch_failures => true)
20       end
21     end
22
23     it 'succeeds in puppeting mod_security' do
24       pp= <<-EOS
25         host { 'modsec.example.com': ip => '127.0.0.1', }
26         class { 'apache': }
27         class { 'apache::mod::security': }
28         apache::vhost { 'modsec.example.com':
29           port    => '80',
30           docroot => '/var/www/html',
31         }
32         file { '/var/www/html/index.html':
33           ensure  => file,
34           content => 'Index page',
35         }
36       EOS
37       apply_manifest(pp, :catch_failures => true)
38     end
39
40     describe service(service_name) do
41       it { is_expected.to be_enabled }
42       it { is_expected.to be_running }
43     end
44
45     describe package(package_name) do
46       it { is_expected.to be_installed }
47     end
48
49     describe file("#{mod_dir}/security.conf") do
50       it { is_expected.to contain "mod_security2.c" }
51     end
52
53     it 'should return index page' do
54       shell('/usr/bin/curl -A beaker modsec.example.com:80') do |r|
55         expect(r.stdout).to match(/Index page/)
56         expect(r.exit_code).to eq(0)
57       end
58     end
59
60     it 'should block query with SQL' do
61       shell '/usr/bin/curl -A beaker -f modsec.example.com:80?SELECT%20*FROM%20mysql.users', :acceptable_exit_codes => [22]
62     end
63
64   end #default mod_security config
65
66   context "mod_security should allow disabling by vhost" do
67     it 'succeeds in puppeting mod_security' do
68       pp= <<-EOS
69         host { 'modsec.example.com': ip => '127.0.0.1', }
70         class { 'apache': }
71         class { 'apache::mod::security': }
72         apache::vhost { 'modsec.example.com':
73           port    => '80',
74           docroot => '/var/www/html',
75         }
76         file { '/var/www/html/index.html':
77           ensure  => file,
78           content => 'Index page',
79         }
80       EOS
81       apply_manifest(pp, :catch_failures => true)
82     end
83
84     describe service(service_name) do
85       it { is_expected.to be_enabled }
86       it { is_expected.to be_running }
87     end
88
89     describe file("#{mod_dir}/security.conf") do
90       it { is_expected.to contain "mod_security2.c" }
91     end
92
93     it 'should block query with SQL' do
94       shell '/usr/bin/curl -A beaker -f modsec.example.com:80?SELECT%20*FROM%20mysql.users', :acceptable_exit_codes => [22]
95     end
96
97     it 'should disable mod_security per vhost' do
98       pp= <<-EOS
99         class { 'apache': }
100         class { 'apache::mod::security': }
101         apache::vhost { 'modsec.example.com':
102           port                 => '80',
103           docroot              => '/var/www/html',
104           modsec_disable_vhost => true,
105         }
106       EOS
107       apply_manifest(pp, :catch_failures => true)
108     end
109
110     it 'should return index page' do
111       shell('/usr/bin/curl -A beaker -f modsec.example.com:80?SELECT%20*FROM%20mysql.users') do |r|
112         expect(r.stdout).to match(/Index page/)
113         expect(r.exit_code).to eq(0)
114       end
115     end
116   end #mod_security should allow disabling by vhost
117
118   context "mod_security should allow disabling by ip" do
119     it 'succeeds in puppeting mod_security' do
120       pp= <<-EOS
121         host { 'modsec.example.com': ip => '127.0.0.1', }
122         class { 'apache': }
123         class { 'apache::mod::security': }
124         apache::vhost { 'modsec.example.com':
125           port    => '80',
126           docroot => '/var/www/html',
127         }
128         file { '/var/www/html/index.html':
129           ensure  => file,
130           content => 'Index page',
131         }
132       EOS
133       apply_manifest(pp, :catch_failures => true)
134     end
135
136     describe service(service_name) do
137       it { is_expected.to be_enabled }
138       it { is_expected.to be_running }
139     end
140
141     describe file("#{mod_dir}/security.conf") do
142       it { is_expected.to contain "mod_security2.c" }
143     end
144
145     it 'should block query with SQL' do
146       shell '/usr/bin/curl -A beaker -f modsec.example.com:80?SELECT%20*FROM%20mysql.users', :acceptable_exit_codes => [22]
147     end
148
149     it 'should disable mod_security per vhost' do
150       pp= <<-EOS
151         class { 'apache': }
152         class { 'apache::mod::security': }
153         apache::vhost { 'modsec.example.com':
154           port               => '80',
155           docroot            => '/var/www/html',
156           modsec_disable_ips => [ '127.0.0.1' ],
157         }
158       EOS
159       apply_manifest(pp, :catch_failures => true)
160     end
161
162     it 'should return index page' do
163       shell('/usr/bin/curl -A beaker modsec.example.com:80') do |r|
164         expect(r.stdout).to match(/Index page/)
165         expect(r.exit_code).to eq(0)
166       end
167     end
168   end #mod_security should allow disabling by ip
169
170   context "mod_security should allow disabling by id" do
171     it 'succeeds in puppeting mod_security' do
172       pp= <<-EOS
173         host { 'modsec.example.com': ip => '127.0.0.1', }
174         class { 'apache': }
175         class { 'apache::mod::security': }
176         apache::vhost { 'modsec.example.com':
177           port    => '80',
178           docroot => '/var/www/html',
179         }
180         file { '/var/www/html/index.html':
181           ensure  => file,
182           content => 'Index page',
183         }
184         file { '/var/www/html/index2.html':
185           ensure  => file,
186           content => 'Page 2',
187         }
188       EOS
189       apply_manifest(pp, :catch_failures => true)
190     end
191
192     describe service(service_name) do
193       it { is_expected.to be_enabled }
194       it { is_expected.to be_running }
195     end
196
197     describe file("#{mod_dir}/security.conf") do
198       it { is_expected.to contain "mod_security2.c" }
199     end
200
201     it 'should block query with SQL' do
202       shell '/usr/bin/curl -A beaker -f modsec.example.com:80?SELECT%20*FROM%20mysql.users', :acceptable_exit_codes => [22]
203     end
204
205     it 'should disable mod_security per vhost' do
206       pp= <<-EOS
207         class { 'apache': }
208         class { 'apache::mod::security': }
209         apache::vhost { 'modsec.example.com':
210           port               => '80',
211           docroot            => '/var/www/html',
212           modsec_disable_ids => [ '950007' ],
213         }
214       EOS
215       apply_manifest(pp, :catch_failures => true)
216     end
217
218     it 'should return index page' do
219       shell('/usr/bin/curl -A beaker -f modsec.example.com:80?SELECT%20*FROM%20mysql.users') do |r|
220         expect(r.stdout).to match(/Index page/)
221         expect(r.exit_code).to eq(0)
222       end
223     end
224
225   end #mod_security should allow disabling by id
226
227
228 end #apache::mod::security class