Skip to content

Commit d0db76f

Browse files
authored
Fix space_left/admin_space_left as percentages (#200)
* Fix space_left/admin_space_left as percentages Fixes #199 * Bump version
1 parent 21d2df7 commit d0db76f

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* Tue Jul 16 2024 Steven Pritchard <steve@sicura.us> - 8.14.3
2+
- Fix comparison of space_left and admin_space_left as percentages
3+
14
* Mon Jul 08 2024 Steven Pritchard <steve@sicura.us> - 8.14.2
25
- Remove calls to deprecated parameters (for Puppet 8 compatibility)
36

functions/validate_init_params.pp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@
77
# @return [None]
88
#
99
function auditd::validate_init_params {
10-
if (( '%' in $auditd::space_left ) or ( '%' in $auditd::admin_space_left ))
11-
{
10+
if (( '%' in $auditd::space_left ) or ( '%' in $auditd::admin_space_left )) {
1211
if $facts['auditd_version'] and ( versioncmp($facts['auditd_version'], '2.8.5') < 0 ) {
1312
fail('$space_left and $admin_space_left cannot contain "%" in auditd < 2.8.5')
1413
}
1514
}
1615

1716
if $auditd::space_left.type('generalized') == $auditd::admin_space_left.type('generalized') {
18-
if $auditd::admin_space_left > $auditd::space_left {
19-
fail('Auditd requires $space_left to be greater than $admin_space_left, otherwise it will not start')
17+
if $auditd::admin_space_left =~ String {
18+
if Integer($auditd::admin_space_left.regsubst(/%$/, '')) > Integer($auditd::space_left.regsubst(/%$/, '')) {
19+
fail('Auditd requires $space_left to be greater than $admin_space_left, otherwise it will not start')
20+
}
21+
} else {
22+
if $auditd::admin_space_left > $auditd::space_left {
23+
fail('Auditd requires $space_left to be greater than $admin_space_left, otherwise it will not start')
24+
}
2025
}
21-
}
22-
else {
26+
} else {
2327
debug('$auditd::space_left and $auditd::admin_space_left are not of the same data type, cannot compare for sanity')
2428
}
2529
}

metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simp-auditd",
3-
"version": "8.14.2",
3+
"version": "8.14.3",
44
"author": "SIMP Team",
55
"summary": "A SIMP puppet module for managing auditd and audispd",
66
"license": "Apache-2.0",

spec/classes/init_spec.rb

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,11 @@
8585
end
8686

8787
context 'auditd 2.8.5' do
88-
context 'with space_left as a percentage' do
89-
let(:facts) do
90-
base_facts.merge({
91-
:auditd_version => '2.8.5'
92-
})
93-
end
88+
let(:facts) do
89+
base_facts.merge(auditd_version: '2.8.5')
90+
end
9491

92+
context 'with space_left as a percentage' do
9593
let(:params) do
9694
{
9795
:space_left => '20%'
@@ -102,12 +100,6 @@
102100
end
103101

104102
context 'with admin_space_left as a percentage' do
105-
let(:facts) do
106-
base_facts.merge({
107-
:auditd_version => '2.8.5'
108-
})
109-
end
110-
111103
let(:params) do
112104
{
113105
:admin_space_left => '20%'
@@ -117,6 +109,29 @@
117109
it { is_expected.to compile.with_all_deps }
118110
it { is_expected.to contain_class('auditd').with_space_left('21%') }
119111
end
112+
113+
context 'auditd with space_left < admin_space_left as percentages' do
114+
let(:params) do
115+
{
116+
space_left: '5%',
117+
admin_space_left: '25%',
118+
}
119+
end
120+
121+
it { is_expected.to compile.and_raise_error(%r{Auditd requires \$space_left to be greater than \$admin_space_left, otherwise it will not start}) }
122+
end
123+
124+
context 'auditd with space_left > admin_space_left as percentages' do
125+
let(:params) do
126+
{
127+
space_left: '25%',
128+
admin_space_left: '5%',
129+
}
130+
end
131+
132+
it { is_expected.to compile.with_all_deps }
133+
it { is_expected.to contain_class('auditd').with_space_left('25%').with_admin_space_left('5%') }
134+
end
120135
end
121136

122137
context 'auditd with auditing disabled' do

0 commit comments

Comments
 (0)