mirror of
https://github.com/inspec/inspec
synced 2024-09-21 06:51:56 +00:00
Add version method to kernel_module
Signed-off-by: Andrey Aleksandrov <postgred@gmail.com>
This commit is contained in:
parent
185d1185fd
commit
3783357e50
5 changed files with 24 additions and 0 deletions
|
@ -49,6 +49,12 @@ The `be_loaded` matcher tests if the module is a loadable kernel module:
|
|||
|
||||
<%= partial "/shared/matcher_match" %>
|
||||
|
||||
### version
|
||||
|
||||
The `version` matcher tests if the named module version is on the system:
|
||||
|
||||
its(:version) { should eq '3.2.2' }
|
||||
|
||||
## Examples
|
||||
|
||||
The following examples show how to use this InSpec audit resource.
|
||||
|
@ -57,4 +63,5 @@ The following examples show how to use this InSpec audit resource.
|
|||
|
||||
describe kernel_module('bridge') do
|
||||
it { should be_loaded }
|
||||
its(:version) { should cmp >= '2.2.2' }
|
||||
end
|
||||
|
|
|
@ -36,6 +36,16 @@ module Inspec::Resources
|
|||
!found.nil?
|
||||
end
|
||||
|
||||
def version
|
||||
# default modinfo command
|
||||
modinfo_cmd = "modinfo -F version #{@module}"
|
||||
# command for CentOS 5 and sudo
|
||||
modinfo_cmd = "/sbin/modinfo -F version #{@module}" if inspec.os[:name] == 'centos' && inspec.os[:release].to_i == 5
|
||||
|
||||
cmd = inspec.command(modinfo_cmd)
|
||||
cmd.exit_status.zero? ? cmd.stdout.gsub("\n", '') : false
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Kernel Module #{@module}"
|
||||
end
|
||||
|
|
|
@ -269,6 +269,7 @@ class MockLoader
|
|||
"schtasks /query /v /fo csv /tn 'does-not-exist' | ConvertFrom-Csv | Select @{N='URI';E={$_.TaskName}},@{N='State';E={$_.Status.ToString()}},'Logon Mode','Last Result','Task To Run','Run As User','Scheduled Task State' | ConvertTo-Json -Compress" => cmd.call('schtasks-error'),
|
||||
# windows_task exist
|
||||
"schtasks /query /v /fo csv /tn 'WeLovePizza' | ConvertFrom-Csv | Select @{N='URI';E={$_.TaskName}},@{N='State';E={$_.Status.ToString()}},'Logon Mode','Last Result','Task To Run','Run As User','Scheduled Task State' | ConvertTo-Json -Compress" => cmd.call('schtasks-success'),
|
||||
'modinfo -F version dhcp' => cmd.call('modinfo-f-version-dhcp')
|
||||
}
|
||||
|
||||
@backend
|
||||
|
|
1
test/unit/mock/cmd/modinfo-f-version-dhcp
Normal file
1
test/unit/mock/cmd/modinfo-f-version-dhcp
Normal file
|
@ -0,0 +1 @@
|
|||
3.2.2
|
|
@ -20,4 +20,9 @@ describe 'Inspec::Resources::KernelModule' do
|
|||
resource = load_resource('kernel_module', 'dhcp')
|
||||
_(resource.loaded?).must_equal false
|
||||
end
|
||||
|
||||
it 'verify kernel_module version' do
|
||||
resource = load_resource('kernel_module', 'dhcp')
|
||||
_(resource.version).must_equal '3.2.2'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue