2019-06-11 22:24:35 +00:00
require " helper "
require " inspec/resource "
require " inspec/resources/service "
require " hashie "
2015-09-14 13:15:32 +00:00
2019-06-11 22:24:35 +00:00
describe " Inspec::Resources::Service " do
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
2019-06-11 22:24:35 +00:00
it " verify service parsing " do
resource = MockLoader . new ( :windows ) . load_resource ( " service " , " dhcp " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " windows "
_ ( resource . name ) . must_equal " dhcp "
_ ( resource . description ) . must_equal " DHCP Client "
2015-09-23 14:30:48 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2019-06-11 22:24:35 +00:00
_ ( resource . startmode ) . must_equal " Auto "
2019-08-07 01:58:03 +00:00
_ ( resource . startname ) . must_equal " LocalSystem "
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2015-09-23 14:30:48 +00:00
end
2015-09-23 20:32:31 +00:00
2015-09-25 08:31:42 +00:00
# ubuntu 14.04 with upstart
2019-06-11 22:24:35 +00:00
it " verify ubuntu service parsing " do
resource = MockLoader . new ( :ubuntu1404 ) . load_resource ( " service " , " ssh " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " upstart "
_ ( resource . name ) . must_equal " ssh "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2015-09-23 20:32:31 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2015-09-23 20:32:31 +00:00
end
2015-09-25 10:48:21 +00:00
2019-06-11 22:24:35 +00:00
it " verify ubuntu service parsing with default upstart_service " do
resource = MockLoader . new ( :ubuntu1404 ) . load_resource ( " upstart_service " , " ssh " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " upstart "
_ ( resource . name ) . must_equal " ssh "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2016-01-20 14:54:36 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2017-06-11 10:16:10 +00:00
_ ( resource . params . UnitFileState ) . must_be_nil
2016-01-20 14:54:36 +00:00
end
2015-09-25 08:31:42 +00:00
# ubuntu 15.04 with systemd
2019-06-11 22:24:35 +00:00
it " verify ubuntu service parsing " do
resource = MockLoader . new ( :ubuntu1504 ) . load_resource ( " service " , " sshd " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " SubState " = > " running " , " UnitFileState " = > " enabled " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
2015-09-25 08:31:42 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2019-06-11 22:24:35 +00:00
_ ( resource . params . SubState ) . must_equal " running "
2015-09-25 08:31:42 +00:00
end
2019-06-11 22:24:35 +00:00
it " verify ubuntu service parsing with default systemd_service " do
resource = MockLoader . new ( :ubuntu1504 ) . load_resource ( " systemd_service " , " sshd " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " SubState " = > " running " , " UnitFileState " = > " enabled " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
2016-01-20 13:33:24 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2016-01-20 13:33:24 +00:00
end
2016-10-08 21:03:59 +00:00
# linux mint 17 with upstart
2019-06-11 22:24:35 +00:00
it " verify mint service parsing " do
resource = MockLoader . new ( :mint17 ) . load_resource ( " service " , " ssh " )
2016-10-08 21:03:59 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " upstart "
_ ( resource . name ) . must_equal " ssh "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2016-10-08 21:03:59 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
end
2019-06-11 22:24:35 +00:00
it " verify mint service parsing with default upstart_service " do
resource = MockLoader . new ( :mint17 ) . load_resource ( " upstart_service " , " ssh " )
2016-10-08 21:03:59 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " upstart "
_ ( resource . name ) . must_equal " ssh "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2016-10-08 21:03:59 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
2017-06-11 10:16:10 +00:00
_ ( resource . params . UnitFileState ) . must_be_nil
2016-10-08 21:03:59 +00:00
end
# mint 18 with systemd
2019-06-11 22:24:35 +00:00
it " verify mint service parsing " do
resource = MockLoader . new ( :mint18 ) . load_resource ( " service " , " sshd " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " SubState " = > " running " , " UnitFileState " = > " enabled " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
2016-10-08 21:03:59 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
2019-06-11 22:24:35 +00:00
_ ( resource . params . SubState ) . must_equal " running "
2016-10-08 21:03:59 +00:00
end
2019-06-11 22:24:35 +00:00
it " verify mint service parsing with default systemd_service " do
resource = MockLoader . new ( :mint18 ) . load_resource ( " systemd_service " , " sshd " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " SubState " = > " running " , " UnitFileState " = > " enabled " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
2018-04-19 17:00:39 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
end
# Amazon Linux
2019-06-11 22:24:35 +00:00
it " verify amazon linux service parsing " do
resource = MockLoader . new ( :amazon ) . load_resource ( " service " , " ssh " )
2018-04-19 17:00:39 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " upstart "
_ ( resource . name ) . must_equal " ssh "
2018-04-19 17:00:39 +00:00
_ ( resource . description ) . must_be_nil
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
_ ( resource . params . UnitFileState ) . must_be_nil
end
# Amazon Linux 2
2019-06-11 22:24:35 +00:00
it " verify amazon linux 2 service parsing " do
resource = MockLoader . new ( :amazon2 ) . load_resource ( " service " , " sshd " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " SubState " = > " running " , " UnitFileState " = > " enabled " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
2016-10-08 21:03:59 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
end
2016-01-20 14:54:36 +00:00
# centos 6 with sysv
2019-06-11 22:24:35 +00:00
it " verify centos 6 service parsing " do
resource = MockLoader . new ( :centos6 ) . load_resource ( " service " , " sshd " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " sysv "
_ ( resource . name ) . must_equal " sshd "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2015-09-25 09:47:59 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2017-06-11 10:16:10 +00:00
_ ( resource . params . SubState ) . must_be_nil
2015-09-25 09:47:59 +00:00
end
2019-06-11 22:24:35 +00:00
it " verify centos 6 service parsing with default sysv_service " do
resource = MockLoader . new ( :centos6 ) . load_resource ( " sysv_service " , " sshd " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " sysv "
_ ( resource . name ) . must_equal " sshd "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2016-01-20 14:54:36 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2016-01-20 14:54:36 +00:00
end
2015-09-25 10:48:21 +00:00
# centos 7 with systemd
2019-06-11 22:24:35 +00:00
it " verify centos 7 service parsing " do
resource = MockLoader . new ( :centos7 ) . load_resource ( " service " , " sshd " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " SubState " = > " running " , " UnitFileState " = > " enabled " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
2015-09-25 10:48:21 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2015-09-25 10:48:21 +00:00
end
2015-09-24 21:32:46 +00:00
2019-06-11 22:24:35 +00:00
it " verify centos 7 service parsing with systemd_service and service_ctl override " do
resource = MockLoader . new ( :centos7 ) . load_resource ( " systemd_service " , " sshd " , " /path/to/systemctl " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " UnitFileState " = > " enabled " , " SubState " = > " running " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
2016-01-21 10:41:48 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2016-01-21 10:41:48 +00:00
end
2019-06-11 22:24:35 +00:00
it " verify centos 7 service parsing with static loaded service " do
resource = MockLoader . new ( :centos7 ) . load_resource ( " service " , " dbus " )
2019-09-25 04:49:29 +00:00
params = Hashie :: Mash . new ( { " Description " = > " D-Bus System Message Bus " , " Id " = > " dbus.service " , " LoadState " = > " loaded " , " Names " = > " messagebus.service dbus.service " , " SubState " = > " running " , " UnitFileState " = > " static " , " User " = > " root " } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " dbus.service "
_ ( resource . description ) . must_equal " D-Bus System Message Bus "
2019-08-07 04:34:46 +00:00
_ ( resource . startname ) . must_equal " root "
2018-08-22 19:58:38 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
2019-06-11 22:24:35 +00:00
_ ( resource . params . UnitFileState ) . must_equal " static "
2018-08-22 19:58:38 +00:00
end
# cloudlinux 7 with systemd
2019-06-11 22:24:35 +00:00
it " verify cloudlinux 7 service parsing " do
resource = MockLoader . new ( :cloudlinux ) . load_resource ( " service " , " sshd " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " SubState " = > " running " , " UnitFileState " = > " enabled " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
2018-08-22 19:58:38 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
end
2019-06-11 22:24:35 +00:00
it " verify cloudlinux 7 service parsing with systemd_service and service_ctl override " do
resource = MockLoader . new ( :cloudlinux ) . load_resource ( " systemd_service " , " sshd " , " /path/to/systemctl " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " UnitFileState " = > " enabled " , " SubState " = > " running " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
2018-08-22 19:58:38 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
end
2019-06-11 22:24:35 +00:00
it " verify cloudlinux 7 service parsing with static loaded service " do
resource = MockLoader . new ( :cloudlinux ) . load_resource ( " service " , " dbus " )
2019-09-25 04:58:55 +00:00
params = Hashie :: Mash . new ( { " Description " = > " D-Bus System Message Bus " , " Id " = > " dbus.service " , " LoadState " = > " loaded " , " Names " = > " messagebus.service dbus.service " , " SubState " = > " running " , " UnitFileState " = > " static " , " User " = > " root " } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " dbus.service "
_ ( resource . description ) . must_equal " D-Bus System Message Bus "
2019-08-07 04:34:46 +00:00
_ ( resource . startname ) . must_equal " root "
2016-04-13 19:44:28 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2019-06-11 22:24:35 +00:00
_ ( resource . params . UnitFileState ) . must_equal " static "
2016-04-13 19:44:28 +00:00
end
2015-09-25 10:53:40 +00:00
# freebsd
2019-06-11 22:24:35 +00:00
it " verify freebsd10 service parsing " do
resource = MockLoader . new ( :freebsd10 ) . load_resource ( " service " , " sendmail " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " bsd-init "
_ ( resource . name ) . must_equal " sendmail "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2015-09-25 10:53:40 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2015-09-25 10:53:40 +00:00
end
2019-06-11 22:24:35 +00:00
it " verify freebsd10 service parsing with default bsd_service " do
resource = MockLoader . new ( :freebsd10 ) . load_resource ( " bsd_service " , " sendmail " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " bsd-init "
_ ( resource . name ) . must_equal " sendmail "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2016-01-20 14:54:36 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2016-01-20 14:54:36 +00:00
end
2015-09-24 21:37:31 +00:00
# arch linux with systemd
2019-06-11 22:24:35 +00:00
it " verify arch linux service parsing " do
resource = MockLoader . new ( :arch ) . load_resource ( " service " , " sshd " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " SubState " = > " running " , " UnitFileState " = > " enabled " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
2015-09-24 21:37:31 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2015-09-24 21:37:31 +00:00
end
2017-06-15 17:19:58 +00:00
# coreos linux with systemd
2019-06-11 22:24:35 +00:00
it " verify coreos linux service parsing " do
resource = MockLoader . new ( :coreos ) . load_resource ( " service " , " sshd " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " SubState " = > " running " , " UnitFileState " = > " enabled " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
2017-06-15 17:19:58 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
end
2015-09-25 09:47:59 +00:00
# debian 7 with systemv
2019-06-11 22:24:35 +00:00
it " verify debian 7 service parsing " do
resource = MockLoader . new ( :debian7 ) . load_resource ( " service " , " sshd " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " sysv "
_ ( resource . name ) . must_equal " sshd "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2015-09-25 09:47:59 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2015-09-25 09:47:59 +00:00
end
2015-09-24 21:32:46 +00:00
# debian 8 with systemd
2019-06-11 22:24:35 +00:00
it " verify debian 8 service parsing " do
resource = MockLoader . new ( :debian8 ) . load_resource ( " service " , " sshd " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " SubState " = > " running " , " UnitFileState " = > " enabled " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
2015-09-24 21:32:46 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2015-09-24 21:32:46 +00:00
end
2019-06-22 17:23:32 +00:00
# debian 10 with systemd
it " verify debian 10 service parsing " do
resource = MockLoader . new ( :debian10 ) . load_resource ( " service " , " sshd " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " SubState " = > " running " , " UnitFileState " = > " enabled " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
end
2018-01-23 20:34:47 +00:00
# debian 8 with systemd but no service file
2019-06-11 22:24:35 +00:00
it " gets the correct service info when the `.service` file is missing " do
resource = MockLoader . new ( :debian8 ) . load_resource ( " service " , " apache2 " )
2018-01-23 20:34:47 +00:00
params = Hashie :: Mash . new (
2019-06-11 22:24:35 +00:00
" ActiveState " = > " active " ,
" Description " = > " LSB: Apache2 web server " ,
" Id " = > " apache2.service " ,
" LoadState " = > " loaded " ,
" Names " = > " apache2.service " ,
" SubState " = > " running " ,
" UnitFileState " = > " "
2018-01-23 20:34:47 +00:00
)
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " apache2.service "
_ ( resource . description ) . must_equal " LSB: Apache2 web server "
2018-01-23 20:34:47 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
end
2015-09-25 10:51:12 +00:00
# macos test
2019-06-11 22:24:35 +00:00
it " verify mac osx service parsing " do
2020-07-01 22:35:23 +00:00
resource = MockLoader . new ( :macos10_10 ) . load_resource ( " service " , " ssh " )
params = Hashie :: Mash . new ( { } )
_ ( resource . type ) . must_equal " darwin "
_ ( resource . name ) . must_equal " org.openbsd.ssh-agent "
_ ( resource . description ) . must_be_nil
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
end
it " verify macos 10.16 (11 / big sur) service parsing " do
resource = MockLoader . new ( :macos10_16 ) . load_resource ( " service " , " ssh " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " darwin "
_ ( resource . name ) . must_equal " org.openbsd.ssh-agent "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2015-09-25 10:51:12 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2015-09-25 10:51:12 +00:00
end
2019-06-11 22:24:35 +00:00
it " verify mac osx service parsing with not-running service " do
2020-07-01 22:35:23 +00:00
resource = MockLoader . new ( :macos10_10 ) . load_resource ( " service " , " FilesystemUI " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " darwin "
_ ( resource . name ) . must_equal " com.apple.FilesystemUI "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2016-01-22 10:52:06 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal false
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2016-01-22 10:52:06 +00:00
end
2019-06-11 22:24:35 +00:00
it " verify mac osx service parsing with default launchd_service " do
2020-07-01 22:35:23 +00:00
resource = MockLoader . new ( :macos10_10 ) . load_resource ( " launchd_service " , " ssh " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " darwin "
_ ( resource . name ) . must_equal " org.openbsd.ssh-agent "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2016-01-20 14:54:36 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2016-01-20 14:54:36 +00:00
end
2015-12-03 03:08:49 +00:00
# wrlinux
2019-06-11 22:24:35 +00:00
it " verify wrlinux service parsing " do
resource = MockLoader . new ( :wrlinux ) . load_resource ( " service " , " sshd " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2019-06-11 22:24:35 +00:00
_ ( resource . type ) . must_equal " sysv "
_ ( resource . name ) . must_equal " sshd "
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2015-12-03 03:08:49 +00:00
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2015-12-03 03:08:49 +00:00
end
2020-01-18 00:24:20 +00:00
# yocto
it " verify yocto service parsing " do
resource = MockLoader . new ( :yocto ) . load_resource ( " service " , " sshd " )
params = Hashie :: Mash . new ( { " ActiveState " = > " active " , " Description " = > " OpenSSH server daemon " , " Id " = > " sshd.service " , " LoadState " = > " loaded " , " Names " = > " sshd.service " , " SubState " = > " running " , " UnitFileState " = > " enabled " } )
_ ( resource . type ) . must_equal " systemd "
_ ( resource . name ) . must_equal " sshd.service "
_ ( resource . description ) . must_equal " OpenSSH server daemon "
_ ( resource . installed? ) . must_equal true
_ ( resource . enabled? ) . must_equal true
_ ( resource . running? ) . must_equal true
_ ( resource . params ) . must_equal params
end
2015-09-23 14:32:51 +00:00
# unknown OS
2019-06-11 22:24:35 +00:00
it " verify service handling on unsupported os " do
resource = MockLoader . new ( :undefined ) . load_resource ( " service " , " dhcp " )
2016-05-06 15:38:56 +00:00
params = Hashie :: Mash . new ( { } )
2015-09-23 14:32:51 +00:00
_ ( resource . installed? ) . must_equal false
2017-06-11 10:16:10 +00:00
_ ( resource . description ) . must_be_nil
2016-05-06 15:38:56 +00:00
_ ( resource . params ) . must_equal params
2015-09-23 14:32:51 +00:00
end
2016-02-14 17:37:20 +00:00
# runlevel detection
2019-06-11 22:24:35 +00:00
describe " runlevels on centos 6 (system V) " do
let ( :service ) { MockLoader . new ( :centos6 ) . load_resource ( " service " , " sshd " ) }
2016-02-14 17:37:20 +00:00
2019-06-11 22:24:35 +00:00
it " grabs all runlevels " do
2019-09-30 22:31:55 +00:00
_ ( service . runlevels . keys ) . must_equal [ 0 , 1 , 2 , 3 , 4 , 5 , 6 ]
2016-02-14 17:37:20 +00:00
end
2019-06-11 22:24:35 +00:00
it " grabs runlevels via filter nil " do
2019-09-30 22:31:55 +00:00
_ ( service . runlevels ( nil ) . keys ) . must_equal [ 0 , 1 , 2 , 3 , 4 , 5 , 6 ]
2016-02-14 17:37:20 +00:00
end
2019-06-11 22:24:35 +00:00
it " grabs runlevels by number " do
2019-09-30 22:31:55 +00:00
_ ( service . runlevels ( 3 ) . keys ) . must_equal [ 3 ]
2016-02-14 17:37:20 +00:00
end
2019-06-11 22:24:35 +00:00
it " grabs runlevels by multiple numbers " do
2019-09-30 22:31:55 +00:00
_ ( service . runlevels ( 3 , 4 , 8 ) . keys ) . must_equal [ 3 , 4 ]
2016-02-14 17:37:20 +00:00
end
2019-06-11 22:24:35 +00:00
it " grabs runlevels via regex " do
2019-09-30 22:31:55 +00:00
_ ( service . runlevels ( / [5-9] / ) . keys ) . must_equal [ 5 , 6 ]
2016-02-14 17:37:20 +00:00
end
2019-06-11 22:24:35 +00:00
it " checks enabled true if all services are enabled " do
2019-09-30 22:31:55 +00:00
_ ( service . runlevels ( 2 , 4 ) . enabled? ) . must_equal true
2016-02-14 17:37:20 +00:00
end
2019-06-11 22:24:35 +00:00
it " checks enabled false if some services are not enabled " do
2019-09-30 22:31:55 +00:00
_ ( service . runlevels ( 1 , 4 ) . enabled? ) . must_equal false
2016-02-14 17:37:20 +00:00
end
2019-06-11 22:24:35 +00:00
it " checks disabled true if all services are disabled " do
2019-09-30 22:31:55 +00:00
_ ( service . runlevels ( 0 , 1 ) . disabled? ) . must_equal true
2016-02-14 17:37:20 +00:00
end
2019-06-11 22:24:35 +00:00
it " checks disabled false if some services are not disabled " do
2019-09-30 22:31:55 +00:00
_ ( service . runlevels ( 0 , 4 ) . enabled? ) . must_equal false
2016-02-14 17:37:20 +00:00
end
end
2015-09-14 13:15:32 +00:00
end