Class: PluginManagerCliInstall

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

Overview

—————————————————————————————–#

inspec plugin install

—————————————————————————————–#

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



682
683
684
685
686
687
688
689
690
691
692
693
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 682

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



502
503
504
505
506
507
508
509
510
511
512
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 502

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



396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 396

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



533
534
535
536
537
538
539
540
541
542
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 533

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



564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 564

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



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 444

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



427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 427

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



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 468

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



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 411

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



484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 484

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



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 514

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



636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 636

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



544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 544

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



614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 614

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



594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 594

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



580
581
582
583
584
585
586
587
588
589
590
591
592
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 580

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



655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 655

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