2015-09-05 15:40:02 +00:00
|
|
|
# encoding: utf-8
|
2015-10-06 16:55:44 +00:00
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
2015-09-05 15:40:02 +00:00
|
|
|
|
|
|
|
require 'helper'
|
2015-10-26 03:04:18 +00:00
|
|
|
require 'inspec/resource'
|
2015-09-05 15:40:02 +00:00
|
|
|
|
2015-10-26 03:04:18 +00:00
|
|
|
describe 'Inspec::Resources::Processes' do
|
2015-10-26 15:47:54 +00:00
|
|
|
it 'handles empty process results' do
|
|
|
|
resource = load_resource('processes', 'nothing')
|
|
|
|
_(resource.list).must_equal []
|
|
|
|
end
|
|
|
|
|
2015-09-22 16:33:05 +00:00
|
|
|
it 'verify processes resource' do
|
2016-05-09 19:19:56 +00:00
|
|
|
resource = MockLoader.new(:freebsd10).load_resource('processes', '/bin/bash')
|
2016-05-13 09:16:45 +00:00
|
|
|
_(resource.list.length).must_equal 1
|
|
|
|
_(resource.list[0].to_h).must_equal({
|
2016-05-09 19:19:56 +00:00
|
|
|
label: nil,
|
2016-05-06 12:57:31 +00:00
|
|
|
pid: 1,
|
2015-09-22 16:33:05 +00:00
|
|
|
cpu: '0.0',
|
|
|
|
mem: '0.0',
|
2016-05-06 12:57:31 +00:00
|
|
|
vsz: 18084,
|
|
|
|
rss: 3228,
|
2015-09-22 16:33:05 +00:00
|
|
|
tty: '?',
|
|
|
|
stat: 'Ss',
|
|
|
|
start: '14:15',
|
|
|
|
time: '0:00',
|
2015-10-12 11:21:50 +00:00
|
|
|
command: '/bin/bash',
|
2016-09-26 18:03:19 +00:00
|
|
|
user: 'root',
|
2016-05-13 09:16:45 +00:00
|
|
|
})
|
2015-09-05 15:40:02 +00:00
|
|
|
end
|
2015-12-07 08:39:48 +00:00
|
|
|
|
2016-05-09 19:19:56 +00:00
|
|
|
it 'verify processes resource on linux os' do
|
|
|
|
resource = MockLoader.new(:centos6).load_resource('processes', '/sbin/init')
|
2016-05-13 09:16:45 +00:00
|
|
|
_(resource.list.length).must_equal 1
|
|
|
|
_(resource.list[0].to_h).must_equal({
|
2016-05-09 19:19:56 +00:00
|
|
|
label: 'system_u:system_r:kernel_t:s0',
|
|
|
|
pid: 1,
|
|
|
|
cpu: '0.0',
|
|
|
|
mem: '0.0',
|
|
|
|
vsz: 19232,
|
|
|
|
rss: 1492,
|
|
|
|
tty: '?',
|
|
|
|
stat: 'Ss',
|
|
|
|
start: 'May04',
|
|
|
|
time: '0:01',
|
|
|
|
command: '/sbin/init',
|
2016-09-26 18:03:19 +00:00
|
|
|
user: 'root',
|
2016-05-13 09:16:45 +00:00
|
|
|
})
|
|
|
|
end
|
2016-05-09 19:19:56 +00:00
|
|
|
|
2016-05-13 09:16:45 +00:00
|
|
|
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'
|
2016-09-26 18:03:19 +00:00
|
|
|
process[-1].must_equal 'root'
|
|
|
|
process[1].must_equal 1
|
2016-05-09 19:19:56 +00:00
|
|
|
end
|
|
|
|
|
2015-12-07 08:39:48 +00:00
|
|
|
it 'retrieves the users and states as arrays' do
|
2016-05-09 19:19:56 +00:00
|
|
|
resource = MockLoader.new(:freebsd10).load_resource('processes', 'svc')
|
2015-12-07 08:39:48 +00:00
|
|
|
_(resource.users.sort).must_equal ['noot']
|
|
|
|
_(resource.states.sort).must_equal ['S', 'Ss']
|
|
|
|
end
|
2016-05-09 19:19:56 +00:00
|
|
|
|
|
|
|
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
|
2015-09-05 15:40:02 +00:00
|
|
|
end
|