mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
CFINSPEC-533: Fix undefined method 'summary' for Gem::SourceFetchProblem (NoMethodError) when airgapped (#6337) (#6434)
* This fixes the undefined method 'summary' for #<Gem::SourceFetchProblem:0x000000000139dc70> (NoMethodError) while invoking any inspec command if the custom plugin is installed and if inspec commands are run in an air gap environment. This fix removes an earlier call for getting gem specification from rubygems.org which is the cause for above error and replaces it with fetching the summary from a locally saved gemspec file. This will work in both airgap and non-airgap environments. * Adds test for reading description from local gemspec file. Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
This commit is contained in:
parent
81845cec30
commit
35f8c4829f
4 changed files with 17 additions and 9 deletions
|
@ -290,7 +290,12 @@ module Inspec::Plugin::V2
|
|||
when :user_gem
|
||||
status.entry_point = status.name.to_s
|
||||
status.version = plugin_entry[:version]
|
||||
status.description = fetch_plugin_specs(status.name.to_s)&.summary
|
||||
# Fetch the summary of the gem from local gemspec file instead of remote call using Gem::SpecFetcher.fetcher.
|
||||
unless plugin_entry[:version].nil? # safe check very rare case.
|
||||
version_string = plugin_entry[:version].gsub(/[=,~,>,<]/, "").strip
|
||||
plugin_name_with_version = "#{status.name}-#{version_string}"
|
||||
status.description = fetch_gemspec(File.join(plugin_gem_path, "gems", plugin_name_with_version, "/", status.name.to_s + ".gemspec"))&.summary
|
||||
end
|
||||
when :path
|
||||
status.entry_point = plugin_entry[:installation_path]
|
||||
end
|
||||
|
@ -299,12 +304,6 @@ module Inspec::Plugin::V2
|
|||
end
|
||||
end
|
||||
|
||||
def fetch_plugin_specs(plugin_name)
|
||||
fetcher = Gem::SpecFetcher.fetcher
|
||||
plugin_dependency = Gem::Dependency.new(plugin_name)
|
||||
fetcher.spec_for_dependency(plugin_dependency).flatten.first
|
||||
end
|
||||
|
||||
def fixup_train_plugin_status(status)
|
||||
status.api_generation = :'train-1'
|
||||
if status.installation_type == :user_gem
|
||||
|
|
|
@ -5,7 +5,6 @@ class TestInspecPlugin < ArtifactTest
|
|||
# This one is custom because it emits a special warning to stderr
|
||||
inspec_command = "plugin list"
|
||||
stdout, stderr, status = run_cmd "inspec #{inspec_command} #{TEST_CLI_OPTS}"
|
||||
|
||||
assert_empty stderr.sub(/#< CLIXML\n/, "").sub(/The table size exceeds the currently set width\.Defaulting to vertical orientation\.\n/, "")
|
||||
assert stdout
|
||||
assert status
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"plugins": [
|
||||
{
|
||||
"name": "train-test-fixture",
|
||||
"version": "0.1.0"
|
||||
"version": ">= 0.1.0"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -333,4 +333,14 @@ class PluginLoaderTests < Minitest::Test
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_read_conf_file_into_registry
|
||||
ENV["INSPEC_CONFIG_DIR"] = File.join(@config_dir_path, "train-test-fixture")
|
||||
loader = Inspec::Plugin::V2::Loader.new(omit_bundles: true)
|
||||
registry = loader.send(:read_conf_file_into_registry)
|
||||
assert_includes registry, { :name => :"train-test-fixture", :version => ">= 0.1.0" }
|
||||
reg = Inspec::Plugin::V2::Registry.instance
|
||||
status = reg[registry.first[:name]]
|
||||
assert_equal("Test train plugin. Not intended for use as an example.", status.description, "Reads the description of the plugin from local gemspec file.")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue