2015-09-05 17:40:02 +02:00
|
|
|
# encoding: utf-8
|
2015-10-06 18:55:44 +02:00
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
2015-09-05 17:40:02 +02:00
|
|
|
|
|
|
|
require 'helper'
|
2015-10-26 04:04:18 +01:00
|
|
|
require 'inspec/resource'
|
2015-09-05 17:40:02 +02:00
|
|
|
|
2015-10-26 04:04:18 +01:00
|
|
|
describe 'Inspec::Resources::Processes' do
|
2015-10-26 16:47:54 +01:00
|
|
|
it 'handles empty process results' do
|
|
|
|
resource = load_resource('processes', 'nothing')
|
|
|
|
_(resource.list).must_equal []
|
|
|
|
end
|
|
|
|
|
2015-09-22 18:33:05 +02:00
|
|
|
it 'verify processes resource' do
|
2016-10-17 15:23:50 +01:00
|
|
|
resource = MockLoader.new(:freebsd10).load_resource('processes', 'login -fp apop')
|
|
|
|
_(resource.list.length).must_equal 2
|
2016-05-13 11:16:45 +02:00
|
|
|
_(resource.list[0].to_h).must_equal({
|
2016-05-09 15:19:56 -04:00
|
|
|
label: nil,
|
2016-10-17 15:23:50 +01:00
|
|
|
pid: 7115,
|
|
|
|
cpu: '0.3',
|
2015-09-22 18:33:05 +02:00
|
|
|
mem: '0.0',
|
2016-10-17 15:23:50 +01:00
|
|
|
vsz: 2516588,
|
|
|
|
rss: 3052,
|
|
|
|
tty: 'ttys008',
|
|
|
|
stat: 'U',
|
|
|
|
start: 'Fri05PM',
|
|
|
|
time: '0:00.05',
|
2016-09-26 23:33:19 +05:30
|
|
|
user: 'root',
|
2016-10-17 15:23:50 +01:00
|
|
|
command: 'login -fp apop',
|
2016-05-13 11:16:45 +02:00
|
|
|
})
|
2015-09-05 17:40:02 +02:00
|
|
|
end
|
2015-12-07 09:39:48 +01:00
|
|
|
|
2016-05-09 15:19:56 -04:00
|
|
|
it 'verify processes resource on linux os' do
|
2016-10-17 15:23:50 +01:00
|
|
|
resource = MockLoader.new(:centos6).load_resource('processes', 'postgres: bifrost bifrost')
|
2016-05-13 11:16:45 +02:00
|
|
|
_(resource.list.length).must_equal 1
|
|
|
|
_(resource.list[0].to_h).must_equal({
|
2016-10-17 15:23:50 +01:00
|
|
|
label: 'system_u:system_r:init_t:s0',
|
|
|
|
pid: 5127,
|
2016-05-09 15:19:56 -04:00
|
|
|
cpu: '0.0',
|
2016-10-17 15:23:50 +01:00
|
|
|
mem: '0.2',
|
|
|
|
vsz: 547208,
|
|
|
|
rss: 5376,
|
2016-05-09 15:19:56 -04:00
|
|
|
tty: '?',
|
|
|
|
stat: 'Ss',
|
2016-10-17 15:23:50 +01:00
|
|
|
start: '10:54:22',
|
|
|
|
time: '00:00:00',
|
|
|
|
user: 'opscode-pgsql',
|
|
|
|
command: 'postgres: bifrost bifrost 127.0.0.1(43699) idle',
|
2016-05-13 11:16:45 +02:00
|
|
|
})
|
|
|
|
end
|
2016-05-09 15:19:56 -04:00
|
|
|
|
2016-05-13 11:16:45 +02:00
|
|
|
it 'access attributes of a process' do
|
2016-10-17 15:23:50 +01:00
|
|
|
resource = MockLoader.new(:centos6).load_resource('processes', 'postgres: bifrost bifrost')
|
2016-05-13 11:16:45 +02:00
|
|
|
process = resource.list[0]
|
2016-10-17 15:23:50 +01:00
|
|
|
process.user.must_equal 'opscode-pgsql'
|
|
|
|
process[:user].must_equal 'opscode-pgsql'
|
|
|
|
process['user'].must_equal 'opscode-pgsql'
|
|
|
|
process[-1].must_equal 'postgres: bifrost bifrost 127.0.0.1(43699) idle'
|
|
|
|
process[1].must_equal 5127
|
2016-05-09 15:19:56 -04:00
|
|
|
end
|
|
|
|
|
2015-12-07 09:39:48 +01:00
|
|
|
it 'retrieves the users and states as arrays' do
|
2016-10-17 15:23:50 +01:00
|
|
|
resource = MockLoader.new(:freebsd10).load_resource('processes', 'login -fp apop')
|
|
|
|
_(resource.users.sort).must_equal ['apop', 'root']
|
|
|
|
_(resource.states.sort).must_equal ['Ss', 'U']
|
2015-12-07 09:39:48 +01:00
|
|
|
end
|
2016-05-09 15:19:56 -04:00
|
|
|
|
|
|
|
it 'retrieves the users and states as arrays on linux os' do
|
2016-10-17 15:23:50 +01:00
|
|
|
resource = MockLoader.new(:centos6).load_resource('processes', 'postgres: bifrost bifrost')
|
|
|
|
_(resource.users.sort).must_equal ['opscode-pgsql']
|
|
|
|
_(resource.states.sort).must_equal ['Ss']
|
2016-05-09 15:19:56 -04:00
|
|
|
end
|
2016-11-29 11:00:43 +00:00
|
|
|
|
|
|
|
it 'command name matches with output (string)' do
|
|
|
|
resource = MockLoader.new(:centos6).load_resource('processes', 'mysqld')
|
|
|
|
_(resource.to_s).must_equal 'Processes mysqld'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'command name matches with output (regex)' do
|
|
|
|
resource = MockLoader.new(:centos6).load_resource('processes', /mysqld/)
|
|
|
|
_(resource.to_s).must_equal 'Processes /mysqld/'
|
|
|
|
end
|
2015-09-05 17:40:02 +02:00
|
|
|
end
|