diff --git a/lib/resources/auditd.rb b/lib/resources/auditd.rb index 9af107e11..a192f5fdc 100644 --- a/lib/resources/auditd.rb +++ b/lib/resources/auditd.rb @@ -30,11 +30,26 @@ module Inspec::Resources " def initialize - @content = inspec.command('/sbin/auditctl -l').stdout.chomp + unless inspec.command('/sbin/auditctl').exist? + raise Inspec::Exceptions::ResourceFailed, + 'Command `/sbin/auditctl` does not exist' + end + + auditctl_cmd = '/sbin/auditctl -l' + result = inspec.command(auditctl_cmd) + + if result.exit_status != 0 + raise Inspec::Exceptions::ResourceFailed, + "Command `#{auditctl_cmd}` failed with error: #{result.stderr}" + end + + @content = result.stdout @params = [] if @content =~ /^LIST_RULES:/ - return skip_resource 'The version of audit is outdated. The `auditd` resource supports versions of audit >= 2.3.5' + raise Inspec::Exceptions::RsourceFailed, + 'The version of audit is outdated.' \ + 'The `auditd` resource supports versions of audit >= 2.3.' end parse_content end diff --git a/test/helper.rb b/test/helper.rb index 99e00c7a4..1f8141178 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -218,6 +218,7 @@ class MockLoader 'bash -c \'type "/test/path/pip"\'' => empty.call, 'bash -c \'type "Rscript"\'' => empty.call, 'bash -c \'type "perl"\'' => empty.call, + 'bash -c \'type "/sbin/auditctl"\'' => empty.call, 'type "pwsh"' => empty.call, 'type "netstat"' => empty.call, 'sh -c \'find /etc/apache2/ports.conf -type l -maxdepth 1\'' => empty.call,