2015-10-06 16:55:44 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
2015-09-14 13:15:32 +00:00
|
|
|
|
|
|
|
require 'helper'
|
2015-10-26 03:04:18 +00:00
|
|
|
require 'inspec/resource'
|
2015-09-14 13:15:32 +00:00
|
|
|
|
2015-10-26 03:04:18 +00:00
|
|
|
describe 'Inspec::Resources::Service' do
|
2016-02-14 17:18:40 +00:00
|
|
|
let(:runlevels) { {0=>false, 1=>false, 2=>true, 3=>true, 4=>true, 5=>true, 6=>false} }
|
2015-09-14 13:15:32 +00:00
|
|
|
|
2015-09-22 16:33:05 +00:00
|
|
|
# windows
|
2015-09-23 14:30:48 +00:00
|
|
|
it 'verify service parsing' do
|
|
|
|
resource = MockLoader.new(:windows).load_resource('service', 'dhcp')
|
|
|
|
srv = { name: 'dhcp', description: 'DHCP Client', installed: true, running: true, enabled: true, type: 'windows' }
|
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
2015-09-23 20:32:31 +00:00
|
|
|
|
2015-09-25 08:31:42 +00:00
|
|
|
# ubuntu 14.04 with upstart
|
2015-09-23 20:32:31 +00:00
|
|
|
it 'verify ubuntu package parsing' do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource('service', 'ssh')
|
2015-09-25 09:25:17 +00:00
|
|
|
srv = { name: 'ssh', description: nil, installed: true, running: true, enabled: true, type: 'upstart' }
|
2015-09-23 20:32:31 +00:00
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
2015-09-25 10:48:21 +00:00
|
|
|
|
2016-01-20 14:54:36 +00:00
|
|
|
it 'verify ubuntu package parsing with default upstart_service' do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource('upstart_service', 'ssh')
|
|
|
|
srv = { name: 'ssh', description: nil, installed: true, running: true, enabled: true, type: 'upstart' }
|
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2015-09-25 08:31:42 +00:00
|
|
|
# ubuntu 15.04 with systemd
|
|
|
|
it 'verify ubuntu package parsing' do
|
|
|
|
resource = MockLoader.new(:ubuntu1504).load_resource('service', 'sshd')
|
|
|
|
srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
|
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2016-01-20 14:54:36 +00:00
|
|
|
it 'verify ubuntu package parsing with default systemd_service' do
|
2016-01-20 13:33:24 +00:00
|
|
|
resource = MockLoader.new(:ubuntu1504).load_resource('systemd_service', 'sshd')
|
|
|
|
srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
|
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2016-01-20 14:54:36 +00:00
|
|
|
# centos 6 with sysv
|
2015-09-25 09:47:59 +00:00
|
|
|
it 'verify centos 6 package parsing' do
|
|
|
|
resource = MockLoader.new(:centos6).load_resource('service', 'sshd')
|
2016-02-14 17:18:40 +00:00
|
|
|
srv = { name: 'sshd', description: nil, installed: true, running: true, enabled: true, runlevels: runlevels, type: 'sysv' }
|
2015-09-25 09:47:59 +00:00
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2016-01-20 14:54:36 +00:00
|
|
|
it 'verify centos 6 package parsing with default sysv_service' do
|
|
|
|
resource = MockLoader.new(:centos6).load_resource('sysv_service', 'sshd')
|
2016-02-14 17:18:40 +00:00
|
|
|
srv = { name: 'sshd', description: nil, installed: true, running: true, enabled: true, runlevels: runlevels, type: 'sysv' }
|
2016-01-20 14:54:36 +00:00
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2015-09-25 10:48:21 +00:00
|
|
|
# centos 7 with systemd
|
2015-09-25 09:51:21 +00:00
|
|
|
it 'verify centos 7 package parsing' do
|
2015-09-25 10:48:21 +00:00
|
|
|
resource = MockLoader.new(:centos7).load_resource('service', 'sshd')
|
|
|
|
srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
|
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
2015-09-24 21:32:46 +00:00
|
|
|
|
2016-01-21 10:41:48 +00:00
|
|
|
it 'verify centos 7 package parsing with systemd_service and service_ctl override' do
|
|
|
|
resource = MockLoader.new(:centos7).load_resource('systemd_service', 'sshd', '/path/to/systemctl')
|
|
|
|
srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
|
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2015-09-25 10:53:40 +00:00
|
|
|
# freebsd
|
|
|
|
it 'verify freebsd10 package parsing' do
|
|
|
|
resource = MockLoader.new(:freebsd10).load_resource('service', 'sendmail')
|
|
|
|
srv = { name: 'sendmail', description: nil, installed: true, running: true, enabled: true, type: 'bsd-init' }
|
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2016-01-20 14:54:36 +00:00
|
|
|
it 'verify freebsd10 package parsing with default bsd_service' do
|
|
|
|
resource = MockLoader.new(:freebsd10).load_resource('bsd_service', 'sendmail')
|
|
|
|
srv = { name: 'sendmail', description: nil, installed: true, running: true, enabled: true, type: 'bsd-init' }
|
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2015-09-24 21:37:31 +00:00
|
|
|
# arch linux with systemd
|
|
|
|
it 'verify arch linux package parsing' do
|
|
|
|
resource = MockLoader.new(:arch).load_resource('service', 'sshd')
|
|
|
|
srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
|
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2015-09-25 09:47:59 +00:00
|
|
|
# debian 7 with systemv
|
|
|
|
it 'verify debian 7 package parsing' do
|
|
|
|
resource = MockLoader.new(:debian7).load_resource('service', 'sshd')
|
2016-02-14 17:18:40 +00:00
|
|
|
srv = { name: 'sshd', description: nil, installed: true, running: true, enabled: true, runlevels: runlevels, type: 'sysv' }
|
2015-09-25 09:47:59 +00:00
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2015-09-24 21:32:46 +00:00
|
|
|
# debian 8 with systemd
|
2016-01-20 14:54:36 +00:00
|
|
|
it 'verify debian 8 package parsing' do
|
2015-09-25 09:50:48 +00:00
|
|
|
resource = MockLoader.new(:debian8).load_resource('service', 'sshd')
|
2015-09-24 21:32:46 +00:00
|
|
|
srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
|
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2015-09-25 10:51:12 +00:00
|
|
|
# macos test
|
2016-01-20 14:54:36 +00:00
|
|
|
it 'verify mac osx package parsing' do
|
2015-09-25 10:51:12 +00:00
|
|
|
resource = MockLoader.new(:osx104).load_resource('service', 'ssh')
|
2015-09-25 09:51:21 +00:00
|
|
|
srv = { name: 'org.openbsd.ssh-agent', description: nil, installed: true, running: true, enabled: true, type: 'darwin' }
|
2015-09-25 10:51:12 +00:00
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2016-01-22 10:52:06 +00:00
|
|
|
it 'verify mac osx package parsing with not-running service' do
|
|
|
|
resource = MockLoader.new(:osx104).load_resource('service', 'FilesystemUI')
|
|
|
|
srv = { name: 'com.apple.FilesystemUI', description: nil, installed: true, running: false, enabled: true, type: 'darwin' }
|
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal false
|
|
|
|
end
|
|
|
|
|
2016-01-20 14:54:36 +00:00
|
|
|
it 'verify mac osx package parsing with default launchd_service' do
|
|
|
|
resource = MockLoader.new(:osx104).load_resource('launchd_service', 'ssh')
|
|
|
|
srv = { name: 'org.openbsd.ssh-agent', description: nil, installed: true, running: true, enabled: true, type: 'darwin' }
|
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2015-12-03 03:08:49 +00:00
|
|
|
# wrlinux
|
|
|
|
it 'verify wrlinux package parsing' do
|
|
|
|
resource = MockLoader.new(:wrlinux).load_resource('service', 'sshd')
|
2016-02-14 17:18:40 +00:00
|
|
|
srv = { name: 'sshd', description: nil, installed: true, running: true, enabled: true, runlevels: runlevels, type: 'sysv' }
|
2015-12-03 03:08:49 +00:00
|
|
|
_(resource.info).must_equal srv
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.enabled?).must_equal true
|
|
|
|
_(resource.running?).must_equal true
|
|
|
|
end
|
|
|
|
|
2016-01-20 14:54:36 +00:00
|
|
|
|
2015-09-23 14:32:51 +00:00
|
|
|
# unknown OS
|
|
|
|
it 'verify package handling on unsupported os' do
|
|
|
|
resource = MockLoader.new(:undefined).load_resource('service', 'dhcp')
|
|
|
|
_(resource.installed?).must_equal false
|
|
|
|
_(resource.info).must_equal nil
|
|
|
|
end
|
2016-02-14 17:37:20 +00:00
|
|
|
|
|
|
|
# runlevel detection
|
|
|
|
describe 'runlevels on centos 6 (system V)' do
|
|
|
|
let(:service) { MockLoader.new(:centos6).load_resource('service', 'sshd') }
|
|
|
|
|
|
|
|
it 'grabs all runlevels' do
|
|
|
|
service.runlevels.keys.must_equal [0, 1, 2, 3, 4, 5, 6]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'grabs runlevels via filter nil' do
|
|
|
|
service.runlevels(nil).keys.must_equal [0, 1, 2, 3, 4, 5, 6]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'grabs runlevels by number' do
|
|
|
|
service.runlevels(3).keys.must_equal [3]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'grabs runlevels by multiple numbers' do
|
|
|
|
service.runlevels(3, 4, 8).keys.must_equal [3, 4]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'grabs runlevels via regex' do
|
|
|
|
service.runlevels(/[5-9]/).keys.must_equal [5, 6]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'checks enabled true if all services are enabled' do
|
|
|
|
service.runlevels(2, 4).enabled?.must_equal true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'checks enabled false if some services are not enabled' do
|
|
|
|
service.runlevels(1, 4).enabled?.must_equal false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'checks disabled true if all services are disabled' do
|
|
|
|
service.runlevels(0, 1).disabled?.must_equal true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'checks disabled false if some services are not disabled' do
|
|
|
|
service.runlevels(0, 4).enabled?.must_equal false
|
|
|
|
end
|
|
|
|
end
|
2015-09-14 13:15:32 +00:00
|
|
|
end
|