inspec 0.21.0 → 0.21.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 609dd579538c5f1f9a4f86acf691fee0270ad878
4
- data.tar.gz: c4d6ae9ca27a55efca499a37ee70d71c50e2ff42
3
+ metadata.gz: 1a6c7098d367a3d561834016a1bfdd60d23c1253
4
+ data.tar.gz: da8753876169c48fbe087a1b16e92b13ab6185dd
5
5
  SHA512:
6
- metadata.gz: 29a47097ef98d5ddafc0c145bfff580ac74762538e3de8ef9d5730e210f0a76a478d084acf344f3668b946bee98c03102f8248d4d0632bcc12b5d94cf574b3e9
7
- data.tar.gz: 65fb88edad1729f9968024c37e9466824d467f290c14f233ca87e70e1792d96cac3a37d9cd36ec2177ac0a64e7f0038225d38911183525e74c4ad23374f68472
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.0](https://github.com/chef/inspec/tree/0.21.0) (2016-05-10)
4
- [Full Changelog](https://github.com/chef/inspec/compare/v0.20.1...0.21.0)
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
 
@@ -6,7 +6,6 @@ libdir = File.dirname(__FILE__)
6
6
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
7
7
 
8
8
  module Supermarket
9
- autoload :Configuration, 'inspec-supermarket/configuration'
10
9
  autoload :API, 'inspec-supermarket/api'
11
10
  end
12
11
 
@@ -3,5 +3,5 @@
3
3
  # author: Christoph Hartmann
4
4
 
5
5
  module Inspec
6
- VERSION = '0.21.0'.freeze
6
+ VERSION = '0.21.1'.freeze
7
7
  end
@@ -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|
@@ -45,30 +45,61 @@ module Inspec::Resources
45
45
  private
46
46
 
47
47
  def ps_aux
48
- # get all running processes
49
- cmd = inspec.command('ps aux')
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
- # user 32296 0.0 0.0 42592 7972 pts/15 Ss+ Apr06 0:00 zsh
55
- line.match(/^([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+(.*)$/)
66
+ line.match(regex)
56
67
  end.compact
57
68
 
58
- lines.map do |m|
59
- {
60
- user: m[1],
61
- pid: m[2].to_i,
62
- cpu: m[3],
63
- mem: m[4],
64
- vsz: m[5].to_i,
65
- rss: m[6].to_i,
66
- tty: m[7],
67
- stat: m[8],
68
- start: m[9],
69
- time: m[10],
70
- command: m[11],
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'),
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ describe ['ananas', 'apples', 'oranges', 'air', 'alot'] do
4
+ it { should all_match /[a]./}
5
+ end
6
+
7
+ describe ['ananas', 'apples', 'oranges', 'air', 'melons'] do
8
+ it { should_not all_match /[a]./}
9
+ end
@@ -0,0 +1,3 @@
1
+ LABEL USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
2
+ system_u:system_r:kernel_t:s0 root 1 0.0 0.0 19232 1492 ? Ss May04 0:01 /sbin/init
3
+ system_u:system_r:kernel_t:s0 root 39 0.0 0.0 0 0 ? S May04 0:00 crypto/0
@@ -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.0
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