Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable core dumps if they are enabled via attribute #174

Merged
merged 1 commit into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion recipes/limits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@
mode '0440'
owner 'root'
group 'root'
not_if { node['os-hardening']['security']['kernel']['enable_core_dump'] }
if node['os-hardening']['security']['kernel']['enable_core_dump']
action :delete
end
end
4 changes: 3 additions & 1 deletion recipes/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
mode 0755
owner 'root'
group 'root'
not_if { node['os-hardening']['security']['kernel']['enable_core_dump'] }
if node['os-hardening']['security']['kernel']['enable_core_dump']
action :delete
end
end
55 changes: 45 additions & 10 deletions spec/recipes/limits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@

subject { chef_run }

it 'creates /etc/sysconfig/init' do
is_expected.to create_template(
'/etc/security/limits.d/10.hardcore.conf'
).with(
user: 'root',
group: 'root',
mode: '0440'
)
end

it 'creates /etc/security/limits.d directory' do
is_expected.to create_directory('/etc/security/limits.d').with(
user: 'root',
Expand All @@ -41,4 +31,49 @@
recursive: true
)
end

describe 'core dump setting' do
let(:enable_core_dump) { nil }
let(:chef_run) do
ChefSpec::ServerRunner.new do |node|
node.override['os-hardening']['security']['kernel']['enable_core_dump'] = enable_core_dump if enable_core_dump # rubocop:disable Metrics/LineLength
end.converge(described_recipe)
end

context 'enable_core_dump has its default value' do
it 'should create the settings file' do
is_expected.to create_template(
'/etc/security/limits.d/10.hardcore.conf'
).with(
user: 'root',
group: 'root',
mode: '0440'
)
end
end

context 'enable_core_dump is disabled' do
let(:enable_core_dump) { false }

it 'should create the settings file' do
is_expected.to create_template(
'/etc/security/limits.d/10.hardcore.conf'
).with(
user: 'root',
group: 'root',
mode: '0440'
)
end
end

context 'enable_core_dump is enabled' do
let(:enable_core_dump) { true }

it 'should remove the settings file' do
is_expected.to delete_template(
'/etc/security/limits.d/10.hardcore.conf'
)
end
end
end
end
46 changes: 37 additions & 9 deletions spec/recipes/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,46 @@
#

describe 'os-hardening::profile' do
cached(:chef_run) do
ChefSpec::ServerRunner.new.converge(described_recipe)
let(:enable_core_dump) { nil }
let(:chef_run) do
ChefSpec::ServerRunner.new do |node|
node.override['os-hardening']['security']['kernel']['enable_core_dump'] = enable_core_dump if enable_core_dump # rubocop:disable Metrics/LineLength
end.converge(described_recipe)
end

subject { chef_run }

it 'create /etc/profile.d/pinerolo_profile.sh' do
is_expected.to create_template('/etc/profile.d/pinerolo_profile.sh').with(
source: 'profile.conf.erb',
mode: 0755,
owner: 'root',
group: 'root'
)
context 'enable_core_dump has its default value' do
it 'create /etc/profile.d/pinerolo_profile.sh' do
is_expected.to create_template('/etc/profile.d/pinerolo_profile.sh').with(
source: 'profile.conf.erb',
mode: 0755,
owner: 'root',
group: 'root'
)
end
end

context 'enable_core_dump is disabled' do
let(:enable_core_dump) { false }

it 'create /etc/profile.d/pinerolo_profile.sh' do
is_expected.to create_template('/etc/profile.d/pinerolo_profile.sh').with(
source: 'profile.conf.erb',
mode: 0755,
owner: 'root',
group: 'root'
)
end
end

context 'enable_core_dump is enabled' do
let(:enable_core_dump) { true }

it 'should remove the settings file' do
is_expected.to delete_template(
'/etc/profile.d/pinerolo_profile.sh'
)
end
end
end