diff --git a/lib/inspec/plugin/v2/loader.rb b/lib/inspec/plugin/v2/loader.rb index e28ab685e..b328cefa0 100644 --- a/lib/inspec/plugin/v2/loader.rb +++ b/lib/inspec/plugin/v2/loader.rb @@ -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 diff --git a/test/artifact/inspec_plugin_test.rb b/test/artifact/inspec_plugin_test.rb index 2189bf423..ce56edc6b 100644 --- a/test/artifact/inspec_plugin_test.rb +++ b/test/artifact/inspec_plugin_test.rb @@ -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 diff --git a/test/fixtures/config_dirs/train-test-fixture/plugins.json b/test/fixtures/config_dirs/train-test-fixture/plugins.json index fe139bfd8..6bb3630a0 100644 --- a/test/fixtures/config_dirs/train-test-fixture/plugins.json +++ b/test/fixtures/config_dirs/train-test-fixture/plugins.json @@ -3,7 +3,7 @@ "plugins": [ { "name": "train-test-fixture", - "version": "0.1.0" + "version": ">= 0.1.0" } ] } \ No newline at end of file diff --git a/test/unit/plugin/v2/loader_test.rb b/test/unit/plugin/v2/loader_test.rb index d5fc6be17..05a469e0a 100644 --- a/test/unit/plugin/v2/loader_test.rb +++ b/test/unit/plugin/v2/loader_test.rb @@ -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