From 986c8818d38a296202b7e57d03ef883dd3a76fc6 Mon Sep 17 00:00:00 2001 From: eramoto Date: Thu, 16 Nov 2017 05:56:39 +0900 Subject: [PATCH] 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 --- lib/resources/xinetd.rb | 12 +++++------- lib/utils/parser.rb | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/resources/xinetd.rb b/lib/resources/xinetd.rb index c5218cbdd..d62d921cf 100644 --- a/lib/resources/xinetd.rb +++ b/lib/resources/xinetd.rb @@ -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] diff --git a/lib/utils/parser.rb b/lib/utils/parser.rb index 672f44ed6..c9d8e0a89 100644 --- a/lib/utils/parser.rb +++ b/lib/utils/parser.rb @@ -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")