From 7273a7380f3ca8d7167d08624e55a0115a44cc27 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Mon, 17 Jun 2019 18:59:42 -0700 Subject: [PATCH] Fixed file resource raising UndefinedMethod on source_path This is a first pass at fixing the failure found by @scottvidmar where file resource was raising undefined_method on nil. The problem was that the initialize method for file was not being called at all because Resource#initialize was returning early without reporting anything. This fix causes a failure in test/functional/inspec_exec_test.rb where it is testing a similar scenario but for some reason the unsupported resources get reported. We need to figure that part out, but in the meantime this will at least report an error at the root cause rather than down the road. Fixes #4208 Signed-off-by: Ryan Davis --- lib/inspec/plugin/v1/plugin_types/resource.rb | 10 +++++++++- test/functional/inspec_exec_test.rb | 7 +++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/inspec/plugin/v1/plugin_types/resource.rb b/lib/inspec/plugin/v1/plugin_types/resource.rb index 7d1e68141..e23655070 100644 --- a/lib/inspec/plugin/v1/plugin_types/resource.rb +++ b/lib/inspec/plugin/v1/plugin_types/resource.rb @@ -87,7 +87,15 @@ module Inspec @__backend_runner__ = backend @__resource_name__ = name - check_supports unless @supports.nil? # this has side effects + # check resource supports + supported = @supports ? check_supports : true # check_supports has side effects! + test_backend = defined?(Train::Transports::Mock::Connection) && backend.backend.class == Train::Transports::Mock::Connection + # raise unless we are supported or in test + unless supported || test_backend + msg = "Unsupported resource/backend combination: %s / %s. Exiting." % + [name, backend.platform.name] + raise ArgumentError, msg + end # call the resource initializer begin diff --git a/test/functional/inspec_exec_test.rb b/test/functional/inspec_exec_test.rb index 1629677a1..958068cbd 100644 --- a/test/functional/inspec_exec_test.rb +++ b/test/functional/inspec_exec_test.rb @@ -297,10 +297,9 @@ Test Summary: 0 successful, 0 failures, 0 skipped let(:out) { inspec("exec " + File.join(profile_path, "aws-profile")) } it "exits with an error" do skip if ENV["NO_AWS"] - - stdout.must_include "Resource `aws_iam_users` is not supported on platform" - stdout.must_include "Resource `aws_iam_access_keys` is not supported on platform" - stdout.must_include "Resource `aws_s3_bucket` is not supported on platform" + stdout.must_include "Unsupported resource/backend combination: aws_iam_users" + stdout.must_include "Unsupported resource/backend combination: aws_iam_access_keys" + stdout.must_include "Unsupported resource/backend combination: aws_s3_bucket" stdout.must_include "3 failures" assert_exit_code 100, out