Skip to content

Commit

Permalink
Move functionality of ca_cert::enable to ca_cert::update
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Friderici committed Aug 22, 2023
1 parent 7a2ab4a commit 083b731
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 92 deletions.
1 change: 0 additions & 1 deletion manifests/ca.pp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
String[1] $ca_file_extension = lookup('ca_cert::ca::ca_file_extension'),
) {
include ca_cert::update
require ca_cert::enable

if ($ensure == 'trusted' or $ensure == 'distrusted') and $source == 'text' and !$ca_text {
fail('ca_text is required if source is set to text')
Expand Down
23 changes: 0 additions & 23 deletions manifests/enable.pp

This file was deleted.

20 changes: 19 additions & 1 deletion manifests/update.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
# Private class
class ca_cert::update {
require ca_cert
require ca_cert::enable

if ($facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['full'], '7') < 0) {
if $ca_cert::force_enable {
exec { 'enable_ca_trust':
command => 'update-ca-trust force-enable',
logoutput => 'on_failure',
path => ['/usr/sbin', '/usr/bin', '/bin'],
onlyif => 'update-ca-trust check | grep DISABLED',
}
}
else {
exec { 'enable_ca_trust':
command => 'update-ca-trust enable',
logoutput => 'on_failure',
path => ['/usr/sbin', '/usr/bin', '/bin'],
onlyif => 'update-ca-trust check | grep DISABLED',
}
}
}

exec { 'ca_cert_update':
command => $ca_cert::update_cmd,
Expand Down
63 changes: 0 additions & 63 deletions spec/classes/enable_spec.rb

This file was deleted.

3 changes: 1 addition & 2 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

it { is_expected.to compile }
it { is_expected.to contain_class('ca_cert::update') }
it { is_expected.to contain_class('ca_cert::enable') } # only here to reach 100% resource coverage, sourced by ca_cert::update

it do
is_expected.to contain_file('trusted_certs').only_with(
Expand Down Expand Up @@ -127,7 +126,7 @@
context 'with force_enable set to valid true' do
let(:params) { { force_enable: true } }

it { is_expected.to contain_exec('enable_ca_trust').with_command('update-ca-trust force-enable') } # from ca_cert::enable
it { is_expected.to contain_exec('enable_ca_trust').with_command('update-ca-trust force-enable') } # from ca_cert::update
end

context 'with ca_certs set to valid hash' do
Expand Down
32 changes: 31 additions & 1 deletion spec/classes/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

it { is_expected.to compile }
it { is_expected.to contain_class('ca_cert') }
it { is_expected.to contain_class('ca_cert::enable') }

# only here to reach 100% resource coverage
it { is_expected.to contain_ca_cert__ca('ca1') }
Expand All @@ -50,6 +49,19 @@
end
# /only here to reach 100% resource coverage

if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'].to_i < 7
it do
is_expected.to contain_exec('enable_ca_trust').only_with(
{
'command' => 'update-ca-trust enable',
'logoutput' => 'on_failure',
'path' => ['/usr/sbin', '/usr/bin', '/bin'],
'onlyif' => 'update-ca-trust check | grep DISABLED',
},
)
end
end

it do
is_expected.to contain_exec('ca_cert_update').only_with(
{
Expand All @@ -61,5 +73,23 @@
)
end
end

context "on #{os} when ca_cert::force_enable is true" do
let(:facts) { facts }
let(:pre_condition) { 'class { ca_cert: force_enable => true }' }

if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'].to_i < 7
it do
is_expected.to contain_exec('enable_ca_trust').only_with(
{
'command' => 'update-ca-trust force-enable',
'logoutput' => 'on_failure',
'path' => ['/usr/sbin', '/usr/bin', '/bin'],
'onlyif' => 'update-ca-trust check | grep DISABLED',
},
)
end
end
end
end
end
1 change: 0 additions & 1 deletion spec/defines/ca_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

it { is_expected.to compile }
it { is_expected.to contain_class('ca_cert::update') }
it { is_expected.to contain_class('ca_cert::enable') }

# only here to reach 100% resource coverage
it { is_expected.to contain_ca_cert__ca('ca1') }
Expand Down

0 comments on commit 083b731

Please sign in to comment.