Class: PluginManagerCliInstall

Inherits:
Minitest::Test
  • Object
show all
Extended by:
CorePluginFunctionalHelper
Includes:
CorePluginFunctionalHelper, PluginManagerHelpers
Defined in:
lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb

Constant Summary

Constants included from CorePluginFunctionalHelper

CorePluginFunctionalHelper::TRAIN_CONNECTION

Instance Method Summary collapse

Methods included from CorePluginFunctionalHelper

__find_plugin_path_from_caller, __make_empty_plugin_file_data_structure, __make_plugin_file_data_structure_with_path, run_inspec_process, run_inspec_process_with_this_plugin

Methods included from PluginManagerHelpers

#clear_empty_config_dir, #copy_in_core_config_dir, #copy_in_project_config_dir, #parse_plugin_list_lines, #teardown

Instance Method Details

#test_error_install_with_debug_enabledObject



356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 356

def test_error_install_with_debug_enabled
  skip "this test requires bundler to pass" unless defined? ::Bundler

  install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture -v 0.1.1 --log-level debug")
  skip_windows!

  assert_includes install_result.stdout, "DEBUG"

  assert_includes install_result.stderr, "can't activate rake"

  assert_exit_code 1, install_result
end

#test_fail_install_from_nonexistant_gemfileObject



176
177
178
179
180
181
182
183
184
185
186
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 176

def test_fail_install_from_nonexistant_gemfile
  bad_path = File.join(project_fixtures_path, "none", "such", "inspec-test-fixture-nonesuch-0.3.0.gem")
  install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")

  skip_windows!
  assert_match(/No such plugin gem file .+ - installation failed./, install_result.stdout)

  assert_empty install_result.stderr

  assert_exit_code 1, install_result
end

#test_fail_install_from_nonexistant_pathObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 70

def test_fail_install_from_nonexistant_path
  bad_path = File.join(project_fixtures_path, "none", "such", "inspec-test-fixture-nonesuch.rb")
  install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
  skip_windows!

  error_message = install_result.stdout
  assert_includes error_message, "No such source code path"
  assert_includes error_message, "inspec-test-fixture-nonesuch.rb"
  assert_includes error_message, "installation failed"

  assert_empty install_result.stderr

  assert_exit_code 1, install_result
end

#test_fail_install_from_nonexistant_remote_rubygemObject



207
208
209
210
211
212
213
214
215
216
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 207

def test_fail_install_from_nonexistant_remote_rubygem
  install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture-nonesuch")

  skip_windows!
  assert_match(/No such plugin gem .+ could be found on rubygems.org - installation failed./, install_result.stdout)

  assert_empty install_result.stderr

  assert_exit_code 1, install_result
end

#test_fail_install_from_nonexistant_rubygem_versionObject



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 238

def test_fail_install_from_nonexistant_rubygem_version
  install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture -v 99.99.99")

  fail_message = install_result.stdout.split("\n").grep(/failed/).last
  skip_windows!
  refute_nil fail_message, "Should find a failure message at the end"
  assert_includes fail_message, "inspec-test-fixture"
  assert_includes fail_message, "99.99.99"
  assert_includes fail_message, "no such version"
  assert_includes fail_message, "on rubygems.org"

  assert_empty install_result.stderr

  assert_exit_code 1, install_result
end

#test_fail_install_from_path_when_it_is_already_installedObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 118

def test_fail_install_from_path_when_it_is_already_installed
  plugin_path = File.join(core_fixture_plugins_path, "inspec-test-fixture", "lib", "inspec-test-fixture.rb")
  pre_block = Proc.new do |plugin_data, _tmp_dir|
    plugin_data["plugins"] << {
      "name" => "inspec-test-fixture",
      "installation_type" => "path",
      "installation_path" => plugin_path,
    }
  end

  install_result = run_inspec_process_with_this_plugin("plugin install #{plugin_path}", pre_run: pre_block)
  skip_windows!

  error_message = install_result.stdout
  assert_includes error_message, "Plugin already installed"
  assert_includes error_message, "inspec-test-fixture"
  assert_includes error_message, "Use 'inspec plugin list' to see previously installed plugin"
  assert_includes error_message, "installation failed"

  assert_empty install_result.stderr

  assert_exit_code 2, install_result
end

#test_fail_install_from_path_when_it_is_not_a_pluginObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 101

def test_fail_install_from_path_when_it_is_not_a_plugin
  bad_path = File.join(project_fixtures_path, "plugins", "inspec-egg-white-omelette", "lib", "inspec-egg-white-omelette.rb")
  install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
  skip_windows!

  error_message = install_result.stdout
  assert_includes error_message, "Does not appear to be a plugin"
  assert_includes error_message, "inspec-egg-white-omelette"
  assert_includes error_message, "After probe-loading the supposed plugin, it did not register"
  assert_includes error_message, "Ensure something inherits from 'Inspec.plugin(2)'"
  assert_includes error_message, "installation failed"

  assert_empty install_result.stderr

  assert_exit_code 1, install_result
end

#test_fail_install_from_path_when_the_dir_structure_is_wrongObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 142

def test_fail_install_from_path_when_the_dir_structure_is_wrong
  bad_path = File.join(project_fixtures_path, "plugins", "inspec-wrong-structure")
  install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
  skip_windows!

  error_message = install_result.stdout
  assert_includes error_message, "Unrecognizable plugin structure"
  assert_includes error_message, "inspec-wrong-structure"
  assert_includes error_message, " When installing from a path, please provide the path of the entry point file"
  assert_includes error_message, "installation failed"

  assert_empty install_result.stderr

  assert_exit_code 1, install_result
end

#test_fail_install_from_path_with_wrong_nameObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 85

def test_fail_install_from_path_with_wrong_name
  bad_path = File.join(project_fixtures_path, "plugins", "wrong-name", "lib", "wrong-name.rb")
  install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
  skip_windows!

  error_message = install_result.stdout
  assert_includes error_message, "Invalid plugin name"
  assert_includes error_message, "wrong-name"
  assert_includes error_message, "All inspec plugins must begin with either 'inspec-' or 'train-'"
  assert_includes error_message, "installation failed"

  assert_empty install_result.stderr

  assert_exit_code 1, install_result
end

#test_install_from_gemfileObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 158

def test_install_from_gemfile
  fixture_gemfile_path = File.join(core_fixture_plugins_path, "inspec-test-fixture", "pkg", "inspec-test-fixture-0.1.0.gem")
  install_result = run_inspec_process_with_this_plugin("plugin install #{fixture_gemfile_path}", post_run: list_after_run)
  skip_windows!

  success_message = install_result.stdout.split("\n").grep(/installed/).last
  refute_nil success_message, "Should find a success message at the end"
  assert_includes success_message, "installed from local .gem file"

  itf_plugin = install_result.payload.list_result.detect { |p| p[:name] == "inspec-test-fixture" }
  refute_nil itf_plugin, "plugin name should now appear in the output of inspec list"
  assert_equal "gem (user)", itf_plugin[:type]
  assert_equal "0.1.0", itf_plugin[:version]

  assert_empty install_result.stderr
  assert_exit_code 0, install_result
end

#test_install_from_rubygems_latestObject



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 188

def test_install_from_rubygems_latest
  install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture", post_run: list_after_run)
  skip_windows!

  success_message = install_result.stdout.split("\n").grep(/installed/).last
  refute_nil success_message, "Should find a success message at the end"
  assert_includes success_message, "inspec-test-fixture"
  assert_includes success_message, "0.2.0"
  assert_includes success_message, "installed from rubygems.org"

  itf_plugin = install_result.payload.list_result.detect { |p| p[:name] == "inspec-test-fixture" }
  refute_nil itf_plugin, "plugin name should now appear in the output of inspec list"
  assert_equal "gem (user)", itf_plugin[:type]
  assert_equal "0.2.0", itf_plugin[:version]

  assert_empty install_result.stderr
  assert_exit_code 0, install_result
end

#test_install_from_rubygems_latest_with_train_pluginObject



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 310

def test_install_from_rubygems_latest_with_train_plugin
  install_result = run_inspec_process_with_this_plugin("plugin install train-test-fixture", post_run: list_after_run)
  skip_windows!

  success_message = install_result.stdout.split("\n").grep(/installed/).last
  refute_nil success_message, "Should find a success message at the end"
  assert_includes success_message, "train-test-fixture"
  assert_includes success_message, "0.1.0"
  assert_includes success_message, "installed from rubygems.org"

  ttf_plugin = install_result.payload.list_result.detect { |p| p[:name] == "train-test-fixture" }
  refute_nil ttf_plugin, "plugin name should now appear in the output of inspec list"
  assert_equal "gem (user)", ttf_plugin[:type]
  assert_equal "0.1.0", ttf_plugin[:version]

  assert_empty install_result.stderr
  assert_exit_code 0, install_result
end

#test_install_from_rubygems_with_pinned_versionObject



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 218

def test_install_from_rubygems_with_pinned_version
  install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture -v 0.1.0", post_run: list_after_run)

  success_message = install_result.stdout.split("\n").grep(/installed/).last
  skip_windows!
  refute_nil success_message, "Should find a success message at the end"
  assert_includes success_message, "inspec-test-fixture"
  assert_includes success_message, "0.1.0"
  assert_includes success_message, "installed from rubygems.org"

  itf_plugin = install_result.payload.list_result.detect { |p| p[:name] == "inspec-test-fixture" }
  refute_nil itf_plugin, "plugin name should now appear in the output of inspec list"
  assert_equal "gem (user)", itf_plugin[:type]
  assert_equal "0.1.0", itf_plugin[:version]

  assert_empty install_result.stderr

  assert_exit_code 0, install_result
end

#test_refuse_install_when_already_installed_can_updateObject



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 288

def test_refuse_install_when_already_installed_can_update
  pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
    plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
    copy_in_core_config_dir("test-fixture-1-float", tmp_dir)
  end

  install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture", pre_run: pre_block)

  refusal_message = install_result.stdout.split("\n").grep(/refusing/).last
  skip_windows!
  refute_nil refusal_message, "Should find a failure message at the end"
  assert_includes refusal_message, "inspec-test-fixture"
  assert_includes refusal_message, "0.1.0"
  assert_includes refusal_message, "0.2.0"
  assert_includes refusal_message, "Update required"
  assert_includes refusal_message, "inspec plugin update"

  assert_empty install_result.stderr

  assert_exit_code 2, install_result
end

#test_refuse_install_when_already_installed_same_versionObject



268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 268

def test_refuse_install_when_already_installed_same_version
  pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
    plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
    copy_in_core_config_dir("test-fixture-2-float", tmp_dir)
  end

  install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture", pre_run: pre_block)

  refusal_message = install_result.stdout.split("\n").grep(/refusing/).last
  skip_windows!
  refute_nil refusal_message, "Should find a failure message at the end"
  assert_includes refusal_message, "inspec-test-fixture"
  assert_includes refusal_message, "0.2.0"
  assert_includes refusal_message, "Plugin already installed at latest version"

  assert_empty install_result.stderr

  assert_exit_code 2, install_result
end

#test_refuse_install_when_missing_prefixObject



254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 254

def test_refuse_install_when_missing_prefix
  install_result = run_inspec_process_with_this_plugin("plugin install test-fixture")

  fail_message = install_result.stdout.split("\n").grep(/failed/).last
  skip_windows!
  refute_nil fail_message, "Should find a failure message at the end"
  assert_includes fail_message, "test-fixture"
  assert_includes fail_message, "All inspec plugins must begin with either 'inspec-' or 'train-'"

  assert_empty install_result.stderr

  assert_exit_code 1, install_result
end

#test_refuse_install_when_plugin_on_exclusion_listObject



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb', line 329

def test_refuse_install_when_plugin_on_exclusion_list
  # Here, 'inspec-core', 'inspec-multi-server', and 'train-tax-collector'
  # are the names of real rubygems.  They are not InSpec/Train plugins, though,
  # and installing them would be a jam-up.
  # This is configured in 'etc/plugin-filter.json'.
  %w{
    inspec-core
    inspec-multi-server
    train-tax-calculator
  }.each do |plugin_name|
    install_result = run_inspec_process_with_this_plugin("plugin install #{plugin_name}")
    refusal_message = install_result.stdout
    refute_nil refusal_message, "Should find a failure message at the end"
    skip_windows!
    assert_includes refusal_message, plugin_name
    assert_includes refusal_message, "Plugin on Exclusion List"
    assert_includes refusal_message, "refusing to install"
    assert_includes refusal_message, "Rationale:"
    assert_includes refusal_message, "etc/plugin_filters.json"
    assert_includes refusal_message, "github.com/inspec/inspec/issues/new"

    assert_empty install_result.stderr

    assert_exit_code 2, install_result
  end
end