|
211 | 211 | end
|
212 | 212 | end
|
213 | 213 |
|
| 214 | + it 'should set UsePAM to yes per default' do |
| 215 | + expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UsePAM yes') |
| 216 | + end |
| 217 | + |
| 218 | + describe 'UsePAM option' do |
| 219 | + let(:use_pam) { true } |
| 220 | + |
| 221 | + let(:chef_run) do |
| 222 | + ChefSpec::ServerRunner.new(platform: platform, version: version) do |node| |
| 223 | + node.normal['ssh-hardening']['ssh']['server']['use_pam'] = use_pam |
| 224 | + end.converge(described_recipe) |
| 225 | + end |
| 226 | + |
| 227 | + context 'when running on Ubuntu' do |
| 228 | + let(:platform) { 'ubuntu' } |
| 229 | + let(:version) { '16.04' } |
| 230 | + |
| 231 | + it 'does not invoke any SELinux resources' do |
| 232 | + expect(chef_run).not_to create_directory('/tmp/ssh-hardening-file-cache/ssh-hardening') |
| 233 | + expect(chef_run).not_to render_file('/tmp/ssh-hardening-file-cache/ssh-hardening/ssh_password.te') |
| 234 | + expect(chef_run).not_to run_execute('remove selinux policy') |
| 235 | + expect(chef_run).not_to run_bash('build selinux package and install it') |
| 236 | + expect(chef_run).not_to install_package('policycoreutils-python') |
| 237 | + end |
| 238 | + |
| 239 | + context 'when use_pam is set to true' do |
| 240 | + let(:use_pam) { true } |
| 241 | + |
| 242 | + it 'should set UsePAM to yes' do |
| 243 | + expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UsePAM yes') |
| 244 | + end |
| 245 | + end |
| 246 | + |
| 247 | + context 'when use_pam is set to false' do |
| 248 | + let(:use_pam) { false } |
| 249 | + |
| 250 | + it 'should set UsePAM to no' do |
| 251 | + expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UsePAM no') |
| 252 | + end |
| 253 | + end |
| 254 | + end |
| 255 | + |
| 256 | + context 'when running on CentOS' do |
| 257 | + let(:platform) { 'centos' } |
| 258 | + let(:version) { '7.2.1511' } |
| 259 | + |
| 260 | + let(:selinux_disabled_or_policy_removed) { false } |
| 261 | + let(:selinux_enabled_and_policy_installed) { false } |
| 262 | + |
| 263 | + before do |
| 264 | + stub_command('getenforce | grep -vq Disabled && semodule -l | grep -q ssh_password').and_return(selinux_enabled_and_policy_installed) |
| 265 | + stub_command('getenforce | grep -q Disabled || semodule -l | grep -q ssh_password').and_return(selinux_disabled_or_policy_removed) |
| 266 | + end |
| 267 | + |
| 268 | + it 'should install selinux tools' do |
| 269 | + expect(chef_run).to install_package('policycoreutils-python') |
| 270 | + end |
| 271 | + |
| 272 | + context 'when use_pam is set to true' do |
| 273 | + let(:use_pam) { true } |
| 274 | + |
| 275 | + it 'should set UsePAM to yes' do |
| 276 | + expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UsePAM yes') |
| 277 | + end |
| 278 | + |
| 279 | + context 'when selinux is disabled or policy is removed' do |
| 280 | + let(:selinux_enabled_and_policy_installed) { false } |
| 281 | + |
| 282 | + it 'should not invoke the policy removal' do |
| 283 | + expect(chef_run).not_to run_execute('remove selinux policy') |
| 284 | + end |
| 285 | + end |
| 286 | + |
| 287 | + context 'when selinux is enabled and policy is present' do |
| 288 | + let(:selinux_enabled_and_policy_installed) { true } |
| 289 | + |
| 290 | + it 'should invoke the policy removal' do |
| 291 | + expect(chef_run).to run_execute('remove selinux policy') |
| 292 | + end |
| 293 | + end |
| 294 | + end |
| 295 | + |
| 296 | + context 'when use_pam is set to false' do |
| 297 | + let(:use_pam) { false } |
| 298 | + |
| 299 | + it 'should set UsePAM to no' do |
| 300 | + expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UsePAM no') |
| 301 | + end |
| 302 | + |
| 303 | + it 'should create cache directory for policy files' do |
| 304 | + expect(chef_run).to create_directory('/tmp/ssh-hardening-file-cache/ssh-hardening') |
| 305 | + end |
| 306 | + |
| 307 | + it 'should create selinux source policy file' do |
| 308 | + expect(chef_run).to render_file('/tmp/ssh-hardening-file-cache/ssh-hardening/ssh_password.te') |
| 309 | + end |
| 310 | + |
| 311 | + context 'when selinux is disabled or policy is installed' do |
| 312 | + let(:selinux_disabled_or_policy_removed) { true } |
| 313 | + |
| 314 | + it 'should not install the policy' do |
| 315 | + expect(chef_run).not_to run_bash('build selinux package and install it') |
| 316 | + end |
| 317 | + end |
| 318 | + |
| 319 | + context 'when selinux is enabled and policy is not installed' do |
| 320 | + let(:selinux_disabled_or_policy_removed) { false } |
| 321 | + |
| 322 | + it 'should install the policy' do |
| 323 | + expect(chef_run).to run_bash('build selinux package and install it') |
| 324 | + end |
| 325 | + end |
| 326 | + end |
| 327 | + end |
| 328 | + end |
| 329 | + |
214 | 330 | describe 'debian banner' do
|
215 | 331 | cached(:chef_run) do
|
216 | 332 | ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe)
|
|
235 | 351 | end
|
236 | 352 |
|
237 | 353 | context 'with centos as platform' do
|
| 354 | + before do |
| 355 | + stub_command('getenforce | grep -vq Disabled && semodule -l | grep -q ssh_password').and_return(true) |
| 356 | + end |
| 357 | + |
238 | 358 | cached(:chef_run) do
|
239 | 359 | ChefSpec::ServerRunner.new(platform: 'centos', version: '7.2.1511') do |node|
|
240 | 360 | node.normal['ssh-hardening']['ssh']['server']['os_banner'] = true
|
|
0 commit comments