inspec 1.45.13 → 1.46.2
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 +25 -12
- data/docs/resources/file.md.erb +14 -0
- data/docs/resources/kernel_module.md.erb +34 -35
- data/examples/kitchen-ansible/Gemfile +0 -1
- data/examples/kitchen-chef/Gemfile +0 -1
- data/examples/kitchen-puppet/Gemfile +0 -1
- data/lib/inspec/objects/attribute.rb +2 -2
- data/lib/inspec/version.rb +1 -1
- data/lib/resources/csv.rb +8 -2
- data/lib/resources/file.rb +2 -0
- data/lib/resources/grub_conf.rb +1 -1
- data/lib/resources/http.rb +11 -1
- data/lib/resources/ini.rb +6 -2
- data/lib/resources/json.rb +59 -40
- data/lib/resources/toml.rb +8 -2
- data/lib/resources/wmi.rb +2 -2
- data/lib/resources/xml.rb +8 -2
- data/lib/resources/yaml.rb +8 -2
- data/lib/utils/filter.rb +55 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 275cc93db905d4d442e1c7c897a197c0123e1671
|
4
|
+
data.tar.gz: '097b235e017ce4fdde8e890a12e4221de4fd7330'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4424e307b2c5d474cb040e4fa023f98c9507c764edd84684cb286bf21c36a83395f5cd2d8a4f1f87d14a271e7b0a6d281eabe140065dcdd012f3780f3d390d1
|
7
|
+
data.tar.gz: 35a966232190612e93daac133334c5f7f2f5c705261d0155dc2758168c0f2b15865cfd52f47d635065a754f4b1f239216dd5c1574a4657024d0d92a008c6e0b4
|
data/CHANGELOG.md
CHANGED
@@ -1,23 +1,37 @@
|
|
1
1
|
# Change Log
|
2
2
|
<!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
|
3
|
-
<!-- latest_release 1.
|
4
|
-
## [v1.
|
3
|
+
<!-- latest_release 1.46.2 -->
|
4
|
+
## [v1.46.2](https://github.com/chef/inspec/tree/v1.46.2) (2017-11-29)
|
5
5
|
|
6
|
-
####
|
7
|
-
-
|
6
|
+
#### Bug Fixes
|
7
|
+
- Allow skipping/failing resources in FilterTable [#2349](https://github.com/chef/inspec/pull/2349) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
|
8
8
|
<!-- latest_release -->
|
9
9
|
|
10
|
-
<!-- release_rollup since=1.45.
|
11
|
-
### Changes since 1.45.
|
10
|
+
<!-- release_rollup since=1.45.13 -->
|
11
|
+
### Changes since 1.45.13 release
|
12
12
|
|
13
|
-
####
|
14
|
-
-
|
15
|
-
|
16
|
-
|
17
|
-
-
|
13
|
+
#### Enhancements
|
14
|
+
- allow override of attribute identifier [#2347](https://github.com/chef/inspec/pull/2347) ([chris-rock](https://github.com/chris-rock)) <!-- 1.46.0 -->
|
15
|
+
|
16
|
+
#### Bug Fixes
|
17
|
+
- Allow skipping/failing resources in FilterTable [#2349](https://github.com/chef/inspec/pull/2349) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 1.46.2 -->
|
18
|
+
- wmi resource: properly escape quotes in WMI query [#2342](https://github.com/chef/inspec/pull/2342) ([TheLonelyGhost](https://github.com/TheLonelyGhost)) <!-- 1.46.1 -->
|
19
|
+
- file resource: fix NilClass error when using advanced windows permissions [#2344](https://github.com/chef/inspec/pull/2344) ([TheLonelyGhost](https://github.com/TheLonelyGhost)) <!-- 1.45.17 -->
|
20
|
+
- http resource: properly support HEAD request with remote worker [#2340](https://github.com/chef/inspec/pull/2340) ([adamleff](https://github.com/adamleff)) <!-- 1.45.16 -->
|
21
|
+
- grub_conf resource: correct grub path for RHEL-7-based OS [#2332](https://github.com/chef/inspec/pull/2332) ([atomic111](https://github.com/atomic111)) <!-- 1.45.15 -->
|
22
|
+
- json resource (et. al.): allow inspec check to succeed when using command [#2317](https://github.com/chef/inspec/pull/2317) ([adamleff](https://github.com/adamleff)) <!-- 1.45.14 -->
|
18
23
|
<!-- release_rollup -->
|
19
24
|
|
20
25
|
<!-- latest_stable_release -->
|
26
|
+
## [v1.45.13](https://github.com/chef/inspec/tree/v1.45.13) (2017-11-21)
|
27
|
+
|
28
|
+
#### Merged Pull Requests
|
29
|
+
- Remove debug message from unit test [#2313](https://github.com/chef/inspec/pull/2313) ([eramoto](https://github.com/eramoto))
|
30
|
+
- Remove bundler install during Appveyor tests [#2322](https://github.com/chef/inspec/pull/2322) ([adamleff](https://github.com/adamleff))
|
31
|
+
- Bump Rubocop to 0.49.1 [#2323](https://github.com/chef/inspec/pull/2323) ([adamleff](https://github.com/adamleff))
|
32
|
+
- Bump train to 0.29.2 [#2327](https://github.com/chef/inspec/pull/2327) ([adamleff](https://github.com/adamleff))
|
33
|
+
<!-- latest_stable_release -->
|
34
|
+
|
21
35
|
## [v1.45.9](https://github.com/chef/inspec/tree/v1.45.9) (2017-11-16)
|
22
36
|
|
23
37
|
#### Enhancements
|
@@ -36,7 +50,6 @@
|
|
36
50
|
- Fix gid filtering for etc_group resource [#2297](https://github.com/chef/inspec/pull/2297) ([eramoto](https://github.com/eramoto))
|
37
51
|
- Require Ruby 2.3 and later [#2293](https://github.com/chef/inspec/pull/2293) ([adamleff](https://github.com/adamleff))
|
38
52
|
- Update Rubocop to TargetRubyVersion 2.3 [#2311](https://github.com/chef/inspec/pull/2311) ([adamleff](https://github.com/adamleff))
|
39
|
-
<!-- latest_stable_release -->
|
40
53
|
|
41
54
|
## [v1.44.8](https://github.com/chef/inspec/tree/v1.44.8) (2017-11-09)
|
42
55
|
|
data/docs/resources/file.md.erb
CHANGED
@@ -200,6 +200,20 @@ For example, for the following symlink:
|
|
200
200
|
|
201
201
|
This InSpec audit resource has the following matchers. For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
202
202
|
|
203
|
+
### be\_allowed
|
204
|
+
|
205
|
+
The `be_allowed` matcher tests if the file contains a certain permission set, such as `execute` or `write` in Unix and [`full-control` or `modify` in Windows](https://www.codeproject.com/Reference/871338/AccessControl-FileSystemRights-Permissions-Table).
|
206
|
+
|
207
|
+
it { should be_allowed('read') }
|
208
|
+
|
209
|
+
Just like with `be_executable` and other permissions, one can check for the permission with respect to the specific user or group.
|
210
|
+
|
211
|
+
it { should be_allowed('full-control', by_user: 'MyComputerName\Administrator') }
|
212
|
+
|
213
|
+
OR
|
214
|
+
|
215
|
+
it { should be_allowed('write', by: 'root') }
|
216
|
+
|
203
217
|
### be\_block\_device
|
204
218
|
|
205
219
|
The `be_block_device` matcher tests if the file exists as a block device, such as `/dev/disk0` or `/dev/disk0s9`:
|
@@ -25,7 +25,6 @@ blacklisted:
|
|
25
25
|
it { should_not be_disabled }
|
26
26
|
it { should_not be_blacklisted }
|
27
27
|
end
|
28
|
-
end
|
29
28
|
|
30
29
|
where
|
31
30
|
|
@@ -40,53 +39,53 @@ where
|
|
40
39
|
|
41
40
|
The following examples show how to use this InSpec audit resource.
|
42
41
|
|
43
|
-
|
42
|
+
### Test a modules 'version'
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
describe kernel_module('bridge') do
|
45
|
+
it { should be_loaded }
|
46
|
+
its(:version) { should cmp >= '2.2.2' }
|
47
|
+
end
|
49
48
|
|
50
|
-
|
49
|
+
### Test if a module is loaded, not disabled and not blacklisted
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
describe kernel_module('video') do
|
52
|
+
it { should be_loaded }
|
53
|
+
it { should_not be_disabled }
|
54
|
+
it { should_not be_blacklisted }
|
55
|
+
end
|
57
56
|
|
58
|
-
|
57
|
+
### Check if a module is blacklisted
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
describe kernel_module('floppy') do
|
60
|
+
it { should be_blacklisted }
|
61
|
+
end
|
63
62
|
|
64
|
-
|
63
|
+
### Ensure a module is *not* blacklisted and it is loaded
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
describe kernel_module('video') do
|
66
|
+
it { should_not be_blacklisted }
|
67
|
+
it { should be_loaded }
|
68
|
+
end
|
70
69
|
|
71
|
-
|
70
|
+
### Ensure a module is disabled via 'bin_false'
|
72
71
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
describe kernel_module('sstfb') do
|
73
|
+
it { should_not be_loaded }
|
74
|
+
it { should be_disabled }
|
75
|
+
end
|
77
76
|
|
78
|
-
|
77
|
+
### Ensure a module is 'blacklisted'/'disabled' via 'bin_true'
|
79
78
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
describe kernel_module('nvidiafb') do
|
80
|
+
it { should_not be_loaded }
|
81
|
+
it { should be_blacklisted }
|
82
|
+
end
|
84
83
|
|
85
|
-
|
84
|
+
### Ensure a module is not loaded
|
86
85
|
|
87
|
-
|
88
|
-
|
89
|
-
|
86
|
+
describe kernel_module('dhcp') do
|
87
|
+
it { should_not be_loaded }
|
88
|
+
end
|
90
89
|
|
91
90
|
<br>
|
92
91
|
|
@@ -39,7 +39,7 @@ module Inspec
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def ruby_var_identifier
|
42
|
-
'attr_' + @name.downcase.strip.gsub(/\s+/, '-').gsub(/[^\w-]/, '')
|
42
|
+
@opts[:identifier] || 'attr_' + @name.downcase.strip.gsub(/\s+/, '-').gsub(/[^\w-]/, '')
|
43
43
|
end
|
44
44
|
|
45
45
|
def to_hash
|
@@ -52,7 +52,7 @@ module Inspec
|
|
52
52
|
def to_ruby
|
53
53
|
res = ["#{ruby_var_identifier} = attribute('#{@name}',{"]
|
54
54
|
res.push " title: '#{title}'," unless title.to_s.empty?
|
55
|
-
res.push " default:
|
55
|
+
res.push " default: #{default.inspect}," unless default.to_s.empty?
|
56
56
|
res.push " description: '#{description}'," unless description.to_s.empty?
|
57
57
|
res.push '})'
|
58
58
|
res.join("\n")
|
data/lib/inspec/version.rb
CHANGED
data/lib/resources/csv.rb
CHANGED
@@ -34,6 +34,8 @@ module Inspec::Resources
|
|
34
34
|
|
35
35
|
# convert to hash
|
36
36
|
csv.to_a.map(&:to_hash)
|
37
|
+
rescue => e
|
38
|
+
raise Inspec::Exceptions::ResourceFailed, "Unable to parse CSV: #{e.message}"
|
37
39
|
end
|
38
40
|
|
39
41
|
# override the value method from JsonConfig
|
@@ -45,8 +47,12 @@ module Inspec::Resources
|
|
45
47
|
@params.map { |x| x[key.first.to_s] }.compact
|
46
48
|
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
+
private
|
51
|
+
|
52
|
+
# used by JsonConfig to build up a full to_s method
|
53
|
+
# based on whether a file path, content, or command was supplied.
|
54
|
+
def resource_base_name
|
55
|
+
'CSV'
|
50
56
|
end
|
51
57
|
end
|
52
58
|
end
|
data/lib/resources/file.rb
CHANGED
@@ -240,6 +240,8 @@ module Inspec::Resources
|
|
240
240
|
names ||= translate_granular_perms(access_type)
|
241
241
|
names ||= translate_uncommon_perms(access_type)
|
242
242
|
raise 'Invalid access_type provided' unless names
|
243
|
+
|
244
|
+
names
|
243
245
|
end
|
244
246
|
|
245
247
|
def translate_common_perms(access_type)
|
data/lib/resources/grub_conf.rb
CHANGED
@@ -50,7 +50,7 @@ class GrubConfig < Inspec.resource(1) # rubocop:disable Metrics/ClassLength
|
|
50
50
|
@conf_path = path || '/etc/grub.conf'
|
51
51
|
@version = 'legacy'
|
52
52
|
else
|
53
|
-
@conf_path = path || '/boot/
|
53
|
+
@conf_path = path || '/boot/grub2/grub.cfg'
|
54
54
|
@defaults_path = '/etc/default/grub'
|
55
55
|
@version = 'grub2'
|
56
56
|
end
|
data/lib/resources/http.rb
CHANGED
@@ -203,7 +203,17 @@ module Inspec::Resources
|
|
203
203
|
end
|
204
204
|
|
205
205
|
def curl_command # rubocop:disable Metrics/AbcSize
|
206
|
-
cmd = [
|
206
|
+
cmd = ['curl -i']
|
207
|
+
|
208
|
+
# Use curl's --head option when the method requested is HEAD. Otherwise,
|
209
|
+
# the user may experience a timeout when curl does not properly close
|
210
|
+
# the connection after the response is received.
|
211
|
+
if http_method.casecmp('HEAD') == 0
|
212
|
+
cmd << '--head'
|
213
|
+
else
|
214
|
+
cmd << "-X #{http_method}"
|
215
|
+
end
|
216
|
+
|
207
217
|
cmd << "--connect-timeout #{open_timeout}"
|
208
218
|
cmd << "--max-time #{open_timeout+read_timeout}"
|
209
219
|
cmd << "--user \'#{username}:#{password}\'" unless username.nil? || password.nil?
|
data/lib/resources/ini.rb
CHANGED
@@ -18,8 +18,12 @@ module Inspec::Resources
|
|
18
18
|
SimpleConfig.new(content).params
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
private
|
22
|
+
|
23
|
+
# used by JsonConfig to build up a full to_s method
|
24
|
+
# based on whether a file path, content, or command was supplied.
|
25
|
+
def resource_base_name
|
26
|
+
'INI'
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
data/lib/resources/json.rb
CHANGED
@@ -26,45 +26,11 @@ module Inspec::Resources
|
|
26
26
|
include ObjectTraverser
|
27
27
|
|
28
28
|
# make params readable
|
29
|
-
attr_reader :params
|
29
|
+
attr_reader :params, :raw_content
|
30
30
|
|
31
31
|
def initialize(opts)
|
32
|
-
@
|
33
|
-
|
34
|
-
if opts.key?(:content)
|
35
|
-
@file_content = opts[:content]
|
36
|
-
elsif opts.key?(:command)
|
37
|
-
@command = inspec.command(opts[:command])
|
38
|
-
@file_content = @command.stdout
|
39
|
-
end
|
40
|
-
else
|
41
|
-
@path = opts
|
42
|
-
@file = inspec.file(@opts)
|
43
|
-
@file_content = @file.content
|
44
|
-
|
45
|
-
# check if file is available
|
46
|
-
if !@file.file?
|
47
|
-
skip_resource "Can't find file \"#{@path}\""
|
48
|
-
return @params = {}
|
49
|
-
end
|
50
|
-
|
51
|
-
# check if file is readable
|
52
|
-
if @file_content.nil? && !@file.empty?
|
53
|
-
skip_resource "Can't read file \"#{@path}\""
|
54
|
-
return @params = {}
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
@params = parse(@file_content)
|
59
|
-
end
|
60
|
-
|
61
|
-
def parse(content)
|
62
|
-
require 'json'
|
63
|
-
JSON.parse(content)
|
64
|
-
end
|
65
|
-
|
66
|
-
def value(key)
|
67
|
-
extract_value(key, @params)
|
32
|
+
@raw_content = load_raw_content(opts)
|
33
|
+
@params = parse(@raw_content)
|
68
34
|
end
|
69
35
|
|
70
36
|
# Shorthand to retrieve a parameter name via `#its`.
|
@@ -79,12 +45,65 @@ module Inspec::Resources
|
|
79
45
|
value(keys)
|
80
46
|
end
|
81
47
|
|
48
|
+
def value(key)
|
49
|
+
# uses ObjectTraverser.extract_value to walk the hash looking for the key,
|
50
|
+
# which may be an Array of keys for a nested Hash.
|
51
|
+
extract_value(key, params)
|
52
|
+
end
|
53
|
+
|
82
54
|
def to_s
|
83
|
-
|
84
|
-
|
55
|
+
"#{resource_base_name} #{@resource_name_supplement || 'content'}"
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def parse(content)
|
61
|
+
require 'json'
|
62
|
+
JSON.parse(content)
|
63
|
+
rescue => e
|
64
|
+
raise Inspec::Exceptions::ResourceFailed, "Unable to parse JSON: #{e.message}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def load_raw_content(opts)
|
68
|
+
# if the opts isn't a hash, we assume it's a path to a file
|
69
|
+
unless opts.is_a?(Hash)
|
70
|
+
@resource_name_supplement = opts
|
71
|
+
return load_raw_from_file(opts)
|
72
|
+
end
|
73
|
+
|
74
|
+
if opts.key?(:command)
|
75
|
+
@resource_name_supplement = "from command: #{opts[:command]}"
|
76
|
+
load_raw_from_command(opts[:command])
|
77
|
+
elsif opts.key?(:content)
|
78
|
+
opts[:content]
|
85
79
|
else
|
86
|
-
|
80
|
+
raise Inspec::Exceptions::ResourceFailed, 'No JSON content; must specify a file, command, or raw JSON content'
|
87
81
|
end
|
88
82
|
end
|
83
|
+
|
84
|
+
def load_raw_from_file(path)
|
85
|
+
file = inspec.file(path)
|
86
|
+
|
87
|
+
# these are currently ResourceSkipped to maintain consistency with the resource
|
88
|
+
# pre-refactor (which used skip_resource). These should likely be changed to
|
89
|
+
# ResourceFailed during a major version bump.
|
90
|
+
raise Inspec::Exceptions::ResourceSkipped, "No such file: #{path}" unless file.file?
|
91
|
+
raise Inspec::Exceptions::ResourceSkipped, "File #{path} is empty or is not readable by current user" if file.content.nil? || file.content.empty?
|
92
|
+
|
93
|
+
file.content
|
94
|
+
end
|
95
|
+
|
96
|
+
def load_raw_from_command(command)
|
97
|
+
command_output = inspec.command(command).stdout
|
98
|
+
raise Inspec::Exceptions::ResourceSkipped, "No output from command: #{command}" if command_output.nil? || command_output.empty?
|
99
|
+
|
100
|
+
command_output
|
101
|
+
end
|
102
|
+
|
103
|
+
# for resources the subclass JsonConfig, this allows specification of the resource
|
104
|
+
# base name in each subclass so we can build a good to_s method
|
105
|
+
def resource_base_name
|
106
|
+
'JSON'
|
107
|
+
end
|
89
108
|
end
|
90
109
|
end
|
data/lib/resources/toml.rb
CHANGED
@@ -17,10 +17,16 @@ module Inspec::Resources
|
|
17
17
|
|
18
18
|
def parse(content)
|
19
19
|
Tomlrb.parse(content)
|
20
|
+
rescue => e
|
21
|
+
raise Inspec::Exceptions::ResourceFailed, "Unable to parse TOML: #{e.message}"
|
20
22
|
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
private
|
25
|
+
|
26
|
+
# used by JsonConfig to build up a full to_s method
|
27
|
+
# based on whether a file path, content, or command was supplied.
|
28
|
+
def resource_base_name
|
29
|
+
'TOML'
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
data/lib/resources/wmi.rb
CHANGED
@@ -27,7 +27,7 @@ module Inspec::Resources
|
|
27
27
|
|
28
28
|
def initialize(wmiclass = nil, opts = nil)
|
29
29
|
# verify that this resource is only supported on Windows
|
30
|
-
return skip_resource 'The `
|
30
|
+
return skip_resource 'The `wmi` resource is not supported on your OS.' unless inspec.os.windows?
|
31
31
|
|
32
32
|
@options = opts || {}
|
33
33
|
# if wmiclass is not a hash, we have to handle deprecation behavior
|
@@ -67,7 +67,7 @@ module Inspec::Resources
|
|
67
67
|
|
68
68
|
# convert to Get-WmiObject arguments
|
69
69
|
params = ''
|
70
|
-
args.each { |key, value| params += " -#{key} \"#{value}\"" }
|
70
|
+
args.each { |key, value| params += " -#{key} \"#{value.gsub('"', '`"')}\"" }
|
71
71
|
|
72
72
|
# run wmi command and filter empty wmi
|
73
73
|
script = <<-EOH
|
data/lib/resources/xml.rb
CHANGED
@@ -14,14 +14,20 @@ module Inspec::Resources
|
|
14
14
|
def parse(content)
|
15
15
|
require 'rexml/document'
|
16
16
|
REXML::Document.new(content)
|
17
|
+
rescue => e
|
18
|
+
raise Inspec::Exceptions::ResourceFailed, "Unable to parse XML: #{e.message}"
|
17
19
|
end
|
18
20
|
|
19
21
|
def value(key)
|
20
22
|
REXML::XPath.each(@params, key.first.to_s).map(&:text)
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
private
|
26
|
+
|
27
|
+
# used by JsonConfig to build up a full to_s method
|
28
|
+
# based on whether a file path, content, or command was supplied.
|
29
|
+
def resource_base_name
|
30
|
+
'XML'
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
data/lib/resources/yaml.rb
CHANGED
@@ -30,10 +30,16 @@ module Inspec::Resources
|
|
30
30
|
# override file load and parse hash from yaml
|
31
31
|
def parse(content)
|
32
32
|
YAML.load(content)
|
33
|
+
rescue => e
|
34
|
+
raise Inspec::Exceptions::ResourceFailed, "Unable to parse YAML: #{e.message}"
|
33
35
|
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
+
private
|
38
|
+
|
39
|
+
# used by JsonConfig to build up a full to_s method
|
40
|
+
# based on whether a file path, content, or command was supplied.
|
41
|
+
def resource_base_name
|
42
|
+
'YAML'
|
37
43
|
end
|
38
44
|
end
|
39
45
|
end
|
data/lib/utils/filter.rb
CHANGED
@@ -6,6 +6,48 @@
|
|
6
6
|
module FilterTable
|
7
7
|
module Show; end
|
8
8
|
|
9
|
+
class ExceptionCatcher
|
10
|
+
def initialize(original_resource, original_exception)
|
11
|
+
@original_resource = original_resource
|
12
|
+
@original_exception = original_exception
|
13
|
+
end
|
14
|
+
|
15
|
+
# This method is called via the runner and signals RSpec to output a block
|
16
|
+
# showing why the resource was skipped. This prevents the resource from
|
17
|
+
# being added to the test collection and being evaluated.
|
18
|
+
def resource_skipped?
|
19
|
+
@original_exception.is_a?(Inspec::Exceptions::ResourceSkipped)
|
20
|
+
end
|
21
|
+
|
22
|
+
# This method is called via the runner and signals RSpec to output a block
|
23
|
+
# showing why the resource failed. This prevents the resource from
|
24
|
+
# being added to the test collection and being evaluated.
|
25
|
+
def resource_failed?
|
26
|
+
@original_exception.is_a?(Inspec::Exceptions::ResourceFailed)
|
27
|
+
end
|
28
|
+
|
29
|
+
def resource_exception_message
|
30
|
+
@original_exception.message
|
31
|
+
end
|
32
|
+
|
33
|
+
# Capture message chains and return `ExceptionCatcher` objects
|
34
|
+
def method_missing(*)
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
# RSpec will check the object returned to see if it responds to a method
|
39
|
+
# before calling it. We need to fake it out and tell it that it does. This
|
40
|
+
# allows it to skip past that check and fall through to #method_missing
|
41
|
+
def respond_to?(_method)
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
@original_resource.to_s
|
47
|
+
end
|
48
|
+
alias inspect to_s
|
49
|
+
end
|
50
|
+
|
9
51
|
class Trace
|
10
52
|
def initialize
|
11
53
|
@chain = []
|
@@ -140,7 +182,7 @@ module FilterTable
|
|
140
182
|
@connectors = {}
|
141
183
|
end
|
142
184
|
|
143
|
-
def connect(resource, table_accessor)
|
185
|
+
def connect(resource, table_accessor) # rubocop:disable Metrics/AbcSize
|
144
186
|
# create the table structure
|
145
187
|
connectors = @connectors
|
146
188
|
struct_fields = connectors.values.map(&:field_name)
|
@@ -170,12 +212,21 @@ module FilterTable
|
|
170
212
|
end
|
171
213
|
}
|
172
214
|
|
173
|
-
#
|
215
|
+
# Define all access methods with the parent resource
|
216
|
+
# These methods will be configured to return an `ExceptionCatcher` object
|
217
|
+
# that will always return the original exception, but only when called
|
218
|
+
# upon. This will allow method chains in `describe` statements to pass the
|
219
|
+
# `instance_eval` when loaded and only throw-and-catch the exception when
|
220
|
+
# the tests are run.
|
174
221
|
accessors = @accessors + @connectors.keys
|
175
222
|
accessors.each do |method_name|
|
176
223
|
resource.send(:define_method, method_name.to_sym) do |*args, &block|
|
177
|
-
|
178
|
-
|
224
|
+
begin
|
225
|
+
filter = table.new(self, method(table_accessor).call, ' with')
|
226
|
+
filter.method(method_name.to_sym).call(*args, &block)
|
227
|
+
rescue Inspec::Exceptions::ResourceFailed, Inspec::Exceptions::ResourceSkipped => e
|
228
|
+
FilterTable::ExceptionCatcher.new(resource, e)
|
229
|
+
end
|
179
230
|
end
|
180
231
|
end
|
181
232
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.46.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: train
|