inspec 0.20.1 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -2
  3. data/docs/dsl_inspec.rst +2 -2
  4. data/docs/resources.rst +9 -9
  5. data/docs/ruby_usage.rst +145 -0
  6. data/inspec.gemspec +1 -0
  7. data/lib/bundles/inspec-compliance/cli.rb +15 -2
  8. data/lib/inspec/cli.rb +23 -10
  9. data/lib/inspec/dsl.rb +0 -52
  10. data/lib/inspec/objects/or_test.rb +1 -0
  11. data/lib/inspec/objects/test.rb +4 -4
  12. data/lib/inspec/profile.rb +76 -61
  13. data/lib/inspec/profile_context.rb +12 -11
  14. data/lib/inspec/rspec_json_formatter.rb +93 -40
  15. data/lib/inspec/rule.rb +7 -29
  16. data/lib/inspec/runner.rb +15 -4
  17. data/lib/inspec/runner_mock.rb +1 -1
  18. data/lib/inspec/runner_rspec.rb +26 -24
  19. data/lib/inspec/version.rb +1 -1
  20. data/lib/matchers/matchers.rb +3 -3
  21. data/lib/resources/auditd_rules.rb +2 -2
  22. data/lib/resources/host.rb +1 -1
  23. data/lib/resources/interface.rb +1 -1
  24. data/lib/resources/kernel_parameter.rb +1 -1
  25. data/lib/resources/mount.rb +2 -1
  26. data/lib/resources/mysql_session.rb +1 -1
  27. data/lib/resources/os_env.rb +2 -2
  28. data/lib/resources/passwd.rb +33 -93
  29. data/lib/resources/port.rb +47 -3
  30. data/lib/resources/processes.rb +3 -3
  31. data/lib/resources/service.rb +33 -1
  32. data/lib/resources/user.rb +15 -15
  33. data/lib/utils/base_cli.rb +1 -3
  34. data/lib/utils/filter.rb +30 -7
  35. data/test/cookbooks/os_prepare/recipes/_upstart_service_centos.rb +4 -0
  36. data/test/functional/helper.rb +1 -0
  37. data/test/functional/inheritance_test.rb +1 -1
  38. data/test/functional/inspec_compliance_test.rb +4 -3
  39. data/test/functional/inspec_exec_json_test.rb +122 -0
  40. data/test/functional/inspec_exec_test.rb +23 -117
  41. data/test/functional/{inspec_json_test.rb → inspec_json_profile_test.rb} +13 -15
  42. data/test/functional/inspec_test.rb +15 -2
  43. data/test/helper.rb +5 -1
  44. data/test/integration/default/auditd_rules_spec.rb +3 -3
  45. data/test/integration/default/kernel_parameter_spec.rb +6 -6
  46. data/test/integration/default/service_spec.rb +4 -0
  47. data/test/resource/command_test.rb +9 -9
  48. data/test/resource/dsl_test.rb +1 -1
  49. data/test/resource/file_test.rb +17 -17
  50. data/test/unit/control_test.rb +1 -1
  51. data/test/unit/mock/cmd/hpux-netstat-inet +10 -0
  52. data/test/unit/mock/cmd/hpux-netstat-inet6 +11 -0
  53. data/test/unit/mock/profiles/skippy-profile-os/controls/one.rb +1 -1
  54. data/test/unit/profile_context_test.rb +2 -2
  55. data/test/unit/profile_test.rb +11 -14
  56. data/test/unit/resources/passwd_test.rb +13 -14
  57. data/test/unit/resources/port_test.rb +14 -0
  58. data/test/unit/resources/processes_test.rb +3 -3
  59. data/test/unit/resources/service_test.rb +103 -39
  60. data/test/unit/utils/filter_table_test.rb +35 -3
  61. metadata +25 -4
@@ -12,7 +12,7 @@ describe 'controls' do
12
12
  }
13
13
  opts = { test_collector: Inspec::RunnerMock.new }
14
14
  Inspec::Profile.for_target(data, opts)
15
- .params[:rules].values[0]['1']
15
+ .params[:controls]['1']
16
16
  end
17
17
 
18
18
  it 'works with empty refs' do
@@ -0,0 +1,10 @@
1
+ Active Internet connections (including servers)
2
+ Proto Recv-Q Send-Q Local Address Foreign Address (state)
3
+ tcp 0 0 *.515 *.* LISTEN
4
+ tcp 0 28 16.147.37.141.22 16.180.154.172.64145 ESTABLISHED
5
+ tcp 0 0 *.22 *.* LISTEN
6
+ tcp 0 0 *.49196 *.* LISTEN
7
+ tcp 0 0 16.147.37.141.49399 16.147.37.141.1712 ESTABLISHED
8
+ tcp 0 0 127.0.0.1.49433 *.* LISTEN
9
+ udp 0 0 127.0.0.1.49178 127.0.0.1.49178
10
+ udp 0 0 *.49153 *.*
@@ -0,0 +1,11 @@
1
+ Active Internet connections (IPv6, including servers)
2
+ Proto Recv-Q Send-Q Local Address Foreign Address (state)
3
+ tcp6 0 0 ::1.49309 *.* LISTEN
4
+ tcp6 0 0 *.21 *.* LISTEN
5
+ tcp6 0 0 ::1.49671 ::1.49400 ESTABLISHED
6
+ tcp6 0 0 *.383 *.* LISTEN
7
+ tcp6 0 0 *.22 *.* LISTEN
8
+ tcp6 0 0 ::1.49403 ::1.49400 ESTABLISHED
9
+ tcp6 0 0 ::1.62538 ::1.62537 TIME_WAIT
10
+ udp6 0 0 *.514 *.*
11
+ udp6 0 0 *.9 *.*
@@ -1,3 +1,3 @@
1
1
  describe command('touch /tmp/inspec_test_DONT_CREATE') do
2
- its(:exit_status) { should eq 123 }
2
+ its('exit_status') { should eq 123 }
3
3
  end
@@ -177,13 +177,13 @@ describe Inspec::ProfileContext do
177
177
 
178
178
  it 'provides the control keyword in the global DSL' do
179
179
  profile.load('control 1')
180
- profile.rules.keys.must_equal [1]
180
+ profile.rules.keys.must_equal ['1']
181
181
  profile.rules.values[0].must_be_kind_of Inspec::Rule
182
182
  end
183
183
 
184
184
  it 'provides the rule keyword in the global DSL (legacy mode)' do
185
185
  profile.load('rule 1')
186
- profile.rules.keys.must_equal [1]
186
+ profile.rules.keys.must_equal ['1']
187
187
  profile.rules.values[0].must_be_kind_of Inspec::Rule
188
188
  end
189
189
  end
@@ -16,8 +16,8 @@ describe Inspec::Profile do
16
16
  profile.params[:name].must_be_nil
17
17
  end
18
18
 
19
- it 'has no rules' do
20
- profile.params[:rules].must_equal({})
19
+ it 'has no controls' do
20
+ profile.params[:controls].must_equal({})
21
21
  end
22
22
  end
23
23
 
@@ -28,8 +28,8 @@ describe Inspec::Profile do
28
28
  profile.params[:name].must_be_nil
29
29
  end
30
30
 
31
- it 'has no rules' do
32
- profile.params[:rules].must_equal({})
31
+ it 'has no controls' do
32
+ profile.params[:controls].must_equal({})
33
33
  end
34
34
  end
35
35
 
@@ -41,8 +41,8 @@ describe Inspec::Profile do
41
41
  profile.params[:name].must_equal 'yumyum profile'
42
42
  end
43
43
 
44
- it 'has no rules' do
45
- profile.params[:rules].must_equal({})
44
+ it 'has no controls' do
45
+ profile.params[:controls].must_equal({})
46
46
  end
47
47
 
48
48
  it 'can overwrite the profile ID' do
@@ -59,8 +59,8 @@ describe Inspec::Profile do
59
59
  profile.params[:name].must_equal 'metadata profile'
60
60
  end
61
61
 
62
- it 'has no rules' do
63
- profile.params[:rules].must_equal({})
62
+ it 'has no controls' do
63
+ profile.params[:controls].must_equal({})
64
64
  end
65
65
  end
66
66
 
@@ -179,11 +179,10 @@ describe Inspec::Profile do
179
179
  describe 'a complete metadata profile with controls' do
180
180
  let(:profile_id) { 'complete-profile' }
181
181
 
182
- it 'prints ok messages and counts the rules' do
182
+ it 'prints ok messages and counts the controls' do
183
183
  logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
184
184
  logger.expect :info, nil, ['Metadata OK.']
185
185
  logger.expect :info, nil, ['Found 1 controls.']
186
- logger.expect :info, nil, ["Verify all controls in controls/filesystem_spec.rb"]
187
186
  logger.expect :info, nil, ['Control definitions OK.']
188
187
 
189
188
  result = MockLoader.load_profile(profile_id, {logger: logger}).check
@@ -205,11 +204,10 @@ describe Inspec::Profile do
205
204
  let(:profile_path) { MockLoader.profile_tgz(profile_id) }
206
205
  let(:profile) { MockLoader.load_profile(profile_path, {logger: logger}) }
207
206
 
208
- it 'prints ok messages and counts the rules' do
207
+ it 'prints ok messages and counts the controls' do
209
208
  logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
210
209
  logger.expect :info, nil, ['Metadata OK.']
211
210
  logger.expect :info, nil, ['Found 1 controls.']
212
- logger.expect :info, nil, ["Verify all controls in controls/filesystem_spec.rb"]
213
211
  logger.expect :info, nil, ['Control definitions OK.']
214
212
 
215
213
  result = MockLoader.load_profile(profile_id, {logger: logger}).check
@@ -231,11 +229,10 @@ describe Inspec::Profile do
231
229
  let(:profile_path) { MockLoader.profile_zip(profile_id) }
232
230
  let(:profile) { MockLoader.load_profile(profile_path, {logger: logger}) }
233
231
 
234
- it 'prints ok messages and counts the rules' do
232
+ it 'prints ok messages and counts the controls' do
235
233
  logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
236
234
  logger.expect :info, nil, ['Metadata OK.']
237
235
  logger.expect :info, nil, ['Found 1 controls.']
238
- logger.expect :info, nil, ["Verify all controls in controls/filesystem_spec.rb"]
239
236
  logger.expect :info, nil, ['Control definitions OK.']
240
237
 
241
238
  result = MockLoader.load_profile(profile_id, {logger: logger}).check
@@ -77,36 +77,35 @@ describe 'Inspec::Resources::Passwd' do
77
77
  end
78
78
  end
79
79
 
80
- # TODO REWORK ALL OF THESE, please don't depend on them yet!
81
- describe 'experimental features' do
80
+ describe 'where clause' do
82
81
  it 'retrieves username via uids < x' do
83
- _(passwd.uids({ :< => 33 }).count).must_equal 1
84
- _(passwd.uids({ :< => 34 }).count).must_equal 2
82
+ _(passwd.where { uid.to_i < 33 }.entries.length).must_equal 1
83
+ _(passwd.where { uid.to_i < 34 }.entries.length).must_equal 2
85
84
  end
86
85
 
87
86
  it 'retrieves username via uids <= x' do
88
- _(passwd.uids({ :<= => 32 }).count).must_equal 1
89
- _(passwd.uids({ :<= => 33 }).count).must_equal 2
87
+ _(passwd.where { uid.to_i <= 32 }.entries.length).must_equal 1
88
+ _(passwd.where { uid.to_i <= 33 }.entries.length).must_equal 2
90
89
  end
91
90
 
92
91
  it 'retrieves username via uids > x' do
93
- _(passwd.uids({ :> => 0 }).count).must_equal 1
94
- _(passwd.uids({ :> => -1 }).count).must_equal 2
92
+ _(passwd.where { uid.to_i > 0 }.entries.length).must_equal 1
93
+ _(passwd.where { uid.to_i > -1 }.entries.length).must_equal 2
95
94
  end
96
95
 
97
96
  it 'retrieves username via uids >= x' do
98
- _(passwd.uids({ :>= => 1 }).count).must_equal 1
99
- _(passwd.uids({ :>= => 0 }).count).must_equal 2
97
+ _(passwd.where { uid.to_i >= 1 }.entries.length).must_equal 1
98
+ _(passwd.where { uid.to_i >= 0 }.entries.length).must_equal 2
100
99
  end
101
100
 
102
101
  it 'retrieves username via uids == x' do
103
- _(passwd.uids({ :== => 0 }).count).must_equal 1
104
- _(passwd.uids({ :== => 1 }).count).must_equal 0
102
+ _(passwd.where { uid.to_i == 0 }.entries.length).must_equal 1
103
+ _(passwd.where { uid.to_i == 1 }.entries.length).must_equal 0
105
104
  end
106
105
 
107
106
  it 'retrieves username via uids != x' do
108
- _(passwd.uids({ :!= => 0 }).count).must_equal 1
109
- _(passwd.uids({ :!= => 1 }).count).must_equal 2
107
+ _(passwd.where { uid.to_i != 0 }.entries.length).must_equal 1
108
+ _(passwd.where { uid.to_i != 1 }.entries.length).must_equal 2
110
109
  end
111
110
  end
112
111
  end
@@ -92,4 +92,18 @@ describe 'Inspec::Resources::Port' do
92
92
  _(resource.listening?).must_equal true
93
93
  _(resource.addresses).must_equal ["0.0.0.0"]
94
94
  end
95
+
96
+ it 'verify port on hpux' do
97
+ resource = MockLoader.new(:hpux).load_resource('port', 22)
98
+ _(resource.listening?).must_equal true
99
+ _(resource.protocols).must_equal %w{ tcp tcp6 }
100
+ _(resource.addresses).must_equal ["0.0.0.0", "0:0:0:0:0:0:0:0" ]
101
+ end
102
+
103
+ it 'verify not listening port on hpux' do
104
+ resource = MockLoader.new(:hpux).load_resource('port', 23)
105
+ _(resource.listening?).must_equal false
106
+ _(resource.protocols).must_equal nil
107
+ _(resource.addresses).must_equal nil
108
+ end
95
109
  end
@@ -15,11 +15,11 @@ describe 'Inspec::Resources::Processes' do
15
15
  resource = load_resource('processes', '/bin/bash')
16
16
  _(resource.list).must_equal [{
17
17
  user: 'root',
18
- pid: '1',
18
+ pid: 1,
19
19
  cpu: '0.0',
20
20
  mem: '0.0',
21
- vsz: '18084',
22
- rss: '3228',
21
+ vsz: 18084,
22
+ rss: 3228,
23
23
  tty: '?',
24
24
  stat: 'Ss',
25
25
  start: '14:15',
@@ -4,6 +4,7 @@
4
4
 
5
5
  require 'helper'
6
6
  require 'inspec/resource'
7
+ require 'hashie'
7
8
 
8
9
  describe 'Inspec::Resources::Service' do
9
10
  let(:runlevels) { {0=>false, 1=>false, 2=>true, 3=>true, 4=>true, 5=>true, 6=>false} }
@@ -11,191 +12,254 @@ describe 'Inspec::Resources::Service' do
11
12
  # windows
12
13
  it 'verify service parsing' do
13
14
  resource = MockLoader.new(:windows).load_resource('service', 'dhcp')
14
- srv = { name: 'dhcp', description: 'DHCP Client', installed: true, running: true, enabled: true, type: 'windows' }
15
- _(resource.info).must_equal srv
15
+ params = Hashie::Mash.new({})
16
+ _(resource.type).must_equal 'windows'
17
+ _(resource.name).must_equal 'dhcp'
18
+ _(resource.description).must_equal 'DHCP Client'
16
19
  _(resource.installed?).must_equal true
17
20
  _(resource.enabled?).must_equal true
18
21
  _(resource.running?).must_equal true
22
+ _(resource.params).must_equal params
19
23
  end
20
24
 
21
25
  # ubuntu 14.04 with upstart
22
26
  it 'verify ubuntu package parsing' do
23
27
  resource = MockLoader.new(:ubuntu1404).load_resource('service', 'ssh')
24
- srv = { name: 'ssh', description: nil, installed: true, running: true, enabled: true, type: 'upstart' }
25
- _(resource.info).must_equal srv
28
+ params = Hashie::Mash.new({})
29
+ _(resource.type).must_equal 'upstart'
30
+ _(resource.name).must_equal 'ssh'
31
+ _(resource.description).must_equal nil
26
32
  _(resource.installed?).must_equal true
27
33
  _(resource.enabled?).must_equal true
28
34
  _(resource.running?).must_equal true
35
+ _(resource.params).must_equal params
29
36
  end
30
37
 
31
38
  it 'verify ubuntu package parsing with default upstart_service' do
32
39
  resource = MockLoader.new(:ubuntu1404).load_resource('upstart_service', 'ssh')
33
- srv = { name: 'ssh', description: nil, installed: true, running: true, enabled: true, type: 'upstart' }
34
- _(resource.info).must_equal srv
40
+ params = Hashie::Mash.new({})
41
+ _(resource.type).must_equal 'upstart'
42
+ _(resource.name).must_equal 'ssh'
43
+ _(resource.description).must_equal nil
35
44
  _(resource.installed?).must_equal true
36
45
  _(resource.enabled?).must_equal true
37
46
  _(resource.running?).must_equal true
47
+ _(resource.params).must_equal params
48
+ _(resource.params.UnitFileState).must_equal nil
38
49
  end
39
50
 
40
51
  # ubuntu 15.04 with systemd
41
52
  it 'verify ubuntu package parsing' do
42
53
  resource = MockLoader.new(:ubuntu1504).load_resource('service', 'sshd')
43
- srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
44
- _(resource.info).must_equal srv
54
+ params = Hashie::Mash.new({ 'Description' => 'OpenSSH server daemon', 'Id' => 'sshd.service', 'LoadState' => 'loaded', 'Names' => 'sshd.service', 'SubState' => 'running', 'UnitFileState' => 'enabled' })
55
+ _(resource.type).must_equal 'systemd'
56
+ _(resource.name).must_equal 'sshd.service'
57
+ _(resource.description).must_equal 'OpenSSH server daemon'
45
58
  _(resource.installed?).must_equal true
46
59
  _(resource.enabled?).must_equal true
47
60
  _(resource.running?).must_equal true
61
+ _(resource.params).must_equal params
62
+ _(resource.params.SubState).must_equal 'running'
48
63
  end
49
64
 
50
65
  it 'verify ubuntu package parsing with default systemd_service' do
51
66
  resource = MockLoader.new(:ubuntu1504).load_resource('systemd_service', 'sshd')
52
- srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
53
- _(resource.info).must_equal srv
67
+ params = Hashie::Mash.new({ 'Description' => 'OpenSSH server daemon', 'Id' => 'sshd.service', 'LoadState' => 'loaded', 'Names' => 'sshd.service', 'SubState' => 'running', 'UnitFileState' => 'enabled' })
68
+ _(resource.type).must_equal 'systemd'
69
+ _(resource.name).must_equal 'sshd.service'
70
+ _(resource.description).must_equal 'OpenSSH server daemon'
54
71
  _(resource.installed?).must_equal true
55
72
  _(resource.enabled?).must_equal true
56
73
  _(resource.running?).must_equal true
74
+ _(resource.params).must_equal params
57
75
  end
58
76
 
59
77
  # centos 6 with sysv
60
78
  it 'verify centos 6 package parsing' do
61
79
  resource = MockLoader.new(:centos6).load_resource('service', 'sshd')
62
- srv = { name: 'sshd', description: nil, installed: true, running: true, enabled: true, runlevels: runlevels, type: 'sysv' }
63
- _(resource.info).must_equal srv
80
+ params = Hashie::Mash.new({})
81
+ _(resource.type).must_equal 'sysv'
82
+ _(resource.name).must_equal 'sshd'
83
+ _(resource.description).must_equal nil
64
84
  _(resource.installed?).must_equal true
65
85
  _(resource.enabled?).must_equal true
66
86
  _(resource.running?).must_equal true
87
+ _(resource.params).must_equal params
88
+ _(resource.params.SubState).must_equal nil
67
89
  end
68
90
 
69
91
  it 'verify centos 6 package parsing with default sysv_service' do
70
92
  resource = MockLoader.new(:centos6).load_resource('sysv_service', 'sshd')
71
- srv = { name: 'sshd', description: nil, installed: true, running: true, enabled: true, runlevels: runlevels, type: 'sysv' }
72
- _(resource.info).must_equal srv
93
+ params = Hashie::Mash.new({})
94
+ _(resource.type).must_equal 'sysv'
95
+ _(resource.name).must_equal 'sshd'
96
+ _(resource.description).must_equal nil
73
97
  _(resource.installed?).must_equal true
74
98
  _(resource.enabled?).must_equal true
75
99
  _(resource.running?).must_equal true
100
+ _(resource.params).must_equal params
76
101
  end
77
102
 
78
103
  # centos 7 with systemd
79
104
  it 'verify centos 7 package parsing' do
80
105
  resource = MockLoader.new(:centos7).load_resource('service', 'sshd')
81
- srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
82
- _(resource.info).must_equal srv
106
+ params = Hashie::Mash.new({ 'Description' => 'OpenSSH server daemon', 'Id' => 'sshd.service', 'LoadState' => 'loaded', 'Names' => 'sshd.service', 'SubState' => 'running', 'UnitFileState' => 'enabled' })
107
+ _(resource.type).must_equal 'systemd'
108
+ _(resource.name).must_equal 'sshd.service'
109
+ _(resource.description).must_equal 'OpenSSH server daemon'
83
110
  _(resource.installed?).must_equal true
84
111
  _(resource.enabled?).must_equal true
85
112
  _(resource.running?).must_equal true
113
+ _(resource.params).must_equal params
86
114
  end
87
115
 
88
116
  it 'verify centos 7 package parsing with systemd_service and service_ctl override' do
89
117
  resource = MockLoader.new(:centos7).load_resource('systemd_service', 'sshd', '/path/to/systemctl')
90
- srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
91
- _(resource.info).must_equal srv
118
+ params = Hashie::Mash.new({ 'Description' => 'OpenSSH server daemon', 'Id' => 'sshd.service', 'LoadState' => 'loaded', 'Names' => 'sshd.service', 'SubState' => 'running', 'UnitFileState' => 'enabled' })
119
+ _(resource.type).must_equal 'systemd'
120
+ _(resource.name).must_equal 'sshd.service'
121
+ _(resource.description).must_equal 'OpenSSH server daemon'
92
122
  _(resource.installed?).must_equal true
93
123
  _(resource.enabled?).must_equal true
94
124
  _(resource.running?).must_equal true
125
+ _(resource.params).must_equal params
95
126
  end
96
127
 
97
128
  it 'verify centos 7 package parsing with static loaded service' do
98
129
  resource = MockLoader.new(:centos7).load_resource('service', 'dbus')
99
- srv = { name: 'dbus.service', description: 'D-Bus System Message Bus', installed: true, running: true, enabled: true, type: 'systemd' }
100
- _(resource.info).must_equal srv
130
+ params = Hashie::Mash.new({ 'Description' => 'D-Bus System Message Bus', 'Id' => 'dbus.service', 'LoadState' => 'loaded', 'Names' => 'messagebus.service dbus.service', 'SubState' => 'running', 'UnitFileState' => 'static' })
131
+ _(resource.type).must_equal 'systemd'
132
+ _(resource.name).must_equal 'dbus.service'
133
+ _(resource.description).must_equal 'D-Bus System Message Bus'
101
134
  _(resource.installed?).must_equal true
102
135
  _(resource.enabled?).must_equal true
103
136
  _(resource.running?).must_equal true
137
+ _(resource.params).must_equal params
138
+ _(resource.params.UnitFileState).must_equal 'static'
104
139
  end
105
140
 
106
141
  # freebsd
107
142
  it 'verify freebsd10 package parsing' do
108
143
  resource = MockLoader.new(:freebsd10).load_resource('service', 'sendmail')
109
- srv = { name: 'sendmail', description: nil, installed: true, running: true, enabled: true, type: 'bsd-init' }
110
- _(resource.info).must_equal srv
144
+ params = Hashie::Mash.new({})
145
+ _(resource.type).must_equal 'bsd-init'
146
+ _(resource.name).must_equal 'sendmail'
147
+ _(resource.description).must_equal nil
111
148
  _(resource.installed?).must_equal true
112
149
  _(resource.enabled?).must_equal true
113
150
  _(resource.running?).must_equal true
151
+ _(resource.params).must_equal params
114
152
  end
115
153
 
116
154
  it 'verify freebsd10 package parsing with default bsd_service' do
117
155
  resource = MockLoader.new(:freebsd10).load_resource('bsd_service', 'sendmail')
118
- srv = { name: 'sendmail', description: nil, installed: true, running: true, enabled: true, type: 'bsd-init' }
119
- _(resource.info).must_equal srv
156
+ params = Hashie::Mash.new({})
157
+ _(resource.type).must_equal 'bsd-init'
158
+ _(resource.name).must_equal 'sendmail'
159
+ _(resource.description).must_equal nil
120
160
  _(resource.installed?).must_equal true
121
161
  _(resource.enabled?).must_equal true
122
162
  _(resource.running?).must_equal true
163
+ _(resource.params).must_equal params
123
164
  end
124
165
 
125
166
  # arch linux with systemd
126
167
  it 'verify arch linux package parsing' do
127
168
  resource = MockLoader.new(:arch).load_resource('service', 'sshd')
128
- srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
129
- _(resource.info).must_equal srv
169
+ params = Hashie::Mash.new({ 'Description' => 'OpenSSH server daemon', 'Id' => 'sshd.service', 'LoadState' => 'loaded', 'Names' => 'sshd.service', 'SubState' => 'running', 'UnitFileState' => 'enabled' })
170
+ _(resource.type).must_equal 'systemd'
171
+ _(resource.name).must_equal 'sshd.service'
172
+ _(resource.description).must_equal 'OpenSSH server daemon'
130
173
  _(resource.installed?).must_equal true
131
174
  _(resource.enabled?).must_equal true
132
175
  _(resource.running?).must_equal true
176
+ _(resource.params).must_equal params
133
177
  end
134
178
 
135
179
  # debian 7 with systemv
136
180
  it 'verify debian 7 package parsing' do
137
181
  resource = MockLoader.new(:debian7).load_resource('service', 'sshd')
138
- srv = { name: 'sshd', description: nil, installed: true, running: true, enabled: true, runlevels: runlevels, type: 'sysv' }
139
- _(resource.info).must_equal srv
182
+ params = Hashie::Mash.new({})
183
+ _(resource.type).must_equal 'sysv'
184
+ _(resource.name).must_equal 'sshd'
185
+ _(resource.description).must_equal nil
140
186
  _(resource.installed?).must_equal true
141
187
  _(resource.enabled?).must_equal true
142
188
  _(resource.running?).must_equal true
189
+ _(resource.params).must_equal params
143
190
  end
144
191
 
145
192
  # debian 8 with systemd
146
193
  it 'verify debian 8 package parsing' do
147
194
  resource = MockLoader.new(:debian8).load_resource('service', 'sshd')
148
- srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
149
- _(resource.info).must_equal srv
195
+ params = Hashie::Mash.new({ 'Description' => 'OpenSSH server daemon', 'Id' => 'sshd.service', 'LoadState' => 'loaded', 'Names' => 'sshd.service', 'SubState' => 'running', 'UnitFileState' => 'enabled' })
196
+ _(resource.type).must_equal 'systemd'
197
+ _(resource.name).must_equal 'sshd.service'
198
+ _(resource.description).must_equal 'OpenSSH server daemon'
150
199
  _(resource.installed?).must_equal true
151
200
  _(resource.enabled?).must_equal true
152
201
  _(resource.running?).must_equal true
202
+ _(resource.params).must_equal params
153
203
  end
154
204
 
155
205
  # macos test
156
206
  it 'verify mac osx package parsing' do
157
207
  resource = MockLoader.new(:osx104).load_resource('service', 'ssh')
158
- srv = { name: 'org.openbsd.ssh-agent', description: nil, installed: true, running: true, enabled: true, type: 'darwin' }
159
- _(resource.info).must_equal srv
208
+ params = Hashie::Mash.new({})
209
+ _(resource.type).must_equal 'darwin'
210
+ _(resource.name).must_equal 'org.openbsd.ssh-agent'
211
+ _(resource.description).must_equal nil
160
212
  _(resource.installed?).must_equal true
161
213
  _(resource.enabled?).must_equal true
162
214
  _(resource.running?).must_equal true
215
+ _(resource.params).must_equal params
163
216
  end
164
217
 
165
218
  it 'verify mac osx package parsing with not-running service' do
166
219
  resource = MockLoader.new(:osx104).load_resource('service', 'FilesystemUI')
167
- srv = { name: 'com.apple.FilesystemUI', description: nil, installed: true, running: false, enabled: true, type: 'darwin' }
168
- _(resource.info).must_equal srv
220
+ params = Hashie::Mash.new({})
221
+ _(resource.type).must_equal 'darwin'
222
+ _(resource.name).must_equal 'com.apple.FilesystemUI'
223
+ _(resource.description).must_equal nil
169
224
  _(resource.installed?).must_equal true
170
225
  _(resource.enabled?).must_equal true
171
226
  _(resource.running?).must_equal false
227
+ _(resource.params).must_equal params
172
228
  end
173
229
 
174
230
  it 'verify mac osx package parsing with default launchd_service' do
175
231
  resource = MockLoader.new(:osx104).load_resource('launchd_service', 'ssh')
176
- srv = { name: 'org.openbsd.ssh-agent', description: nil, installed: true, running: true, enabled: true, type: 'darwin' }
177
- _(resource.info).must_equal srv
232
+ params = Hashie::Mash.new({})
233
+ _(resource.type).must_equal 'darwin'
234
+ _(resource.name).must_equal 'org.openbsd.ssh-agent'
235
+ _(resource.description).must_equal nil
178
236
  _(resource.installed?).must_equal true
179
237
  _(resource.enabled?).must_equal true
180
238
  _(resource.running?).must_equal true
239
+ _(resource.params).must_equal params
181
240
  end
182
241
 
183
242
  # wrlinux
184
243
  it 'verify wrlinux package parsing' do
185
244
  resource = MockLoader.new(:wrlinux).load_resource('service', 'sshd')
186
- srv = { name: 'sshd', description: nil, installed: true, running: true, enabled: true, runlevels: runlevels, type: 'sysv' }
187
- _(resource.info).must_equal srv
245
+ params = Hashie::Mash.new({})
246
+ _(resource.type).must_equal 'sysv'
247
+ _(resource.name).must_equal 'sshd'
248
+ _(resource.description).must_equal nil
188
249
  _(resource.installed?).must_equal true
189
250
  _(resource.enabled?).must_equal true
190
251
  _(resource.running?).must_equal true
252
+ _(resource.params).must_equal params
191
253
  end
192
254
 
193
255
 
194
256
  # unknown OS
195
257
  it 'verify package handling on unsupported os' do
196
258
  resource = MockLoader.new(:undefined).load_resource('service', 'dhcp')
259
+ params = Hashie::Mash.new({})
197
260
  _(resource.installed?).must_equal false
198
- _(resource.info).must_equal nil
261
+ _(resource.description).must_equal nil
262
+ _(resource.params).must_equal params
199
263
  end
200
264
 
201
265
  # runlevel detection