xinetd_conf resource: fix false positives with config file or directory doesn't exist (#2302)

xinetd_conf resource: fix false positives when config file or directory doesn't exist
This commit is contained in:
eramoto 2017-11-16 05:56:39 +09:00 committed by Adam Leff
parent e403dd6e9f
commit 986c8818d3
2 changed files with 6 additions and 8 deletions

View file

@ -53,15 +53,14 @@ module Inspec::Resources
return @contents[path] if @contents.key?(path)
file = inspec.file(path)
if !file.file?
return skip_resource "Can't find file \"#{path}\""
raise Inspec::Exceptions::ResourceSkipped, "Can't find file: #{path}"
end
if file.content.nil? || file.content.empty?
raise Inspec::Exceptions::ResourceSkipped, "Can't read file: #{path}"
end
@contents[path] = file.content
if @contents[path].nil? || @contents[path].empty?
return skip_resource "Can't read file \"#{path}\""
end
@contents[path]
end
def read_params
@ -69,7 +68,6 @@ module Inspec::Resources
flat_params = parse_xinetd(read_content)
# we need to map service data in order to use it with filtertable
params = { 'services' => {} }
# map services that were defined and map it to the service hash
flat_params.each do |k, v|
name = k[/^service (.+)$/, 1]

View file

@ -217,7 +217,7 @@ module XinetdParser
return [] if dir.nil?
unless inspec.file(dir).directory?
return skip_resource "Cannot read folder in #{dir}"
raise Inspec::Exceptions::ResourceSkipped, "Can't find folder: #{dir}"
end
files = inspec.command("find #{dir} -type f").stdout.split("\n")