mirror of
https://github.com/inspec/inspec
synced 2024-12-18 00:53:22 +00:00
dde4433933
we know all the fields + struct is fully compatible to the curren hash implementation
72 lines
2 KiB
Ruby
72 lines
2 KiB
Ruby
# encoding: utf-8
|
|
# author: Christoph Hartmann
|
|
# author: Dominik Richter
|
|
|
|
require 'helper'
|
|
require 'inspec/resource'
|
|
|
|
describe 'Inspec::Resources::Processes' do
|
|
it 'handles empty process results' do
|
|
resource = load_resource('processes', 'nothing')
|
|
_(resource.list).must_equal []
|
|
end
|
|
|
|
it 'verify processes resource' do
|
|
resource = MockLoader.new(:freebsd10).load_resource('processes', '/bin/bash')
|
|
_(resource.list.length).must_equal 1
|
|
_(resource.list[0].to_h).must_equal({
|
|
label: nil,
|
|
user: 'root',
|
|
pid: 1,
|
|
cpu: '0.0',
|
|
mem: '0.0',
|
|
vsz: 18084,
|
|
rss: 3228,
|
|
tty: '?',
|
|
stat: 'Ss',
|
|
start: '14:15',
|
|
time: '0:00',
|
|
command: '/bin/bash',
|
|
})
|
|
end
|
|
|
|
it 'verify processes resource on linux os' do
|
|
resource = MockLoader.new(:centos6).load_resource('processes', '/sbin/init')
|
|
_(resource.list.length).must_equal 1
|
|
_(resource.list[0].to_h).must_equal({
|
|
label: 'system_u:system_r:kernel_t:s0',
|
|
user: 'root',
|
|
pid: 1,
|
|
cpu: '0.0',
|
|
mem: '0.0',
|
|
vsz: 19232,
|
|
rss: 1492,
|
|
tty: '?',
|
|
stat: 'Ss',
|
|
start: 'May04',
|
|
time: '0:01',
|
|
command: '/sbin/init',
|
|
})
|
|
end
|
|
|
|
it 'access attributes of a process' do
|
|
resource = MockLoader.new(:centos6).load_resource('processes', '/sbin/init')
|
|
process = resource.list[0]
|
|
process.user.must_equal 'root'
|
|
process[:user].must_equal 'root'
|
|
process['user'].must_equal 'root'
|
|
process[1].must_equal 'root'
|
|
end
|
|
|
|
it 'retrieves the users and states as arrays' do
|
|
resource = MockLoader.new(:freebsd10).load_resource('processes', 'svc')
|
|
_(resource.users.sort).must_equal ['noot']
|
|
_(resource.states.sort).must_equal ['S', 'Ss']
|
|
end
|
|
|
|
it 'retrieves the users and states as arrays on linux os' do
|
|
resource = MockLoader.new(:centos6).load_resource('processes', 'crypto/0')
|
|
_(resource.users.sort).must_equal ['root']
|
|
_(resource.states.sort).must_equal ['S']
|
|
end
|
|
end
|