inspec 0.21.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -2
- data/lib/bundles/inspec-supermarket.rb +0 -1
- data/lib/inspec/version.rb +1 -1
- data/lib/matchers/matchers.rb +7 -0
- data/lib/resources/processes.rb +49 -18
- data/test/helper.rb +1 -0
- data/test/integration/default/matcher.rb +9 -0
- data/test/unit/mock/cmd/ps-auxZ +3 -0
- data/test/unit/resources/processes_test.rb +29 -2
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a6c7098d367a3d561834016a1bfdd60d23c1253
|
4
|
+
data.tar.gz: da8753876169c48fbe087a1b16e92b13ab6185dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8adc2e483a203e77d2b0df1eb4d842570947474ca83e411967563e7f2e958d54f35733bda867586f28a472807e4dc5e851b81d0414e198788980d77a1241807
|
7
|
+
data.tar.gz: ab9eb448c12955d4b2b633113616d90d44f3732b10f1c65e871b07df627fdf7892f3d6b2e67ead38164491c9d37a9f8338b57292a6370b4410387c41221c2149
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [0.21.
|
4
|
-
[Full Changelog](https://github.com/chef/inspec/compare/v0.
|
3
|
+
## [0.21.1](https://github.com/chef/inspec/tree/0.21.1) (2016-05-10)
|
4
|
+
[Full Changelog](https://github.com/chef/inspec/compare/v0.21.0...0.21.1)
|
5
|
+
|
6
|
+
**Fixed bugs:**
|
7
|
+
|
8
|
+
- fix: remove non-existent class [\#729](https://github.com/chef/inspec/pull/729) ([chris-rock](https://github.com/chris-rock))
|
9
|
+
|
10
|
+
**Merged pull requests:**
|
11
|
+
|
12
|
+
- Expose label for processes only on linux [\#733](https://github.com/chef/inspec/pull/733) ([vjeffrey](https://github.com/vjeffrey))
|
13
|
+
- Add all\_match to matchers [\#730](https://github.com/chef/inspec/pull/730) ([vjeffrey](https://github.com/vjeffrey))
|
14
|
+
|
15
|
+
## [v0.21.0](https://github.com/chef/inspec/tree/v0.21.0) (2016-05-10)
|
16
|
+
[Full Changelog](https://github.com/chef/inspec/compare/v0.20.1...v0.21.0)
|
5
17
|
|
6
18
|
**Implemented enhancements:**
|
7
19
|
|
data/lib/inspec/version.rb
CHANGED
data/lib/matchers/matchers.rb
CHANGED
@@ -74,6 +74,13 @@ RSpec::Matchers.define :contain_legacy_plus do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
# matcher to check that all entries match the regex
|
78
|
+
RSpec::Matchers.define :all_match do |regex|
|
79
|
+
match do |arr|
|
80
|
+
arr.all? { |element| element.match(regex) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
77
84
|
# verifies that no entry in an array contains a value
|
78
85
|
RSpec::Matchers.define :contain_match do |regex|
|
79
86
|
match do |arr|
|
data/lib/resources/processes.rb
CHANGED
@@ -45,30 +45,61 @@ module Inspec::Resources
|
|
45
45
|
private
|
46
46
|
|
47
47
|
def ps_aux
|
48
|
-
|
49
|
-
|
48
|
+
os = inspec.os
|
49
|
+
|
50
|
+
if os.linux?
|
51
|
+
command = 'ps auxZ'
|
52
|
+
regex = /^([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+(.*)$/
|
53
|
+
else
|
54
|
+
command = 'ps aux'
|
55
|
+
regex = /^([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+(.*)$/
|
56
|
+
end
|
57
|
+
build_process_list(command, regex, os)
|
58
|
+
end
|
59
|
+
|
60
|
+
def build_process_list(command, regex, os) # rubocop:disable MethodLength, Metrics/AbcSize
|
61
|
+
cmd = inspec.command(command)
|
50
62
|
all = cmd.stdout.split("\n")[1..-1]
|
51
63
|
return [] if all.nil?
|
52
64
|
|
53
65
|
lines = all.map do |line|
|
54
|
-
|
55
|
-
line.match(/^([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+(.*)$/)
|
66
|
+
line.match(regex)
|
56
67
|
end.compact
|
57
68
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
if os.linux?
|
70
|
+
lines.map do |m|
|
71
|
+
{
|
72
|
+
label: m[1],
|
73
|
+
user: m[2],
|
74
|
+
pid: m[3].to_i,
|
75
|
+
cpu: m[4],
|
76
|
+
mem: m[5],
|
77
|
+
vsz: m[6].to_i,
|
78
|
+
rss: m[7].to_i,
|
79
|
+
tty: m[8],
|
80
|
+
stat: m[9],
|
81
|
+
start: m[10],
|
82
|
+
time: m[11],
|
83
|
+
command: m[12],
|
84
|
+
}
|
85
|
+
end
|
86
|
+
else
|
87
|
+
lines.map do |m|
|
88
|
+
{
|
89
|
+
label: nil,
|
90
|
+
user: m[1],
|
91
|
+
pid: m[2].to_i,
|
92
|
+
cpu: m[3],
|
93
|
+
mem: m[4],
|
94
|
+
vsz: m[5].to_i,
|
95
|
+
rss: m[6].to_i,
|
96
|
+
tty: m[7],
|
97
|
+
stat: m[8],
|
98
|
+
start: m[9],
|
99
|
+
time: m[10],
|
100
|
+
command: m[11],
|
101
|
+
}
|
102
|
+
end
|
72
103
|
end
|
73
104
|
end
|
74
105
|
end
|
data/test/helper.rb
CHANGED
@@ -137,6 +137,7 @@ class MockLoader
|
|
137
137
|
|
138
138
|
mock.commands = {
|
139
139
|
'ps aux' => cmd.call('ps-aux'),
|
140
|
+
'ps auxZ' => cmd.call('ps-auxZ'),
|
140
141
|
'Get-Content win_secpol.cfg' => cmd.call('secedit-export'),
|
141
142
|
'secedit /export /cfg win_secpol.cfg' => cmd.call('success'),
|
142
143
|
'Remove-Item win_secpol.cfg' => cmd.call('success'),
|
@@ -12,8 +12,9 @@ describe 'Inspec::Resources::Processes' do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'verify processes resource' do
|
15
|
-
resource = load_resource('processes', '/bin/bash')
|
15
|
+
resource = MockLoader.new(:freebsd10).load_resource('processes', '/bin/bash')
|
16
16
|
_(resource.list).must_equal [{
|
17
|
+
label: nil,
|
17
18
|
user: 'root',
|
18
19
|
pid: 1,
|
19
20
|
cpu: '0.0',
|
@@ -30,9 +31,35 @@ describe 'Inspec::Resources::Processes' do
|
|
30
31
|
_(resource.list.length).must_equal 1
|
31
32
|
end
|
32
33
|
|
34
|
+
it 'verify processes resource on linux os' do
|
35
|
+
resource = MockLoader.new(:centos6).load_resource('processes', '/sbin/init')
|
36
|
+
_(resource.list).must_equal [{
|
37
|
+
label: 'system_u:system_r:kernel_t:s0',
|
38
|
+
user: 'root',
|
39
|
+
pid: 1,
|
40
|
+
cpu: '0.0',
|
41
|
+
mem: '0.0',
|
42
|
+
vsz: 19232,
|
43
|
+
rss: 1492,
|
44
|
+
tty: '?',
|
45
|
+
stat: 'Ss',
|
46
|
+
start: 'May04',
|
47
|
+
time: '0:01',
|
48
|
+
command: '/sbin/init',
|
49
|
+
}]
|
50
|
+
|
51
|
+
_(resource.list.length).must_equal 1
|
52
|
+
end
|
53
|
+
|
33
54
|
it 'retrieves the users and states as arrays' do
|
34
|
-
resource = load_resource('processes', 'svc')
|
55
|
+
resource = MockLoader.new(:freebsd10).load_resource('processes', 'svc')
|
35
56
|
_(resource.users.sort).must_equal ['noot']
|
36
57
|
_(resource.states.sort).must_equal ['S', 'Ss']
|
37
58
|
end
|
59
|
+
|
60
|
+
it 'retrieves the users and states as arrays on linux os' do
|
61
|
+
resource = MockLoader.new(:centos6).load_resource('processes', 'crypto/0')
|
62
|
+
_(resource.users.sort).must_equal ['root']
|
63
|
+
_(resource.states.sort).must_equal ['S']
|
64
|
+
end
|
38
65
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.21.
|
4
|
+
version: 0.21.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
@@ -411,6 +411,7 @@ files:
|
|
411
411
|
- test/integration/default/json_spec.rb
|
412
412
|
- test/integration/default/kernel_module_spec.rb
|
413
413
|
- test/integration/default/kernel_parameter_spec.rb
|
414
|
+
- test/integration/default/matcher.rb
|
414
415
|
- test/integration/default/mount_spec.rb
|
415
416
|
- test/integration/default/os_spec.rb
|
416
417
|
- test/integration/default/package_spec.rb
|
@@ -496,6 +497,7 @@ files:
|
|
496
497
|
- test/unit/mock/cmd/pkg-info-system-file-system-zfs
|
497
498
|
- test/unit/mock/cmd/pkginfo-l-SUNWzfsr
|
498
499
|
- test/unit/mock/cmd/ps-aux
|
500
|
+
- test/unit/mock/cmd/ps-auxZ
|
499
501
|
- test/unit/mock/cmd/pw-usershow-root-7
|
500
502
|
- test/unit/mock/cmd/reg_schedule
|
501
503
|
- test/unit/mock/cmd/rpm-qia-curl
|
@@ -685,6 +687,7 @@ test_files:
|
|
685
687
|
- test/integration/default/json_spec.rb
|
686
688
|
- test/integration/default/kernel_module_spec.rb
|
687
689
|
- test/integration/default/kernel_parameter_spec.rb
|
690
|
+
- test/integration/default/matcher.rb
|
688
691
|
- test/integration/default/mount_spec.rb
|
689
692
|
- test/integration/default/os_spec.rb
|
690
693
|
- test/integration/default/package_spec.rb
|
@@ -770,6 +773,7 @@ test_files:
|
|
770
773
|
- test/unit/mock/cmd/pkg-info-system-file-system-zfs
|
771
774
|
- test/unit/mock/cmd/pkginfo-l-SUNWzfsr
|
772
775
|
- test/unit/mock/cmd/ps-aux
|
776
|
+
- test/unit/mock/cmd/ps-auxZ
|
773
777
|
- test/unit/mock/cmd/pw-usershow-root-7
|
774
778
|
- test/unit/mock/cmd/reg_schedule
|
775
779
|
- test/unit/mock/cmd/rpm-qia-curl
|