inspec 4.3.2 → 4.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +36 -38
- data/README.md +37 -21
- data/etc/deprecations.json +10 -0
- data/etc/plugin_filters.json +8 -0
- data/inspec.gemspec +38 -39
- data/lib/bundles/inspec-compliance/api.rb +1 -1
- data/lib/bundles/inspec-compliance/configuration.rb +1 -1
- data/lib/bundles/inspec-compliance/http.rb +1 -1
- data/lib/bundles/inspec-compliance/support.rb +1 -1
- data/lib/bundles/inspec-compliance/target.rb +1 -1
- data/lib/bundles/inspec-supermarket.rb +3 -7
- data/lib/bundles/inspec-supermarket/api.rb +10 -13
- data/lib/bundles/inspec-supermarket/cli.rb +12 -15
- data/lib/bundles/inspec-supermarket/target.rb +7 -11
- data/lib/fetchers/git.rb +14 -15
- data/lib/fetchers/local.rb +6 -10
- data/lib/fetchers/mock.rb +3 -5
- data/lib/fetchers/url.rb +42 -44
- data/lib/inspec.rb +23 -24
- data/lib/inspec/archive/tar.rb +2 -6
- data/lib/inspec/archive/zip.rb +3 -7
- data/lib/inspec/backend.rb +8 -9
- data/lib/inspec/base_cli.rb +64 -65
- data/lib/inspec/cached_fetcher.rb +2 -3
- data/lib/inspec/cli.rb +136 -97
- data/lib/inspec/config.rb +71 -61
- data/lib/inspec/control_eval_context.rb +22 -18
- data/lib/inspec/dependencies/cache.rb +2 -3
- data/lib/inspec/dependencies/dependency_set.rb +2 -3
- data/lib/inspec/dependencies/lockfile.rb +8 -9
- data/lib/inspec/dependencies/requirement.rb +7 -8
- data/lib/inspec/dependencies/resolver.rb +5 -7
- data/lib/inspec/describe.rb +2 -6
- data/lib/inspec/dist.rb +20 -0
- data/lib/inspec/dsl.rb +4 -7
- data/lib/inspec/dsl_shared.rb +1 -2
- data/lib/inspec/env_printer.rb +11 -12
- data/lib/inspec/errors.rb +0 -4
- data/lib/inspec/exceptions.rb +0 -1
- data/lib/inspec/expect.rb +5 -8
- data/lib/inspec/fetcher.rb +7 -10
- data/lib/inspec/file_provider.rb +24 -24
- data/lib/inspec/formatters.rb +3 -3
- data/lib/inspec/formatters/base.rb +8 -8
- data/lib/inspec/globals.rb +2 -2
- data/lib/inspec/impact.rb +5 -7
- data/lib/inspec/input_registry.rb +84 -33
- data/lib/inspec/library_eval_context.rb +3 -6
- data/lib/inspec/log.rb +1 -5
- data/lib/inspec/metadata.rb +17 -16
- data/lib/inspec/method_source.rb +5 -9
- data/lib/inspec/objects.rb +10 -12
- data/lib/inspec/objects/control.rb +7 -9
- data/lib/inspec/objects/describe.rb +9 -11
- data/lib/inspec/objects/each_loop.rb +1 -3
- data/lib/inspec/objects/input.rb +24 -26
- data/lib/inspec/objects/list.rb +4 -6
- data/lib/inspec/objects/or_test.rb +2 -4
- data/lib/inspec/objects/ruby_helper.rb +3 -5
- data/lib/inspec/objects/tag.rb +0 -2
- data/lib/inspec/objects/test.rb +9 -11
- data/lib/inspec/objects/value.rb +3 -5
- data/lib/inspec/plugin/v1.rb +2 -2
- data/lib/inspec/plugin/v1/plugin_types/cli.rb +1 -5
- data/lib/inspec/plugin/v1/plugin_types/fetcher.rb +2 -5
- data/lib/inspec/plugin/v1/plugin_types/resource.rb +4 -6
- data/lib/inspec/plugin/v1/plugin_types/secret.rb +1 -5
- data/lib/inspec/plugin/v1/plugin_types/source_reader.rb +1 -5
- data/lib/inspec/plugin/v1/plugins.rb +15 -19
- data/lib/inspec/plugin/v1/registry.rb +0 -4
- data/lib/inspec/plugin/v2.rb +8 -8
- data/lib/inspec/plugin/v2/activator.rb +1 -1
- data/lib/inspec/plugin/v2/config_file.rb +6 -6
- data/lib/inspec/plugin/v2/filter.rb +13 -13
- data/lib/inspec/plugin/v2/installer.rb +36 -24
- data/lib/inspec/plugin/v2/loader.rb +28 -28
- data/lib/inspec/plugin/v2/plugin_base.rb +15 -2
- data/lib/inspec/plugin/v2/plugin_types/cli.rb +5 -5
- data/lib/inspec/plugin/v2/plugin_types/input.rb +34 -0
- data/lib/inspec/plugin/v2/plugin_types/mock.rb +1 -1
- data/lib/inspec/plugin/v2/registry.rb +7 -7
- data/lib/inspec/polyfill.rb +0 -3
- data/lib/inspec/profile.rb +55 -63
- data/lib/inspec/profile_context.rb +27 -30
- data/lib/inspec/profile_vendor.rb +6 -9
- data/lib/inspec/reporters.rb +24 -24
- data/lib/inspec/reporters/automate.rb +17 -19
- data/lib/inspec/reporters/base.rb +1 -1
- data/lib/inspec/reporters/cli.rb +88 -91
- data/lib/inspec/reporters/json.rb +2 -4
- data/lib/inspec/reporters/json_automate.rb +1 -3
- data/lib/inspec/reporters/json_min.rb +1 -3
- data/lib/inspec/reporters/junit.rb +26 -28
- data/lib/inspec/reporters/yaml.rb +1 -3
- data/lib/inspec/require_loader.rb +0 -4
- data/lib/inspec/resource.rb +4 -125
- data/lib/inspec/resources.rb +121 -0
- data/lib/{resources → inspec/resources}/aide_conf.rb +24 -25
- data/lib/{resources → inspec/resources}/apache.rb +13 -14
- data/lib/{resources → inspec/resources}/apache_conf.rb +16 -17
- data/lib/{resources → inspec/resources}/apt.rb +17 -17
- data/lib/{resources → inspec/resources}/audit_policy.rb +7 -6
- data/lib/{resources → inspec/resources}/auditd.rb +62 -64
- data/lib/{resources → inspec/resources}/auditd_conf.rb +7 -8
- data/lib/{resources → inspec/resources}/bash.rb +6 -8
- data/lib/{resources → inspec/resources}/bond.rb +15 -14
- data/lib/{resources → inspec/resources}/bridge.rb +8 -8
- data/lib/{resources → inspec/resources}/chocolatey_package.rb +10 -8
- data/lib/{resources → inspec/resources}/command.rb +11 -10
- data/lib/{resources → inspec/resources}/cpan.rb +12 -12
- data/lib/{resources → inspec/resources}/cran.rb +9 -9
- data/lib/{resources → inspec/resources}/crontab.rb +47 -48
- data/lib/{resources → inspec/resources}/csv.rb +5 -5
- data/lib/{resources → inspec/resources}/dh_params.rb +5 -7
- data/lib/{resources → inspec/resources}/directory.rb +5 -7
- data/lib/{resources → inspec/resources}/docker.rb +63 -63
- data/lib/{resources → inspec/resources}/docker_container.rb +6 -6
- data/lib/{resources → inspec/resources}/docker_image.rb +9 -9
- data/lib/{resources → inspec/resources}/docker_object.rb +8 -13
- data/lib/{resources → inspec/resources}/docker_plugin.rb +6 -6
- data/lib/{resources → inspec/resources}/docker_service.rb +7 -7
- data/lib/{resources → inspec/resources}/elasticsearch.rb +40 -42
- data/lib/{resources → inspec/resources}/etc_fstab.rb +23 -24
- data/lib/{resources → inspec/resources}/etc_group.rb +26 -27
- data/lib/{resources → inspec/resources}/etc_hosts.rb +11 -13
- data/lib/{resources → inspec/resources}/etc_hosts_allow_deny.rb +25 -27
- data/lib/{resources → inspec/resources}/file.rb +80 -79
- data/lib/{resources → inspec/resources}/filesystem.rb +20 -15
- data/lib/{resources → inspec/resources}/firewalld.rb +26 -26
- data/lib/{resources → inspec/resources}/gem.rb +12 -12
- data/lib/{resources → inspec/resources}/groups.rb +28 -27
- data/lib/{resources → inspec/resources}/grub_conf.rb +46 -48
- data/lib/{resources → inspec/resources}/host.rb +31 -29
- data/lib/{resources → inspec/resources}/http.rb +24 -24
- data/lib/{resources → inspec/resources}/iis_app.rb +6 -7
- data/lib/{resources → inspec/resources}/iis_app_pool.rb +21 -19
- data/lib/{resources → inspec/resources}/iis_site.rb +17 -15
- data/lib/{resources → inspec/resources}/inetd_conf.rb +9 -10
- data/lib/{resources → inspec/resources}/ini.rb +7 -8
- data/lib/{resources → inspec/resources}/interface.rb +30 -30
- data/lib/{resources → inspec/resources}/iptables.rb +8 -8
- data/lib/{resources → inspec/resources}/json.rb +8 -10
- data/lib/{resources → inspec/resources}/kernel_module.rb +15 -15
- data/lib/{resources → inspec/resources}/kernel_parameter.rb +8 -8
- data/lib/{resources → inspec/resources}/key_rsa.rb +8 -10
- data/lib/{resources → inspec/resources}/ksh.rb +6 -8
- data/lib/{resources → inspec/resources}/limits_conf.rb +8 -9
- data/lib/{resources/login_def.rb → inspec/resources/login_defs.rb} +9 -10
- data/lib/{resources → inspec/resources}/mount.rb +6 -8
- data/lib/{resources → inspec/resources}/mssql_session.rb +16 -18
- data/lib/inspec/resources/mysql.rb +81 -0
- data/lib/{resources → inspec/resources}/mysql_conf.rb +13 -14
- data/lib/{resources → inspec/resources}/mysql_session.rb +16 -16
- data/lib/{resources → inspec/resources}/nginx.rb +16 -17
- data/lib/{resources → inspec/resources}/nginx_conf.rb +26 -27
- data/lib/{resources → inspec/resources}/npm.rb +9 -10
- data/lib/{resources → inspec/resources}/ntp_conf.rb +9 -10
- data/lib/{resources → inspec/resources}/oneget.rb +8 -8
- data/lib/{resources → inspec/resources}/oracledb_session.rb +33 -34
- data/lib/{resources → inspec/resources}/os.rb +6 -8
- data/lib/{resources → inspec/resources}/os_env.rb +11 -12
- data/lib/{resources → inspec/resources}/package.rb +66 -65
- data/lib/{resources → inspec/resources}/packages.rb +13 -13
- data/lib/{resources → inspec/resources}/parse_config.rb +8 -8
- data/lib/{resources → inspec/resources}/passwd.rb +18 -19
- data/lib/{resources → inspec/resources}/pip.rb +19 -19
- data/lib/{resources → inspec/resources}/platform.rb +9 -11
- data/lib/{resources → inspec/resources}/port.rb +134 -136
- data/lib/{resources → inspec/resources}/postgres.rb +40 -32
- data/lib/{resources → inspec/resources}/postgres_conf.rb +17 -17
- data/lib/{resources → inspec/resources}/postgres_hba_conf.rb +21 -23
- data/lib/{resources → inspec/resources}/postgres_ident_conf.rb +12 -14
- data/lib/{resources → inspec/resources}/postgres_session.rb +8 -9
- data/lib/{resources → inspec/resources}/powershell.rb +17 -13
- data/lib/{resources → inspec/resources}/processes.rb +29 -29
- data/lib/{resources/rabbitmq_conf.rb → inspec/resources/rabbitmq_config.rb} +10 -11
- data/lib/{resources → inspec/resources}/registry_key.rb +14 -14
- data/lib/inspec/resources/script.rb +1 -0
- data/lib/{resources → inspec/resources}/security_identifier.rb +11 -10
- data/lib/{resources → inspec/resources}/security_policy.rb +59 -58
- data/lib/{resources → inspec/resources}/service.rb +74 -75
- data/lib/{resources → inspec/resources}/shadow.rb +44 -45
- data/lib/{resources/ssh_conf.rb → inspec/resources/ssh_config.rb} +16 -17
- data/lib/{resources → inspec/resources}/ssl.rb +28 -29
- data/lib/inspec/resources/sys_info.rb +30 -0
- data/lib/{resources → inspec/resources}/toml.rb +5 -7
- data/lib/{resources → inspec/resources}/users.rb +65 -65
- data/lib/{resources → inspec/resources}/vbscript.rb +8 -9
- data/lib/{resources → inspec/resources}/virtualization.rb +60 -62
- data/lib/{resources → inspec/resources}/windows_feature.rb +9 -9
- data/lib/{resources → inspec/resources}/windows_hotfix.rb +5 -5
- data/lib/{resources → inspec/resources}/windows_task.rb +16 -15
- data/lib/{resources → inspec/resources}/wmi.rb +7 -8
- data/lib/{resources → inspec/resources}/x509_certificate.rb +9 -11
- data/lib/{resources/xinetd.rb → inspec/resources/xinetd_conf.rb} +27 -29
- data/lib/{resources → inspec/resources}/xml.rb +7 -7
- data/lib/{resources → inspec/resources}/yaml.rb +5 -6
- data/lib/{resources → inspec/resources}/yum.rb +10 -10
- data/lib/{resources → inspec/resources}/zfs_dataset.rb +6 -6
- data/lib/{resources → inspec/resources}/zfs_pool.rb +4 -4
- data/lib/inspec/rspec_extensions.rb +24 -8
- data/lib/inspec/rule.rb +14 -15
- data/lib/inspec/runner.rb +28 -28
- data/lib/inspec/runner_mock.rb +1 -5
- data/lib/inspec/runner_rspec.rb +18 -20
- data/lib/inspec/runtime_profile.rb +2 -5
- data/lib/inspec/schema.rb +142 -143
- data/lib/inspec/secrets.rb +3 -7
- data/lib/inspec/secrets/yaml.rb +3 -5
- data/lib/inspec/shell.rb +11 -15
- data/lib/inspec/shell_detector.rb +6 -7
- data/lib/inspec/source_reader.rb +4 -8
- data/lib/inspec/ui.rb +33 -39
- data/lib/inspec/ui_table_helper.rb +12 -0
- data/lib/{utils → inspec/utils}/command_wrapper.rb +4 -8
- data/lib/{utils → inspec/utils}/convert.rb +0 -4
- data/lib/{utils → inspec/utils}/database_helpers.rb +4 -8
- data/lib/inspec/utils/deprecation.rb +6 -0
- data/lib/{utils → inspec/utils}/deprecation/config_file.rb +19 -19
- data/lib/{utils → inspec/utils}/deprecation/deprecator.rb +12 -12
- data/lib/{utils → inspec/utils}/deprecation/errors.rb +1 -1
- data/lib/{utils → inspec/utils}/deprecation/global_method.rb +2 -2
- data/lib/{utils → inspec/utils}/enumerable_delegation.rb +0 -2
- data/lib/{utils → inspec/utils}/erlang_parser.rb +61 -65
- data/lib/{utils → inspec/utils}/file_reader.rb +1 -2
- data/lib/{utils → inspec/utils}/filter.rb +30 -33
- data/lib/{utils → inspec/utils}/filter_array.rb +0 -2
- data/lib/{utils → inspec/utils}/find_files.rb +9 -12
- data/lib/{utils → inspec/utils}/hash.rb +1 -5
- data/lib/inspec/utils/json_log.rb +15 -0
- data/lib/inspec/utils/latest_version.rb +13 -0
- data/lib/{utils → inspec/utils}/modulator.rb +0 -3
- data/lib/{utils → inspec/utils}/nginx_parser.rb +31 -35
- data/lib/{utils → inspec/utils}/object_traversal.rb +0 -3
- data/lib/{utils → inspec/utils}/parser.rb +45 -45
- data/lib/{utils → inspec/utils}/pkey_reader.rb +4 -2
- data/lib/{utils → inspec/utils}/simpleconfig.rb +8 -10
- data/lib/{utils → inspec/utils}/spdx.rb +1 -4
- data/lib/{utils → inspec/utils}/spdx.txt +0 -0
- data/lib/inspec/utils/telemetry.rb +3 -3
- data/lib/inspec/utils/telemetry/collector.rb +30 -9
- data/lib/inspec/utils/telemetry/data_series.rb +3 -1
- data/lib/inspec/utils/telemetry/global_methods.rb +1 -1
- data/lib/inspec/version.rb +1 -1
- data/lib/matchers/matchers.rb +22 -25
- data/lib/plugins/inspec-artifact/lib/inspec-artifact.rb +1 -1
- data/lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb +52 -45
- data/lib/plugins/inspec-artifact/lib/inspec-artifact/cli.rb +18 -16
- data/lib/plugins/inspec-artifact/test/functional/inspec_artifact_test.rb +12 -11
- data/lib/plugins/inspec-compliance/lib/inspec-compliance.rb +1 -1
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/api.rb +73 -73
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/api/login.rb +66 -62
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/cli.rb +59 -57
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/configuration.rb +11 -11
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/http.rb +20 -22
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/support.rb +2 -4
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/target.rb +30 -27
- data/lib/plugins/inspec-compliance/test/functional/inspec_compliance_test.rb +12 -14
- data/lib/plugins/inspec-compliance/test/integration/default/cli.rb +39 -41
- data/lib/plugins/inspec-compliance/test/unit/api/login_test.rb +64 -64
- data/lib/plugins/inspec-compliance/test/unit/api_test.rb +157 -156
- data/lib/plugins/inspec-compliance/test/unit/target_test.rb +85 -85
- data/lib/plugins/inspec-habitat/Berksfile +2 -2
- data/lib/plugins/inspec-habitat/lib/inspec-habitat.rb +1 -1
- data/lib/plugins/inspec-habitat/lib/inspec-habitat/cli.rb +15 -13
- data/lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb +64 -63
- data/lib/plugins/inspec-habitat/templates/habitat/hooks/run.erb +3 -3
- data/lib/plugins/inspec-habitat/templates/habitat/plan.sh.erb +11 -11
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/Berksfile +1 -1
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/metadata.rb +8 -8
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/recipes/default.rb +17 -17
- data/lib/plugins/inspec-habitat/test/functional/inspec_habitat_test.rb +9 -8
- data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/controls/inspec_habitat.rb +14 -14
- data/lib/plugins/inspec-habitat/test/support/example_profile/controls/example.rb +4 -4
- data/lib/plugins/inspec-habitat/test/unit/profile_test.rb +42 -41
- data/lib/plugins/inspec-init/lib/inspec-init.rb +1 -1
- data/lib/plugins/inspec-init/lib/inspec-init/cli.rb +6 -8
- data/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb +72 -74
- data/lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb +9 -11
- data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +4 -4
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Gemfile +0 -1
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/inspec-plugin-template.gemspec +0 -2
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template.rb +0 -2
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.rb +0 -2
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.rb +0 -2
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.rb +0 -2
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/inspec_plugin_template_test.rb +5 -5
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/helper.rb +1 -3
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/cli_args_test.rb +2 -2
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/plugin_def_test.rb +2 -2
- data/lib/plugins/inspec-init/templates/profiles/aws/controls/example.rb +10 -11
- data/lib/plugins/inspec-init/templates/profiles/azure/controls/example.rb +4 -5
- data/lib/plugins/inspec-init/templates/profiles/gcp/controls/example.rb +10 -11
- data/lib/plugins/inspec-init/templates/profiles/os/controls/example.rb +6 -7
- data/lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb +51 -50
- data/lib/plugins/inspec-init/test/functional/inspec_init_profile_test.rb +35 -33
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli.rb +1 -2
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +72 -70
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/plugin.rb +1 -1
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name.rb +1 -1
- data/lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb +281 -271
- data/lib/plugins/inspec-plugin-manager-cli/test/unit/cli_args_test.rb +41 -41
- data/lib/plugins/inspec-plugin-manager-cli/test/unit/plugin_def_test.rb +25 -6
- data/lib/plugins/shared/core_plugin_test_helper.rb +43 -38
- data/lib/resource_support/aws.rb +67 -67
- data/lib/resource_support/aws/aws_plural_resource_mixin.rb +4 -1
- data/lib/resource_support/aws/aws_resource_mixin.rb +4 -3
- data/lib/resource_support/aws/aws_singular_resource_mixin.rb +4 -1
- data/lib/resources/aws/aws_billing_report.rb +15 -8
- data/lib/resources/aws/aws_billing_reports.rb +10 -7
- data/lib/resources/aws/aws_cloudtrail_trail.rb +9 -5
- data/lib/resources/aws/aws_cloudtrail_trails.rb +9 -5
- data/lib/resources/aws/aws_cloudwatch_alarm.rb +9 -5
- data/lib/resources/aws/aws_cloudwatch_log_metric_filter.rb +12 -8
- data/lib/resources/aws/aws_config_delivery_channel.rb +13 -9
- data/lib/resources/aws/aws_config_recorder.rb +10 -6
- data/lib/resources/aws/aws_ebs_volume.rb +12 -8
- data/lib/resources/aws/aws_ebs_volumes.rb +9 -5
- data/lib/resources/aws/aws_ec2_instance.rb +14 -11
- data/lib/resources/aws/aws_ec2_instances.rb +9 -5
- data/lib/resources/aws/aws_ecs_cluster.rb +11 -7
- data/lib/resources/aws/aws_eks_cluster.rb +13 -9
- data/lib/resources/aws/aws_elb.rb +9 -5
- data/lib/resources/aws/aws_elbs.rb +9 -5
- data/lib/resources/aws/aws_flow_log.rb +17 -13
- data/lib/resources/aws/aws_iam_access_key.rb +15 -11
- data/lib/resources/aws/aws_iam_access_keys.rb +19 -15
- data/lib/resources/aws/aws_iam_group.rb +9 -5
- data/lib/resources/aws/aws_iam_groups.rb +9 -5
- data/lib/resources/aws/aws_iam_password_policy.rb +13 -10
- data/lib/resources/aws/aws_iam_policies.rb +9 -5
- data/lib/resources/aws/aws_iam_policy.rb +16 -12
- data/lib/resources/aws/aws_iam_role.rb +9 -5
- data/lib/resources/aws/aws_iam_root_user.rb +12 -8
- data/lib/resources/aws/aws_iam_user.rb +12 -12
- data/lib/resources/aws/aws_iam_users.rb +10 -10
- data/lib/resources/aws/aws_kms_key.rb +12 -8
- data/lib/resources/aws/aws_kms_keys.rb +9 -5
- data/lib/resources/aws/aws_rds_instance.rb +11 -8
- data/lib/resources/aws/aws_route_table.rb +11 -7
- data/lib/resources/aws/aws_route_tables.rb +10 -6
- data/lib/resources/aws/aws_s3_bucket.rb +14 -11
- data/lib/resources/aws/aws_s3_bucket_object.rb +12 -9
- data/lib/resources/aws/aws_s3_buckets.rb +9 -7
- data/lib/resources/aws/aws_security_group.rb +16 -12
- data/lib/resources/aws/aws_security_groups.rb +12 -8
- data/lib/resources/aws/aws_sns_subscription.rb +15 -11
- data/lib/resources/aws/aws_sns_topic.rb +10 -6
- data/lib/resources/aws/aws_sns_topics.rb +9 -5
- data/lib/resources/aws/aws_sqs_queue.rb +18 -14
- data/lib/resources/aws/aws_subnet.rb +11 -7
- data/lib/resources/aws/aws_subnets.rb +9 -5
- data/lib/resources/aws/aws_vpc.rb +10 -6
- data/lib/resources/aws/aws_vpcs.rb +9 -5
- data/lib/resources/azure/azure_backend.rb +20 -18
- data/lib/resources/azure/azure_generic_resource.rb +13 -15
- data/lib/resources/azure/azure_resource_group.rb +17 -19
- data/lib/resources/azure/azure_virtual_machine.rb +6 -8
- data/lib/resources/azure/azure_virtual_machine_data_disk.rb +6 -8
- data/lib/source_readers/flat.rb +6 -10
- data/lib/source_readers/inspec.rb +8 -12
- metadata +141 -142
- data/lib/resources/mysql.rb +0 -82
- data/lib/resources/sys_info.rb +0 -28
- data/lib/utils/deprecation.rb +0 -6
- data/lib/utils/json_log.rb +0 -18
- data/lib/utils/latest_version.rb +0 -22
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
# Because this is a core plugin, we place the plugin definition here in the entry point.
|
|
3
2
|
# This is needed because under core testing, the entry point may be reloaded multiple times,
|
|
4
3
|
# and we need plugin registration to properly occur each time.
|
|
@@ -10,7 +9,7 @@ module InspecPlugins
|
|
|
10
9
|
plugin_name :'inspec-plugin-manager-cli'
|
|
11
10
|
|
|
12
11
|
cli_command :plugin do
|
|
13
|
-
require_relative
|
|
12
|
+
require_relative "inspec-plugin-manager-cli/cli_command"
|
|
14
13
|
InspecPlugins::PluginManager::CliCommand
|
|
15
14
|
end
|
|
16
15
|
end
|
|
@@ -1,33 +1,35 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
4
|
-
require
|
|
1
|
+
require "term/ansicolor"
|
|
2
|
+
require "pathname"
|
|
3
|
+
require "inspec/plugin/v2"
|
|
4
|
+
require "inspec/plugin/v2/installer"
|
|
5
|
+
require "inspec/dist"
|
|
5
6
|
|
|
6
7
|
module InspecPlugins
|
|
7
8
|
module PluginManager
|
|
8
9
|
class CliCommand < Inspec.plugin(2, :cli_command)
|
|
9
10
|
include Term::ANSIColor
|
|
11
|
+
include Inspec::Dist
|
|
10
12
|
|
|
11
|
-
subcommand_desc
|
|
13
|
+
subcommand_desc "plugin SUBCOMMAND", "Manage #{PRODUCT_NAME} and Train plugins"
|
|
12
14
|
|
|
13
15
|
#==================================================================#
|
|
14
16
|
# inspec plugin list
|
|
15
17
|
#==================================================================#
|
|
16
18
|
|
|
17
|
-
desc
|
|
18
|
-
option :all, desc:
|
|
19
|
+
desc "list [options]", "Lists user-installed #{PRODUCT_NAME} plugins."
|
|
20
|
+
option :all, desc: "Include plugins shipped with #{PRODUCT_NAME} as well.", type: :boolean, aliases: [:a]
|
|
19
21
|
def list
|
|
20
22
|
plugin_statuses = Inspec::Plugin::V2::Registry.instance.plugin_statuses
|
|
21
23
|
plugin_statuses.reject! { |s| [:core, :bundle].include?(s.installation_type) } unless options[:all]
|
|
22
24
|
|
|
23
25
|
# TODO: ui object support
|
|
24
26
|
puts
|
|
25
|
-
puts(bold { format(
|
|
26
|
-
puts
|
|
27
|
+
puts(bold { format(" %-30s%-10s%-8s%-6s", "Plugin Name", "Version", "Via", "ApiVer") })
|
|
28
|
+
puts "-" * 55
|
|
27
29
|
plugin_statuses.sort_by(&:name).each do |status|
|
|
28
|
-
puts(format(
|
|
30
|
+
puts(format(" %-30s%-10s%-8s%-6s", status.name, make_pretty_version(status), status.installation_type, status.api_generation.to_s))
|
|
29
31
|
end
|
|
30
|
-
puts
|
|
32
|
+
puts "-" * 55
|
|
31
33
|
puts(" #{plugin_statuses.count} plugin(s) total")
|
|
32
34
|
puts
|
|
33
35
|
end
|
|
@@ -36,15 +38,15 @@ module InspecPlugins
|
|
|
36
38
|
# inspec plugin search
|
|
37
39
|
#==================================================================#
|
|
38
40
|
|
|
39
|
-
desc
|
|
41
|
+
desc "search [options] PATTERN", "Searches rubygems.org for plugins."
|
|
40
42
|
long_desc <<~EOLD
|
|
41
|
-
Searches rubygems.org for
|
|
43
|
+
Searches rubygems.org for #{PRODUCT_NAME} plugins. Exits 0 on a search hit, 1 on user error,
|
|
42
44
|
2 on a search miss. PATTERN is a simple string; a wildcard will be added as
|
|
43
45
|
a suffix, unless -e is used.
|
|
44
46
|
EOLD
|
|
45
|
-
option :all, desc:
|
|
46
|
-
option :exact, desc:
|
|
47
|
-
option :'include-test-fixture', type: :boolean, desc:
|
|
47
|
+
option :all, desc: "List all available versions, not just the latest one.", type: :boolean, aliases: [:a]
|
|
48
|
+
option :exact, desc: "Assume PATTERN is exact; do not add a wildcard to the end", type: :boolean, aliases: [:e]
|
|
49
|
+
option :'include-test-fixture', type: :boolean, desc: "Internal use", hide: true
|
|
48
50
|
# Justification for disabling ABC: currently at 33.51/33
|
|
49
51
|
def search(search_term) # rubocop: disable Metrics/AbcSize
|
|
50
52
|
search_results = installer.search(search_term, exact: options[:exact])
|
|
@@ -53,20 +55,20 @@ module InspecPlugins
|
|
|
53
55
|
# for testing. We want to hide those from users, so unless we know we're in
|
|
54
56
|
# test mode, remove them.
|
|
55
57
|
unless options[:'include-test-fixture']
|
|
56
|
-
search_results.delete(
|
|
57
|
-
search_results.delete(
|
|
58
|
+
search_results.delete("inspec-test-fixture")
|
|
59
|
+
search_results.delete("train-test-fixture")
|
|
58
60
|
end
|
|
59
61
|
|
|
60
62
|
# TODO: ui object support
|
|
61
63
|
puts
|
|
62
|
-
puts(bold { format(
|
|
63
|
-
puts
|
|
64
|
+
puts(bold { format(" %-30s%-50s", "Plugin Name", "Versions Available") })
|
|
65
|
+
puts "-" * 55
|
|
64
66
|
search_results.keys.sort.each do |plugin_name|
|
|
65
67
|
versions = options[:all] ? search_results[plugin_name] : [search_results[plugin_name].first]
|
|
66
|
-
versions =
|
|
67
|
-
puts(format(
|
|
68
|
+
versions = "(" + versions.join(", ") + ")"
|
|
69
|
+
puts(format(" %-30s%-50s", plugin_name, versions))
|
|
68
70
|
end
|
|
69
|
-
puts
|
|
71
|
+
puts "-" * 55
|
|
70
72
|
puts(" #{search_results.count} plugin(s) found")
|
|
71
73
|
puts
|
|
72
74
|
|
|
@@ -79,7 +81,7 @@ module InspecPlugins
|
|
|
79
81
|
#==================================================================#
|
|
80
82
|
# inspec plugin install
|
|
81
83
|
#==================================================================#
|
|
82
|
-
desc
|
|
84
|
+
desc "install [-v VERSION] PLUGIN", "Installs a plugin from rubygems.org, a gemfile, or a path to local source."
|
|
83
85
|
long_desc <<~EOLD
|
|
84
86
|
PLUGIN may be the name of a gem on rubygems.org that begins with inspec- or train-.
|
|
85
87
|
PLUGIN may also be the path to a local gemfile, which will then be installed like
|
|
@@ -88,7 +90,7 @@ module InspecPlugins
|
|
|
88
90
|
for local plugin development). Exit codes are 0 on success, 2 if the plugin is
|
|
89
91
|
already installed, and 1 if any other error occurs.
|
|
90
92
|
EOLD
|
|
91
|
-
option :version, desc:
|
|
93
|
+
option :version, desc: "When installing from rubygems.org, specifies a specific version to install.", aliases: [:v]
|
|
92
94
|
def install(plugin_id_arg)
|
|
93
95
|
if plugin_id_arg =~ /\.gem$/ # Does it end in .gem?
|
|
94
96
|
install_from_gemfile(plugin_id_arg)
|
|
@@ -102,7 +104,7 @@ module InspecPlugins
|
|
|
102
104
|
#--------------------------
|
|
103
105
|
# update
|
|
104
106
|
#--------------------------
|
|
105
|
-
desc
|
|
107
|
+
desc "update PLUGIN", "Updates a plugin to the latest from from rubygems.org"
|
|
106
108
|
long_desc <<~EOLD
|
|
107
109
|
PLUGIN may be the name of a gem on rubygems.org that begins with inspec- or train-.
|
|
108
110
|
Exit codes are 0 on success, 2 if the plugin is already up to date, and 1 if any
|
|
@@ -110,14 +112,14 @@ module InspecPlugins
|
|
|
110
112
|
EOLD
|
|
111
113
|
def update(plugin_name)
|
|
112
114
|
pre_update_versions = installer.list_installed_plugin_gems.select { |spec| spec.name == plugin_name }.map { |spec| spec.version.to_s }
|
|
113
|
-
old_version = pre_update_versions.join(
|
|
115
|
+
old_version = pre_update_versions.join(", ")
|
|
114
116
|
|
|
115
117
|
update_preflight_check(plugin_name, pre_update_versions)
|
|
116
118
|
|
|
117
119
|
begin
|
|
118
120
|
installer.update(plugin_name)
|
|
119
121
|
rescue Inspec::Plugin::V2::UpdateError => ex
|
|
120
|
-
puts(red {
|
|
122
|
+
puts(red { "Update error: " } + ex.message + " - update failed")
|
|
121
123
|
exit 1
|
|
122
124
|
end
|
|
123
125
|
post_update_versions = installer.list_installed_plugin_gems.select { |spec| spec.name == plugin_name }.map { |spec| spec.version.to_s }
|
|
@@ -129,7 +131,7 @@ module InspecPlugins
|
|
|
129
131
|
#--------------------------
|
|
130
132
|
# uninstall
|
|
131
133
|
#--------------------------
|
|
132
|
-
desc
|
|
134
|
+
desc "uninstall PLUGIN_NAME", "Uninstalls a gem- or path- based plugin"
|
|
133
135
|
long_desc <<~EOLD
|
|
134
136
|
Removes a plugin from the users configuration.
|
|
135
137
|
In the case of a gem plugin (by far the most common), the plugin gem is removed, along
|
|
@@ -142,19 +144,19 @@ module InspecPlugins
|
|
|
142
144
|
def uninstall(plugin_name)
|
|
143
145
|
status = Inspec::Plugin::V2::Registry.instance[plugin_name.to_sym]
|
|
144
146
|
unless status
|
|
145
|
-
puts(red {
|
|
147
|
+
puts(red { "No such plugin installed: " } + "#{plugin_name} is not installed - uninstall failed")
|
|
146
148
|
|
|
147
149
|
exit 1
|
|
148
150
|
end
|
|
149
151
|
installer = Inspec::Plugin::V2::Installer.instance
|
|
150
152
|
|
|
151
153
|
pre_uninstall_versions = installer.list_installed_plugin_gems.select { |spec| spec.name == plugin_name }.map { |spec| spec.version.to_s }
|
|
152
|
-
old_version = pre_uninstall_versions.join(
|
|
154
|
+
old_version = pre_uninstall_versions.join(", ")
|
|
153
155
|
|
|
154
156
|
installer.uninstall(plugin_name)
|
|
155
157
|
|
|
156
158
|
if status.installation_type == :path
|
|
157
|
-
puts(bold { plugin_name } +
|
|
159
|
+
puts(bold { plugin_name } + " path-based plugin install has been uninstalled")
|
|
158
160
|
else
|
|
159
161
|
puts(bold { plugin_name } + " plugin, version #{old_version}, has been uninstalled")
|
|
160
162
|
end
|
|
@@ -170,14 +172,14 @@ module InspecPlugins
|
|
|
170
172
|
|
|
171
173
|
def install_from_gemfile(gem_file)
|
|
172
174
|
unless File.exist? gem_file
|
|
173
|
-
puts(red {
|
|
175
|
+
puts(red { "No such plugin gem file " } + gem_file + " - installation failed.")
|
|
174
176
|
exit 1
|
|
175
177
|
end
|
|
176
178
|
|
|
177
|
-
plugin_name_parts = File.basename(gem_file,
|
|
179
|
+
plugin_name_parts = File.basename(gem_file, ".gem").split("-")
|
|
178
180
|
version = plugin_name_parts.pop
|
|
179
|
-
plugin_name = plugin_name_parts.join(
|
|
180
|
-
check_plugin_name(plugin_name,
|
|
181
|
+
plugin_name = plugin_name_parts.join("-")
|
|
182
|
+
check_plugin_name(plugin_name, "installation")
|
|
181
183
|
|
|
182
184
|
installer.install(plugin_name, gem_file: gem_file)
|
|
183
185
|
|
|
@@ -187,22 +189,22 @@ module InspecPlugins
|
|
|
187
189
|
|
|
188
190
|
def install_from_path(path)
|
|
189
191
|
unless File.exist? path
|
|
190
|
-
puts(red {
|
|
192
|
+
puts(red { "No such source code path " } + path + " - installation failed.")
|
|
191
193
|
exit 1
|
|
192
194
|
end
|
|
193
195
|
|
|
194
|
-
plugin_name = File.basename(path,
|
|
196
|
+
plugin_name = File.basename(path, ".rb")
|
|
195
197
|
|
|
196
198
|
# While installer.install does some rudimentary checking,
|
|
197
199
|
# this file has good UI access, so we promise to validate the
|
|
198
200
|
# input a lot and hand the installer a sure-thing.
|
|
199
201
|
|
|
200
202
|
# Name OK?
|
|
201
|
-
check_plugin_name(plugin_name,
|
|
203
|
+
check_plugin_name(plugin_name, "installation")
|
|
202
204
|
|
|
203
205
|
# Already installed?
|
|
204
206
|
if registry.known_plugin?(plugin_name.to_sym)
|
|
205
|
-
puts(red {
|
|
207
|
+
puts(red { "Plugin already installed" } + " - #{plugin_name} - Use '#{EXEC_NAME} plugin list' to see previously installed plugin - installation failed.")
|
|
206
208
|
exit 2
|
|
207
209
|
end
|
|
208
210
|
|
|
@@ -215,7 +217,7 @@ module InspecPlugins
|
|
|
215
217
|
# OK, install it!
|
|
216
218
|
installer.install(plugin_name, path: entry_point)
|
|
217
219
|
|
|
218
|
-
puts(bold { plugin_name } +
|
|
220
|
+
puts(bold { plugin_name } + " plugin installed via source path reference, resolved to entry point " + entry_point)
|
|
219
221
|
exit 0
|
|
220
222
|
end
|
|
221
223
|
|
|
@@ -232,14 +234,14 @@ module InspecPlugins
|
|
|
232
234
|
parts = [
|
|
233
235
|
given.parent.parent.basename,
|
|
234
236
|
given.parent.basename,
|
|
235
|
-
given.basename(
|
|
237
|
+
given.basename(".rb"),
|
|
236
238
|
given.extname,
|
|
237
239
|
].map(&:to_s)
|
|
238
240
|
|
|
239
241
|
# Case 1: Simplest case: it was a full entry point, as presented.
|
|
240
242
|
# /home/you/projects/inspec-something/lib/inspec-something.rb
|
|
241
243
|
# parts index: ^0^ ^1^ ^2^ ^3^
|
|
242
|
-
if parts[0] =~ name_regex && parts[1] ==
|
|
244
|
+
if parts[0] =~ name_regex && parts[1] == "lib" && parts[2] == parts[0] && parts[3] == ".rb"
|
|
243
245
|
return given.to_s
|
|
244
246
|
end
|
|
245
247
|
|
|
@@ -247,37 +249,37 @@ module InspecPlugins
|
|
|
247
249
|
# or left the extansion off. Those are the same to us.
|
|
248
250
|
# /home/you/projects/inspec-something/lib/inspec-something
|
|
249
251
|
# parts index: ^0^ ^1^ ^2^ (3 is empty)
|
|
250
|
-
if parts[0] =~ name_regex && parts[1] ==
|
|
251
|
-
return given.to_s +
|
|
252
|
+
if parts[0] =~ name_regex && parts[1] == "lib" && parts[2] == parts[0] && parts[3].empty?
|
|
253
|
+
return given.to_s + ".rb"
|
|
252
254
|
end
|
|
253
255
|
|
|
254
256
|
# Case 3: Maybe they were refering to a path that is inside a gem installation, or an exploded gem?
|
|
255
257
|
# In that case, we'll have a version on the plugin name in part 0
|
|
256
258
|
# /home/you/.gems/2.4.0/gems/inspec-something-3.45.1/lib/inspec-something.rb
|
|
257
259
|
# parts index: ^0^ ^1^ ^2^ ^3^
|
|
258
|
-
if parts[0] =~ versioned_regex && parts[1] ==
|
|
260
|
+
if parts[0] =~ versioned_regex && parts[1] == "lib" && parts[0].start_with?(parts[2]) && parts[3] == ".rb"
|
|
259
261
|
return given.to_s
|
|
260
262
|
end
|
|
261
263
|
|
|
262
264
|
# Case 4: Like case 3, but missing the .rb
|
|
263
265
|
# /home/you/.gems/2.4.0/gems/inspec-something-3.45.1/lib/inspec-something
|
|
264
266
|
# parts index: ^0^ ^1^ ^2^ ^3^ (empty)
|
|
265
|
-
if parts[0] =~ versioned_regex && parts[1] ==
|
|
266
|
-
return given.to_s +
|
|
267
|
+
if parts[0] =~ versioned_regex && parts[1] == "lib" && parts[0].start_with?(parts[2]) && parts[3].empty?
|
|
268
|
+
return given.to_s + ".rb"
|
|
267
269
|
end
|
|
268
270
|
|
|
269
271
|
# Case 5: Easy to recognize, but harder to handle: they referred to the project root.
|
|
270
272
|
# /home/you/projects/inspec-something
|
|
271
273
|
# parts index: ^0^ ^1^ ^2^ (3 is empty)
|
|
272
274
|
# 0 and 1 are not meaningful to us, but we hope to find a parts[2]/lib/inspec-something.rb.
|
|
273
|
-
entry_point_guess = File.join(given.to_s,
|
|
275
|
+
entry_point_guess = File.join(given.to_s, "lib", parts[2] + ".rb")
|
|
274
276
|
if parts[2] =~ name_regex && File.exist?(entry_point_guess)
|
|
275
277
|
return entry_point_guess
|
|
276
278
|
end
|
|
277
279
|
|
|
278
280
|
# Well, if we got here, parts[2] matches an inspec/train prefix, but we have no idea about anything.
|
|
279
281
|
# Give up.
|
|
280
|
-
puts(red {
|
|
282
|
+
puts(red { "Unrecognizable plugin structure" } + " - #{parts[2]} - When installing from a path, please provide the path of the entry point file - installation failed.")
|
|
281
283
|
exit 1
|
|
282
284
|
end
|
|
283
285
|
|
|
@@ -286,23 +288,23 @@ module InspecPlugins
|
|
|
286
288
|
begin
|
|
287
289
|
require entry_point
|
|
288
290
|
rescue LoadError => ex
|
|
289
|
-
puts(red {
|
|
291
|
+
puts(red { "Plugin contains errors" } + " - #{plugin_name} - Encountered errors while trying to test load the plugin entry point, resolved to #{entry_point} - installation failed")
|
|
290
292
|
puts ex.message
|
|
291
293
|
exit 1
|
|
292
294
|
end
|
|
293
295
|
|
|
294
296
|
# OK, the wheels didn't fall off. But is it a plugin?
|
|
295
|
-
if plugin_name.to_s.start_with?(
|
|
297
|
+
if plugin_name.to_s.start_with?("train")
|
|
296
298
|
# Train internal names do not include the prix in their registry entries
|
|
297
299
|
# And the registry is keyed on Strings
|
|
298
|
-
registry_key = plugin_name.to_s.sub(/^train-/,
|
|
300
|
+
registry_key = plugin_name.to_s.sub(/^train-/, "")
|
|
299
301
|
unless Train::Plugins.registry.key?(registry_key)
|
|
300
|
-
puts(red {
|
|
302
|
+
puts(red { "Does not appear to be a plugin" } + " - #{plugin_name} - After probe-loading the supposed plugin, it did not register itself to Train. Ensure something inherits from 'Train.plugin(1)' - installation failed.")
|
|
301
303
|
exit 1
|
|
302
304
|
end
|
|
303
305
|
else
|
|
304
306
|
unless registry.known_plugin?(plugin_name.to_sym)
|
|
305
|
-
puts(red {
|
|
307
|
+
puts(red { "Does not appear to be a plugin" } + " - #{plugin_name} - After probe-loading the supposed plugin, it did not register itself to InSpec. Ensure something inherits from 'Inspec.plugin(2)' - installation failed.")
|
|
306
308
|
exit 1
|
|
307
309
|
end
|
|
308
310
|
end
|
|
@@ -311,7 +313,7 @@ module InspecPlugins
|
|
|
311
313
|
def install_from_remote_gem(plugin_name)
|
|
312
314
|
requested_version = options[:version]
|
|
313
315
|
|
|
314
|
-
check_plugin_name(plugin_name,
|
|
316
|
+
check_plugin_name(plugin_name, "installation")
|
|
315
317
|
|
|
316
318
|
# Version pre-flighting
|
|
317
319
|
pre_installed_versions = installer.list_installed_plugin_gems.select { |spec| spec.name == plugin_name }.map { |spec| spec.version.to_s }
|
|
@@ -346,12 +348,12 @@ module InspecPlugins
|
|
|
346
348
|
they_explicitly_asked_for_a_version = !options[:version].nil?
|
|
347
349
|
what_we_would_install_is_already_installed = pre_installed_versions.include?(requested_version)
|
|
348
350
|
if what_we_would_install_is_already_installed && they_explicitly_asked_for_a_version
|
|
349
|
-
puts(red {
|
|
351
|
+
puts(red { "Plugin already installed at requested version" } + " - plugin #{plugin_name} #{requested_version} - refusing to install.")
|
|
350
352
|
elsif what_we_would_install_is_already_installed && !they_explicitly_asked_for_a_version
|
|
351
|
-
puts(red {
|
|
353
|
+
puts(red { "Plugin already installed at latest version" } + " - plugin #{plugin_name} #{requested_version} - refusing to install.")
|
|
352
354
|
else
|
|
353
355
|
# There are existing versions installed, but none of them are what was requested
|
|
354
|
-
puts(red {
|
|
356
|
+
puts(red { "Update required" } + " - plugin #{plugin_name}, requested #{requested_version}, have #{pre_installed_versions.join(', ')}; use `inspec plugin update` - refusing to install.")
|
|
355
357
|
end
|
|
356
358
|
|
|
357
359
|
exit 2
|
|
@@ -361,20 +363,20 @@ module InspecPlugins
|
|
|
361
363
|
def install_attempt_install(plugin_name) # rubocop: disable Metrics/AbcSize
|
|
362
364
|
installer.install(plugin_name, version: options[:version])
|
|
363
365
|
rescue Inspec::Plugin::V2::PluginExcludedError => ex
|
|
364
|
-
puts(red {
|
|
366
|
+
puts(red { "Plugin on Exclusion List" } + " - #{plugin_name} is listed as an incompatible gem - refusing to install.")
|
|
365
367
|
puts "Rationale: #{ex.details.rationale}"
|
|
366
|
-
puts
|
|
367
|
-
puts
|
|
368
|
+
puts "Exclusion list location: " + File.join(Inspec.src_root, "etc", "plugin_filters.json")
|
|
369
|
+
puts "If you disagree with this determination, please accept our apologies for the misunderstanding, and open an issue at https://github.com/inspec/inspec/issues/new"
|
|
368
370
|
exit 2
|
|
369
371
|
rescue Inspec::Plugin::V2::InstallError
|
|
370
372
|
raise if Inspec::Log.level == :debug
|
|
371
373
|
results = installer.search(plugin_name, exact: true)
|
|
372
374
|
if results.empty?
|
|
373
|
-
puts(red {
|
|
375
|
+
puts(red { "No such plugin gem " } + plugin_name + " could be found on rubygems.org - installation failed.")
|
|
374
376
|
elsif options[:version] && !results[plugin_name].include?(options[:version])
|
|
375
|
-
puts(red {
|
|
377
|
+
puts(red { "No such version" } + " - " + plugin_name + " exists, but no such version #{options[:version]} found on rubygems.org - installation failed.")
|
|
376
378
|
else
|
|
377
|
-
puts(red {
|
|
379
|
+
puts(red { "Unknown error occured " } + " - installation failed.")
|
|
378
380
|
end
|
|
379
381
|
exit 1
|
|
380
382
|
end
|
|
@@ -387,10 +389,10 @@ module InspecPlugins
|
|
|
387
389
|
# Check for path install
|
|
388
390
|
status = Inspec::Plugin::V2::Registry.instance[plugin_name.to_sym]
|
|
389
391
|
if !status
|
|
390
|
-
puts(red {
|
|
392
|
+
puts(red { "No such plugin installed: " } + "#{plugin_name} - update failed")
|
|
391
393
|
exit 1
|
|
392
394
|
elsif status.installation_type == :path
|
|
393
|
-
puts(red {
|
|
395
|
+
puts(red { "Cannot update path-based install: " } + "#{plugin_name} is installed via path reference; use `inspec plugin uninstall` to remove - refusing to update")
|
|
394
396
|
exit 2
|
|
395
397
|
end
|
|
396
398
|
end
|
|
@@ -400,7 +402,7 @@ module InspecPlugins
|
|
|
400
402
|
latest_version = latest_version[plugin_name]&.last
|
|
401
403
|
|
|
402
404
|
if pre_update_versions.include?(latest_version)
|
|
403
|
-
puts(red {
|
|
405
|
+
puts(red { "Already installed at latest version: " } + "#{plugin_name} is at #{latest_version}, which the latest - refusing to update")
|
|
404
406
|
exit 2
|
|
405
407
|
end
|
|
406
408
|
end
|
|
@@ -418,7 +420,7 @@ module InspecPlugins
|
|
|
418
420
|
|
|
419
421
|
def check_plugin_name(plugin_name, action)
|
|
420
422
|
unless plugin_name =~ /^(inspec|train)-/
|
|
421
|
-
puts(red {
|
|
423
|
+
puts(red { "Invalid plugin name" } + " - #{plugin_name} - All inspec plugins must begin with either 'inspec-' or 'train-' - #{action} failed.")
|
|
422
424
|
exit 1
|
|
423
425
|
end
|
|
424
426
|
end
|
|
@@ -435,7 +437,7 @@ module InspecPlugins
|
|
|
435
437
|
.sort_by(&:version)
|
|
436
438
|
.last.version
|
|
437
439
|
when :path
|
|
438
|
-
|
|
440
|
+
"src"
|
|
439
441
|
end
|
|
440
442
|
end
|
|
441
443
|
end
|
data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name.rb
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# This should should never even be loaded.
|
|
1
|
+
# This should should never even be loaded.
|
|
@@ -1,39 +1,43 @@
|
|
|
1
1
|
#=========================================================================================#
|
|
2
2
|
# `inspec plugin SUBCOMMAND` facility
|
|
3
3
|
#=========================================================================================#
|
|
4
|
-
require_relative
|
|
4
|
+
require_relative "../../../shared/core_plugin_test_helper.rb"
|
|
5
5
|
|
|
6
6
|
#-----------------------------------------------------------------------------------------#
|
|
7
7
|
# utilities
|
|
8
8
|
#-----------------------------------------------------------------------------------------#
|
|
9
9
|
module PluginManagerHelpers
|
|
10
|
-
let(:project_repo_path) { File.expand_path(File.join(__FILE__,
|
|
11
|
-
let(:project_fixtures_path) { File.join(project_repo_path,
|
|
12
|
-
let(:project_config_dirs_path) { File.join(project_fixtures_path,
|
|
13
|
-
let(:empty_config_dir_path) { File.join(project_config_dirs_path,
|
|
10
|
+
let(:project_repo_path) { File.expand_path(File.join(__FILE__, "..", "..", "..")) }
|
|
11
|
+
let(:project_fixtures_path) { File.join(project_repo_path, "test", "fixtures") }
|
|
12
|
+
let(:project_config_dirs_path) { File.join(project_fixtures_path, "config_dirs") }
|
|
13
|
+
let(:empty_config_dir_path) { File.join(project_config_dirs_path, "empty") }
|
|
14
14
|
|
|
15
15
|
let(:list_after_run) do
|
|
16
16
|
Proc.new do |run_result, tmp_dir|
|
|
17
17
|
# After installing/uninstalling/whatevering, run list with config in the same dir, and capture it.
|
|
18
|
-
run_result.payload.list_result = run_inspec_process(
|
|
18
|
+
run_result.payload.list_result = run_inspec_process("plugin list", env: { INSPEC_CONFIG_DIR: tmp_dir })
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
def setup
|
|
23
|
+
skip_windows!
|
|
24
|
+
end
|
|
25
|
+
|
|
22
26
|
def copy_in_project_config_dir(fixture_name, dest = nil)
|
|
23
|
-
src = Dir.glob(File.join(project_config_dirs_path, fixture_name,
|
|
24
|
-
dest ||= File.join(project_config_dirs_path,
|
|
27
|
+
src = Dir.glob(File.join(project_config_dirs_path, fixture_name, "*"))
|
|
28
|
+
dest ||= File.join(project_config_dirs_path, "empty")
|
|
25
29
|
src.each { |path| FileUtils.cp_r(path, dest) }
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
def copy_in_core_config_dir(fixture_name, dest = nil)
|
|
29
|
-
src = Dir.glob(File.join(core_config_dir_path, fixture_name,
|
|
30
|
-
dest ||= File.join(project_config_dirs_path,
|
|
33
|
+
src = Dir.glob(File.join(core_config_dir_path, fixture_name, "*"))
|
|
34
|
+
dest ||= File.join(project_config_dirs_path, "empty")
|
|
31
35
|
src.each { |path| FileUtils.cp_r(path, dest) }
|
|
32
36
|
end
|
|
33
37
|
|
|
34
38
|
def clear_empty_config_dir
|
|
35
|
-
Dir.glob(File.join(project_config_dirs_path,
|
|
36
|
-
next if path.end_with?
|
|
39
|
+
Dir.glob(File.join(project_config_dirs_path, "empty", "*")).each do |path|
|
|
40
|
+
next if path.end_with? ".gitkeep"
|
|
37
41
|
FileUtils.rm_rf(path)
|
|
38
42
|
end
|
|
39
43
|
end
|
|
@@ -46,60 +50,64 @@ end
|
|
|
46
50
|
#-----------------------------------------------------------------------------------------#
|
|
47
51
|
# inspec help
|
|
48
52
|
#-----------------------------------------------------------------------------------------#
|
|
49
|
-
class PluginManagerCliHelp <
|
|
53
|
+
class PluginManagerCliHelp < Minitest::Test
|
|
50
54
|
include CorePluginFunctionalHelper
|
|
51
55
|
|
|
56
|
+
def setup
|
|
57
|
+
skip_windows!
|
|
58
|
+
end
|
|
59
|
+
|
|
52
60
|
# Main inspec help subcommand listing
|
|
53
61
|
def test_inspec_help_includes_plugin
|
|
54
|
-
result = run_inspec_process_with_this_plugin(
|
|
55
|
-
assert_includes result.stdout,
|
|
62
|
+
result = run_inspec_process_with_this_plugin("help")
|
|
63
|
+
assert_includes result.stdout, "inspec plugin"
|
|
56
64
|
end
|
|
57
65
|
|
|
58
66
|
# inspec plugin help subcommand listing
|
|
59
67
|
def test_inspec_plugin_help_includes_plugin
|
|
60
|
-
result = run_inspec_process_with_this_plugin(
|
|
61
|
-
assert_includes result.stdout,
|
|
62
|
-
assert_includes result.stdout,
|
|
63
|
-
assert_includes result.stdout,
|
|
64
|
-
assert_includes result.stdout,
|
|
65
|
-
assert_includes result.stdout,
|
|
68
|
+
result = run_inspec_process_with_this_plugin("plugin help")
|
|
69
|
+
assert_includes result.stdout, "inspec plugin list"
|
|
70
|
+
assert_includes result.stdout, "inspec plugin search"
|
|
71
|
+
assert_includes result.stdout, "inspec plugin install"
|
|
72
|
+
assert_includes result.stdout, "inspec plugin update"
|
|
73
|
+
assert_includes result.stdout, "inspec plugin uninstall"
|
|
66
74
|
end
|
|
67
75
|
end
|
|
68
76
|
|
|
69
77
|
#-----------------------------------------------------------------------------------------#
|
|
70
78
|
# inspec plugin list
|
|
71
79
|
#-----------------------------------------------------------------------------------------#
|
|
72
|
-
class PluginManagerCliList <
|
|
80
|
+
class PluginManagerCliList < Minitest::Test
|
|
73
81
|
include CorePluginFunctionalHelper
|
|
74
82
|
include PluginManagerHelpers
|
|
75
83
|
|
|
76
84
|
def test_list_when_no_user_plugins_installed
|
|
77
|
-
result = run_inspec_process_with_this_plugin(
|
|
78
|
-
assert_equal 0, result.exit_status,
|
|
79
|
-
assert_includes result.stdout,
|
|
85
|
+
result = run_inspec_process_with_this_plugin("plugin list")
|
|
86
|
+
assert_equal 0, result.exit_status, "exist status must be 0"
|
|
87
|
+
assert_includes result.stdout, "0 plugin(s) total", "Empty list should include zero count"
|
|
80
88
|
end
|
|
81
89
|
|
|
82
90
|
def test_list_all_when_no_user_plugins_installed
|
|
83
|
-
result = run_inspec_process_with_this_plugin(
|
|
84
|
-
assert_equal 0, result.exit_status,
|
|
85
|
-
assert_includes result.stdout,
|
|
86
|
-
assert_includes result.stdout,
|
|
87
|
-
assert_includes result.stdout,
|
|
91
|
+
result = run_inspec_process_with_this_plugin("plugin list --all")
|
|
92
|
+
assert_equal 0, result.exit_status, "exist status must be 0"
|
|
93
|
+
assert_includes result.stdout, "6 plugin(s) total", "--all list should find six"
|
|
94
|
+
assert_includes result.stdout, "inspec-plugin-manager-cli", "--all list should find inspec-plugin-manager-cli"
|
|
95
|
+
assert_includes result.stdout, "habitat", "--all list should find habitat"
|
|
88
96
|
|
|
89
|
-
result = run_inspec_process_with_this_plugin(
|
|
90
|
-
assert_equal 0, result.exit_status,
|
|
91
|
-
assert_includes result.stdout,
|
|
97
|
+
result = run_inspec_process_with_this_plugin("plugin list -a")
|
|
98
|
+
assert_equal 0, result.exit_status, "exist status must be 0"
|
|
99
|
+
assert_includes result.stdout, "6 plugin(s) total", "-a list should find six"
|
|
92
100
|
end
|
|
93
101
|
|
|
94
102
|
def test_list_when_gem_and_path_plugins_installed
|
|
95
103
|
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
|
96
104
|
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
|
97
|
-
copy_in_core_config_dir(
|
|
105
|
+
copy_in_core_config_dir("test-fixture-1-float", tmp_dir)
|
|
98
106
|
end
|
|
99
107
|
|
|
100
|
-
result = run_inspec_process_with_this_plugin(
|
|
101
|
-
assert_equal 0, result.exit_status,
|
|
102
|
-
assert_includes result.stdout,
|
|
108
|
+
result = run_inspec_process_with_this_plugin("plugin list", pre_run: pre_block)
|
|
109
|
+
assert_equal 0, result.exit_status, "exist status must be 0"
|
|
110
|
+
assert_includes result.stdout, "2 plugin(s) total", "gem+path should show two plugins"
|
|
103
111
|
|
|
104
112
|
# Plugin Name Version Via ApiVer
|
|
105
113
|
# -------------------------------------------------------
|
|
@@ -116,12 +124,12 @@ class PluginManagerCliList < MiniTest::Test
|
|
|
116
124
|
def test_list_when_a_train_plugin_is_installed
|
|
117
125
|
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
|
118
126
|
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
|
119
|
-
copy_in_core_config_dir(
|
|
127
|
+
copy_in_core_config_dir("train-test-fixture", tmp_dir)
|
|
120
128
|
end
|
|
121
129
|
|
|
122
|
-
result = run_inspec_process_with_this_plugin(
|
|
123
|
-
assert_equal 0, result.exit_status,
|
|
124
|
-
assert_includes result.stdout,
|
|
130
|
+
result = run_inspec_process_with_this_plugin("plugin list", pre_run: pre_block)
|
|
131
|
+
assert_equal 0, result.exit_status, "exist status must be 0"
|
|
132
|
+
assert_includes result.stdout, "1 plugin(s) total", "list train should show one plugins"
|
|
125
133
|
|
|
126
134
|
# Plugin Name Version Via ApiVer
|
|
127
135
|
# -------------------------------------------------------
|
|
@@ -129,17 +137,17 @@ class PluginManagerCliList < MiniTest::Test
|
|
|
129
137
|
# -------------------------------------------------------
|
|
130
138
|
# 1 plugin(s) total
|
|
131
139
|
train_line = result.stdout.split("\n").grep(/train/).first
|
|
132
|
-
assert_includes(train_line,
|
|
133
|
-
assert_includes(train_line,
|
|
134
|
-
assert_includes(train_line,
|
|
135
|
-
assert_includes(train_line,
|
|
140
|
+
assert_includes(train_line, "train-test-fixture")
|
|
141
|
+
assert_includes(train_line, "0.1.0")
|
|
142
|
+
assert_includes(train_line, "gem")
|
|
143
|
+
assert_includes(train_line, "train-1")
|
|
136
144
|
end
|
|
137
145
|
end
|
|
138
146
|
|
|
139
147
|
#-----------------------------------------------------------------------------------------#
|
|
140
148
|
# inspec plugin search
|
|
141
149
|
#-----------------------------------------------------------------------------------------#
|
|
142
|
-
class PluginManagerCliSearch <
|
|
150
|
+
class PluginManagerCliSearch < Minitest::Test
|
|
143
151
|
include CorePluginFunctionalHelper
|
|
144
152
|
include PluginManagerHelpers
|
|
145
153
|
|
|
@@ -150,213 +158,213 @@ class PluginManagerCliSearch < MiniTest::Test
|
|
|
150
158
|
# end
|
|
151
159
|
|
|
152
160
|
def test_search_for_a_real_gem_with_full_name_no_options
|
|
153
|
-
result = run_inspec_process(
|
|
154
|
-
assert_equal 0, result.exit_status,
|
|
155
|
-
assert_includes result.stdout,
|
|
156
|
-
assert_includes result.stdout,
|
|
161
|
+
result = run_inspec_process("plugin search --include-test-fixture inspec-test-fixture")
|
|
162
|
+
assert_equal 0, result.exit_status, "Search should exit 0 on a hit"
|
|
163
|
+
assert_includes result.stdout, "inspec-test-fixture", "Search result should contain the gem name"
|
|
164
|
+
assert_includes result.stdout, "1 plugin(s) found", "Search result should find 1 plugin"
|
|
157
165
|
line = result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
|
158
|
-
assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/,line,
|
|
166
|
+
assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/, line, "Plugin line should include name and exactly one version")
|
|
159
167
|
end
|
|
160
168
|
|
|
161
169
|
def test_search_for_a_real_gem_with_stub_name_no_options
|
|
162
|
-
result = run_inspec_process(
|
|
163
|
-
assert_equal 0, result.exit_status,
|
|
164
|
-
assert_includes result.stdout,
|
|
165
|
-
assert_includes result.stdout,
|
|
170
|
+
result = run_inspec_process("plugin search --include-test-fixture inspec-test-")
|
|
171
|
+
assert_equal 0, result.exit_status, "Search should exit 0 on a hit"
|
|
172
|
+
assert_includes result.stdout, "inspec-test-fixture", "Search result should contain the gem name"
|
|
173
|
+
assert_includes result.stdout, "1 plugin(s) found", "Search result should find 1 plugin"
|
|
166
174
|
|
|
167
175
|
line = result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
|
168
|
-
assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/,line,
|
|
176
|
+
assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/, line, "Plugin line should include name and exactly one version")
|
|
169
177
|
end
|
|
170
178
|
|
|
171
179
|
def test_search_for_a_real_gem_with_full_name_and_exact_option
|
|
172
|
-
result = run_inspec_process(
|
|
173
|
-
assert_equal 0, result.exit_status,
|
|
174
|
-
assert_includes result.stdout,
|
|
175
|
-
assert_includes result.stdout,
|
|
180
|
+
result = run_inspec_process("plugin search --exact --include-test-fixture inspec-test-fixture")
|
|
181
|
+
assert_equal 0, result.exit_status, "Search should exit 0 on a hit"
|
|
182
|
+
assert_includes result.stdout, "inspec-test-fixture", "Search result should contain the gem name"
|
|
183
|
+
assert_includes result.stdout, "1 plugin(s) found", "Search result should find 1 plugin"
|
|
176
184
|
|
|
177
|
-
result = run_inspec_process(
|
|
178
|
-
assert_equal 0, result.exit_status,
|
|
185
|
+
result = run_inspec_process("plugin search -e --include-test-fixture inspec-test-fixture")
|
|
186
|
+
assert_equal 0, result.exit_status, "Search should exit 0 on a hit"
|
|
179
187
|
end
|
|
180
188
|
|
|
181
189
|
def test_search_for_a_real_gem_with_stub_name_and_exact_option
|
|
182
|
-
result = run_inspec_process(
|
|
183
|
-
assert_equal 2, result.exit_status,
|
|
184
|
-
assert_includes result.stdout,
|
|
190
|
+
result = run_inspec_process("plugin search --exact --include-test-fixture inspec-test-")
|
|
191
|
+
assert_equal 2, result.exit_status, "Search should exit 2 on a miss"
|
|
192
|
+
assert_includes result.stdout, "0 plugin(s) found", "Search result should find 0 plugins"
|
|
185
193
|
|
|
186
|
-
result = run_inspec_process(
|
|
187
|
-
assert_equal 2, result.exit_status,
|
|
194
|
+
result = run_inspec_process("plugin search -e --include-test-fixture inspec-test-")
|
|
195
|
+
assert_equal 2, result.exit_status, "Search should exit 2 on a miss"
|
|
188
196
|
end
|
|
189
197
|
|
|
190
198
|
def test_search_for_a_real_gem_with_full_name_and_all_option
|
|
191
|
-
result = run_inspec_process(
|
|
192
|
-
assert_equal 0, result.exit_status,
|
|
193
|
-
assert_includes result.stdout,
|
|
194
|
-
assert_includes result.stdout,
|
|
199
|
+
result = run_inspec_process("plugin search --all --include-test-fixture inspec-test-fixture")
|
|
200
|
+
assert_equal 0, result.exit_status, "Search should exit 0 on a hit"
|
|
201
|
+
assert_includes result.stdout, "inspec-test-fixture", "Search result should contain the gem name"
|
|
202
|
+
assert_includes result.stdout, "1 plugin(s) found", "Search result should find 1 plugin"
|
|
195
203
|
|
|
196
204
|
line = result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
|
197
|
-
assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+(,\s)?){2,}\)/,line,
|
|
205
|
+
assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+(,\s)?){2,}\)/, line, "Plugin line should include name and at least two versions")
|
|
198
206
|
|
|
199
|
-
result = run_inspec_process(
|
|
200
|
-
assert_equal 0, result.exit_status,
|
|
207
|
+
result = run_inspec_process("plugin search -a --include-test-fixture inspec-test-fixture")
|
|
208
|
+
assert_equal 0, result.exit_status, "Search should exit 0 on a hit"
|
|
201
209
|
end
|
|
202
210
|
|
|
203
211
|
def test_search_for_a_gem_with_missing_prefix
|
|
204
|
-
result = run_inspec_process(
|
|
205
|
-
assert_equal 1, result.exit_status,
|
|
212
|
+
result = run_inspec_process("plugin search --include-test-fixture test-fixture")
|
|
213
|
+
assert_equal 1, result.exit_status, "Search should exit 1 on user error"
|
|
206
214
|
assert_includes result.stdout, "All inspec plugins must begin with either 'inspec-' or 'train-'"
|
|
207
215
|
end
|
|
208
216
|
|
|
209
217
|
def test_search_for_a_gem_that_does_not_exist
|
|
210
|
-
result = run_inspec_process(
|
|
211
|
-
assert_equal 2, result.exit_status,
|
|
212
|
-
assert_includes result.stdout,
|
|
218
|
+
result = run_inspec_process("plugin search --include-test-fixture inspec-test-fixture-nonesuch")
|
|
219
|
+
assert_equal 2, result.exit_status, "Search should exit 2 on a miss"
|
|
220
|
+
assert_includes result.stdout, "0 plugin(s) found", "Search result should find 0 plugins"
|
|
213
221
|
end
|
|
214
222
|
|
|
215
223
|
def test_search_for_a_real_gem_with_full_name_no_options_and_train_name
|
|
216
|
-
result = run_inspec_process(
|
|
217
|
-
assert_equal 0, result.exit_status,
|
|
218
|
-
assert_includes result.stdout,
|
|
219
|
-
assert_includes result.stdout,
|
|
224
|
+
result = run_inspec_process("plugin search --include-test-fixture train-test-fixture")
|
|
225
|
+
assert_equal 0, result.exit_status, "Search should exit 0 on a hit"
|
|
226
|
+
assert_includes result.stdout, "train-test-fixture", "Search result should contain the gem name"
|
|
227
|
+
assert_includes result.stdout, "1 plugin(s) found", "Search result should find 1 plugin"
|
|
220
228
|
line = result.stdout.split("\n").grep(/train-test-fixture/).first
|
|
221
|
-
assert_match(/\s*train-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/,line,
|
|
229
|
+
assert_match(/\s*train-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/, line, "Plugin line should include name and exactly one version")
|
|
222
230
|
end
|
|
223
231
|
|
|
224
232
|
def test_search_omit_excluded_inspec_plugins
|
|
225
|
-
result = run_inspec_process(
|
|
226
|
-
assert_equal 0, result.exit_status,
|
|
227
|
-
assert_includes result.stdout,
|
|
233
|
+
result = run_inspec_process("plugin search --include-test-fixture inspec-")
|
|
234
|
+
assert_equal 0, result.exit_status, "Search should exit 0"
|
|
235
|
+
assert_includes result.stdout, "inspec-test-fixture", "Search result should contain the test gem"
|
|
228
236
|
[
|
|
229
|
-
|
|
230
|
-
|
|
237
|
+
"inspec-core",
|
|
238
|
+
"inspec-multi-server",
|
|
231
239
|
].each do |plugin_name|
|
|
232
|
-
refute_includes result.stdout, plugin_name,
|
|
240
|
+
refute_includes result.stdout, plugin_name, "Search result should not contain excluded gems"
|
|
233
241
|
end
|
|
234
242
|
end
|
|
243
|
+
|
|
235
244
|
def test_search_for_a_real_gem_with_full_name_no_options_filter_fixtures
|
|
236
|
-
result = run_inspec_process(
|
|
237
|
-
refute_includes result.stdout,
|
|
245
|
+
result = run_inspec_process("plugin search inspec-test-fixture")
|
|
246
|
+
refute_includes result.stdout, "inspec-test-fixture", "Search result should not contain the fixture gem name"
|
|
238
247
|
end
|
|
239
248
|
|
|
240
249
|
def test_search_for_a_real_gem_with_full_name_no_options_filter_fixtures_train
|
|
241
|
-
result = run_inspec_process(
|
|
242
|
-
refute_includes result.stdout,
|
|
250
|
+
result = run_inspec_process("plugin search train-test-fixture")
|
|
251
|
+
refute_includes result.stdout, "train-test-fixture", "Search result should not contain the fixture gem name"
|
|
243
252
|
end
|
|
244
253
|
|
|
245
|
-
|
|
246
254
|
end
|
|
247
255
|
|
|
248
256
|
#-----------------------------------------------------------------------------------------#
|
|
249
257
|
# inspec plugin install
|
|
250
258
|
#-----------------------------------------------------------------------------------------#
|
|
251
|
-
class PluginManagerCliInstall <
|
|
259
|
+
class PluginManagerCliInstall < Minitest::Test
|
|
252
260
|
include CorePluginFunctionalHelper # gives us instance methods, like `let` aliases inside test methods
|
|
253
261
|
extend CorePluginFunctionalHelper # gives us class methods, like `let` aliases out here outside test methods
|
|
254
262
|
|
|
255
263
|
include PluginManagerHelpers
|
|
256
|
-
ruby_abi_version = (Gem.ruby_version.segments[0, 2] << 0).join(
|
|
264
|
+
ruby_abi_version = (Gem.ruby_version.segments[0, 2] << 0).join(".")
|
|
257
265
|
# Test multiple hueristics of the path-mode install.
|
|
258
266
|
# These are all positive tests; they should resolve the entry point to the same path in each case.
|
|
259
267
|
{
|
|
260
|
-
|
|
261
|
-
given: File.join(core_fixture_plugins_path,
|
|
268
|
+
"is_perfect" => {
|
|
269
|
+
given: File.join(core_fixture_plugins_path, "inspec-test-fixture", "lib", "inspec-test-fixture.rb"),
|
|
262
270
|
},
|
|
263
|
-
|
|
264
|
-
given: File.join(core_fixture_plugins_path,
|
|
271
|
+
"refers_to_the_entry_point_with_no_extension" => {
|
|
272
|
+
given: File.join(core_fixture_plugins_path, "inspec-test-fixture", "lib", "inspec-test-fixture"),
|
|
265
273
|
},
|
|
266
|
-
|
|
267
|
-
given: File.join(core_fixture_plugins_path,
|
|
274
|
+
"refers_to_the_src_root_of_a_plugin" => {
|
|
275
|
+
given: File.join(core_fixture_plugins_path, "inspec-test-fixture"),
|
|
268
276
|
},
|
|
269
|
-
|
|
270
|
-
given: File.join(core_config_dir_path,
|
|
271
|
-
resolved_path: File.join(core_config_dir_path,
|
|
277
|
+
"refers_to_a_versioned_gem_install" => {
|
|
278
|
+
given: File.join(core_config_dir_path, "test-fixture-1-float", "gems", ruby_abi_version, "gems", "inspec-test-fixture-0.1.0", "lib", "inspec-test-fixture.rb"),
|
|
279
|
+
resolved_path: File.join(core_config_dir_path, "test-fixture-1-float", "gems", ruby_abi_version, "gems", "inspec-test-fixture-0.1.0", "lib", "inspec-test-fixture.rb"),
|
|
272
280
|
},
|
|
273
|
-
|
|
274
|
-
given: File.join(core_config_dir_path,
|
|
275
|
-
resolved_path: File.join(core_config_dir_path,
|
|
281
|
+
"refers_to_a_versioned_gem_install_missing_extension" => {
|
|
282
|
+
given: File.join(core_config_dir_path, "test-fixture-1-float", "gems", ruby_abi_version, "gems", "inspec-test-fixture-0.1.0", "lib", "inspec-test-fixture"),
|
|
283
|
+
resolved_path: File.join(core_config_dir_path, "test-fixture-1-float", "gems", ruby_abi_version, "gems", "inspec-test-fixture-0.1.0", "lib", "inspec-test-fixture.rb"),
|
|
276
284
|
},
|
|
277
|
-
|
|
278
|
-
given: File.join(
|
|
285
|
+
"refers_to_a_relative_path" => {
|
|
286
|
+
given: File.join("test", "unit", "mock", "plugins", "inspec-test-fixture", "lib", "inspec-test-fixture.rb"),
|
|
279
287
|
},
|
|
280
|
-
|
|
281
|
-
given: File.join(core_config_dir_path,
|
|
282
|
-
plugin_name:
|
|
283
|
-
resolved_path: File.join(core_config_dir_path,
|
|
288
|
+
"refers_to_a_train_plugin" => {
|
|
289
|
+
given: File.join(core_config_dir_path, "train-test-fixture", "gems", ruby_abi_version, "gems", "train-test-fixture-0.1.0", "lib", "train-test-fixture.rb"),
|
|
290
|
+
plugin_name: "train-test-fixture",
|
|
291
|
+
resolved_path: File.join(core_config_dir_path, "train-test-fixture", "gems", ruby_abi_version, "gems", "train-test-fixture-0.1.0", "lib", "train-test-fixture.rb"),
|
|
284
292
|
},
|
|
285
293
|
}.each do |test_name, fixture_info|
|
|
286
|
-
define_method((
|
|
294
|
+
define_method(("test_install_from_path_when_path_" + test_name).to_sym) do
|
|
287
295
|
fixture_info = {
|
|
288
|
-
plugin_name:
|
|
289
|
-
resolved_path: File.join(core_fixture_plugins_path,
|
|
296
|
+
plugin_name: "inspec-test-fixture",
|
|
297
|
+
resolved_path: File.join(core_fixture_plugins_path, "inspec-test-fixture", "lib", "inspec-test-fixture.rb"),
|
|
290
298
|
}.merge(fixture_info)
|
|
291
299
|
|
|
292
300
|
install_result = run_inspec_process_with_this_plugin("plugin install #{fixture_info[:given]}", post_run: list_after_run)
|
|
293
301
|
|
|
294
302
|
assert_empty install_result.stderr
|
|
295
|
-
assert_equal 0, install_result.exit_status,
|
|
303
|
+
assert_equal 0, install_result.exit_status, "Exit status should be 0"
|
|
296
304
|
|
|
297
305
|
# Check UX messaging
|
|
298
306
|
success_message = install_result.stdout.split("\n").grep(/installed/).last
|
|
299
|
-
refute_nil success_message,
|
|
307
|
+
refute_nil success_message, "Should find a success message at the end"
|
|
300
308
|
assert_includes success_message, fixture_info[:plugin_name]
|
|
301
|
-
assert_includes success_message,
|
|
309
|
+
assert_includes success_message, "plugin installed via source path reference"
|
|
302
310
|
|
|
303
311
|
# Check round-trip UX via list
|
|
304
312
|
list_result = install_result.payload.list_result
|
|
305
313
|
itf_line = list_result.stdout.split("\n").grep(Regexp.new(fixture_info[:plugin_name])).first
|
|
306
|
-
refute_nil itf_line,
|
|
307
|
-
assert_match(/\s*(inspec|train)-test-fixture\s+src\s+path\s+/, itf_line,
|
|
314
|
+
refute_nil itf_line, "plugin name should now appear in the output of inspec list"
|
|
315
|
+
assert_match(/\s*(inspec|train)-test-fixture\s+src\s+path\s+/, itf_line, "list output should show that it is a path installation")
|
|
308
316
|
|
|
309
317
|
# Check plugin statefile. Extra important in this case, since all should resolve to the same entry point.
|
|
310
318
|
plugin_data = install_result.payload.plugin_data
|
|
311
|
-
entry = plugin_data[
|
|
312
|
-
assert_equal fixture_info[:resolved_path], entry[
|
|
319
|
+
entry = plugin_data["plugins"].detect { |e| e["name"] == fixture_info[:plugin_name] }
|
|
320
|
+
assert_equal fixture_info[:resolved_path], entry["installation_path"], "Regardless of input, the entry point should be correct."
|
|
313
321
|
end
|
|
314
322
|
end
|
|
315
323
|
|
|
316
324
|
def test_fail_install_from_nonexistant_path
|
|
317
|
-
bad_path = File.join(project_fixtures_path,
|
|
325
|
+
bad_path = File.join(project_fixtures_path, "none", "such", "inspec-test-fixture-nonesuch.rb")
|
|
318
326
|
install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
|
|
319
327
|
|
|
320
328
|
assert_empty install_result.stderr
|
|
321
|
-
assert_equal 1, install_result.exit_status,
|
|
329
|
+
assert_equal 1, install_result.exit_status, "Exit status should be 1"
|
|
322
330
|
|
|
323
331
|
error_message = install_result.stdout.split("\n").last
|
|
324
332
|
assert_includes error_message, "No such source code path"
|
|
325
|
-
assert_includes error_message,
|
|
326
|
-
assert_includes error_message,
|
|
333
|
+
assert_includes error_message, "inspec-test-fixture-nonesuch.rb"
|
|
334
|
+
assert_includes error_message, "installation failed"
|
|
327
335
|
end
|
|
328
336
|
|
|
329
337
|
def test_fail_install_from_path_with_wrong_name
|
|
330
|
-
bad_path = File.join(project_fixtures_path,
|
|
338
|
+
bad_path = File.join(project_fixtures_path, "plugins", "wrong-name", "lib", "wrong-name.rb")
|
|
331
339
|
install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
|
|
332
340
|
|
|
333
341
|
assert_empty install_result.stderr
|
|
334
|
-
assert_equal 1, install_result.exit_status,
|
|
342
|
+
assert_equal 1, install_result.exit_status, "Exit status should be 1"
|
|
335
343
|
|
|
336
344
|
error_message = install_result.stdout.split("\n").last
|
|
337
345
|
assert_includes error_message, "Invalid plugin name"
|
|
338
|
-
assert_includes error_message,
|
|
346
|
+
assert_includes error_message, "wrong-name"
|
|
339
347
|
assert_includes error_message, "All inspec plugins must begin with either 'inspec-' or 'train-'"
|
|
340
|
-
assert_includes error_message,
|
|
348
|
+
assert_includes error_message, "installation failed"
|
|
341
349
|
end
|
|
342
350
|
|
|
343
351
|
def test_fail_install_from_path_when_it_is_not_a_plugin
|
|
344
|
-
bad_path = File.join(project_fixtures_path,
|
|
352
|
+
bad_path = File.join(project_fixtures_path, "plugins", "inspec-egg-white-omelette", "lib", "inspec-egg-white-omelette.rb")
|
|
345
353
|
install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
|
|
346
354
|
|
|
347
355
|
assert_empty install_result.stderr
|
|
348
|
-
assert_equal 1, install_result.exit_status,
|
|
356
|
+
assert_equal 1, install_result.exit_status, "Exit status should be 1"
|
|
349
357
|
|
|
350
358
|
error_message = install_result.stdout.split("\n").last
|
|
351
359
|
assert_includes error_message, "Does not appear to be a plugin"
|
|
352
|
-
assert_includes error_message,
|
|
360
|
+
assert_includes error_message, "inspec-egg-white-omelette"
|
|
353
361
|
assert_includes error_message, "After probe-loading the supposed plugin, it did not register"
|
|
354
362
|
assert_includes error_message, "Ensure something inherits from 'Inspec.plugin(2)'"
|
|
355
|
-
assert_includes error_message,
|
|
363
|
+
assert_includes error_message, "installation failed"
|
|
356
364
|
end
|
|
357
365
|
|
|
358
366
|
def test_fail_install_from_path_when_it_is_already_installed
|
|
359
|
-
plugin_path = File.join(core_fixture_plugins_path,
|
|
367
|
+
plugin_path = File.join(core_fixture_plugins_path, "inspec-test-fixture", "lib", "inspec-test-fixture.rb")
|
|
360
368
|
pre_block = Proc.new do |plugin_data, _tmp_dir|
|
|
361
369
|
plugin_data["plugins"] << {
|
|
362
370
|
"name" => "inspec-test-fixture",
|
|
@@ -367,347 +375,349 @@ class PluginManagerCliInstall < MiniTest::Test
|
|
|
367
375
|
|
|
368
376
|
install_result = run_inspec_process_with_this_plugin("plugin install #{plugin_path}", pre_run: pre_block)
|
|
369
377
|
assert_empty install_result.stderr
|
|
370
|
-
assert_equal 2, install_result.exit_status,
|
|
378
|
+
assert_equal 2, install_result.exit_status, "Exit status on second install should be 2"
|
|
371
379
|
|
|
372
380
|
error_message = install_result.stdout.split("\n").last
|
|
373
381
|
assert_includes error_message, "Plugin already installed"
|
|
374
|
-
assert_includes error_message,
|
|
382
|
+
assert_includes error_message, "inspec-test-fixture"
|
|
375
383
|
assert_includes error_message, "Use 'inspec plugin list' to see previously installed plugin"
|
|
376
|
-
assert_includes error_message,
|
|
384
|
+
assert_includes error_message, "installation failed"
|
|
377
385
|
end
|
|
378
386
|
|
|
379
387
|
def test_fail_install_from_path_when_the_dir_structure_is_wrong
|
|
380
|
-
bad_path = File.join(project_fixtures_path,
|
|
388
|
+
bad_path = File.join(project_fixtures_path, "plugins", "inspec-wrong-structure")
|
|
381
389
|
install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
|
|
382
390
|
|
|
383
391
|
assert_empty install_result.stderr
|
|
384
|
-
assert_equal 1, install_result.exit_status,
|
|
392
|
+
assert_equal 1, install_result.exit_status, "Exit status should be 1"
|
|
385
393
|
|
|
386
394
|
error_message = install_result.stdout.split("\n").last
|
|
387
395
|
assert_includes error_message, "Unrecognizable plugin structure"
|
|
388
|
-
assert_includes error_message,
|
|
389
|
-
assert_includes error_message,
|
|
390
|
-
assert_includes error_message,
|
|
396
|
+
assert_includes error_message, "inspec-wrong-structure"
|
|
397
|
+
assert_includes error_message, " When installing from a path, please provide the path of the entry point file"
|
|
398
|
+
assert_includes error_message, "installation failed"
|
|
391
399
|
end
|
|
392
400
|
|
|
393
401
|
def test_install_from_gemfile
|
|
394
|
-
fixture_gemfile_path = File.join(core_fixture_plugins_path,
|
|
402
|
+
fixture_gemfile_path = File.join(core_fixture_plugins_path, "inspec-test-fixture", "pkg", "inspec-test-fixture-0.1.0.gem")
|
|
395
403
|
install_result = run_inspec_process_with_this_plugin("plugin install #{fixture_gemfile_path}", post_run: list_after_run)
|
|
396
404
|
|
|
397
405
|
assert_empty install_result.stderr
|
|
398
|
-
assert_equal 0, install_result.exit_status,
|
|
406
|
+
assert_equal 0, install_result.exit_status, "Exit status should be 0"
|
|
399
407
|
|
|
400
408
|
success_message = install_result.stdout.split("\n").grep(/installed/).last
|
|
401
|
-
refute_nil success_message,
|
|
402
|
-
assert_includes success_message,
|
|
403
|
-
assert_includes success_message,
|
|
404
|
-
assert_includes success_message,
|
|
409
|
+
refute_nil success_message, "Should find a success message at the end"
|
|
410
|
+
assert_includes success_message, "inspec-test-fixture"
|
|
411
|
+
assert_includes success_message, "0.1.0"
|
|
412
|
+
assert_includes success_message, "installed from local .gem file"
|
|
405
413
|
|
|
406
414
|
list_result = install_result.payload.list_result
|
|
407
415
|
itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
|
408
|
-
refute_nil itf_line,
|
|
409
|
-
assert_match(/\s*inspec-test-fixture\s+0.1.0\s+gem\s+/, itf_line,
|
|
416
|
+
refute_nil itf_line, "inspec-test-fixture should now appear in the output of inspec list"
|
|
417
|
+
assert_match(/\s*inspec-test-fixture\s+0.1.0\s+gem\s+/, itf_line, "list output should show that it is a gem installation with version")
|
|
410
418
|
end
|
|
411
419
|
|
|
412
420
|
def test_fail_install_from_nonexistant_gemfile
|
|
413
|
-
bad_path = File.join(project_fixtures_path,
|
|
421
|
+
bad_path = File.join(project_fixtures_path, "none", "such", "inspec-test-fixture-nonesuch-0.3.0.gem")
|
|
414
422
|
install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
|
|
415
423
|
|
|
416
424
|
assert_empty install_result.stderr
|
|
417
|
-
assert_equal 1, install_result.exit_status,
|
|
425
|
+
assert_equal 1, install_result.exit_status, "Exit status should be 1"
|
|
418
426
|
assert_match(/No such plugin gem file .+ - installation failed./, install_result.stdout)
|
|
419
427
|
end
|
|
420
428
|
|
|
421
429
|
def test_install_from_rubygems_latest
|
|
422
|
-
install_result = run_inspec_process_with_this_plugin(
|
|
430
|
+
install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture", post_run: list_after_run)
|
|
423
431
|
|
|
424
432
|
assert_empty install_result.stderr
|
|
425
|
-
assert_equal 0, install_result.exit_status,
|
|
433
|
+
assert_equal 0, install_result.exit_status, "Exit status should be 0"
|
|
426
434
|
|
|
427
435
|
success_message = install_result.stdout.split("\n").grep(/installed/).last
|
|
428
|
-
refute_nil success_message,
|
|
429
|
-
assert_includes success_message,
|
|
430
|
-
assert_includes success_message,
|
|
431
|
-
assert_includes success_message,
|
|
436
|
+
refute_nil success_message, "Should find a success message at the end"
|
|
437
|
+
assert_includes success_message, "inspec-test-fixture"
|
|
438
|
+
assert_includes success_message, "0.2.0"
|
|
439
|
+
assert_includes success_message, "installed from rubygems.org"
|
|
432
440
|
|
|
433
441
|
list_result = install_result.payload.list_result
|
|
434
442
|
itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
|
435
|
-
refute_nil itf_line,
|
|
436
|
-
assert_match(/\s*inspec-test-fixture\s+0.2.0\s+gem\s+/, itf_line,
|
|
443
|
+
refute_nil itf_line, "inspec-test-fixture should now appear in the output of inspec list"
|
|
444
|
+
assert_match(/\s*inspec-test-fixture\s+0.2.0\s+gem\s+/, itf_line, "list output should show that it is a gem installation with version")
|
|
437
445
|
end
|
|
438
446
|
|
|
439
447
|
def test_fail_install_from_nonexistant_remote_rubygem
|
|
440
|
-
install_result = run_inspec_process_with_this_plugin(
|
|
448
|
+
install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture-nonesuch")
|
|
441
449
|
|
|
442
450
|
assert_empty install_result.stderr
|
|
443
|
-
assert_equal 1, install_result.exit_status,
|
|
451
|
+
assert_equal 1, install_result.exit_status, "Exit status should be 1"
|
|
444
452
|
assert_match(/No such plugin gem .+ could be found on rubygems.org - installation failed./, install_result.stdout)
|
|
445
453
|
end
|
|
446
454
|
|
|
447
455
|
def test_install_from_rubygems_with_pinned_version
|
|
448
|
-
install_result = run_inspec_process_with_this_plugin(
|
|
456
|
+
install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture -v 0.1.0", post_run: list_after_run)
|
|
449
457
|
|
|
450
458
|
assert_empty install_result.stderr
|
|
451
|
-
assert_equal 0, install_result.exit_status,
|
|
459
|
+
assert_equal 0, install_result.exit_status, "Exit status should be 0"
|
|
452
460
|
|
|
453
461
|
success_message = install_result.stdout.split("\n").grep(/installed/).last
|
|
454
|
-
refute_nil success_message,
|
|
455
|
-
assert_includes success_message,
|
|
456
|
-
assert_includes success_message,
|
|
457
|
-
assert_includes success_message,
|
|
462
|
+
refute_nil success_message, "Should find a success message at the end"
|
|
463
|
+
assert_includes success_message, "inspec-test-fixture"
|
|
464
|
+
assert_includes success_message, "0.1.0"
|
|
465
|
+
assert_includes success_message, "installed from rubygems.org"
|
|
458
466
|
|
|
459
467
|
list_result = install_result.payload.list_result
|
|
460
468
|
itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
|
461
|
-
refute_nil itf_line,
|
|
462
|
-
assert_match(/\s*inspec-test-fixture\s+0.1.0\s+gem\s+/, itf_line,
|
|
469
|
+
refute_nil itf_line, "inspec-test-fixture should now appear in the output of inspec list"
|
|
470
|
+
assert_match(/\s*inspec-test-fixture\s+0.1.0\s+gem\s+/, itf_line, "list output should show that it is a gem installation with version")
|
|
463
471
|
end
|
|
464
472
|
|
|
465
473
|
def test_fail_install_from_nonexistant_rubygem_version
|
|
466
|
-
install_result = run_inspec_process_with_this_plugin(
|
|
474
|
+
install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture -v 99.99.99")
|
|
467
475
|
|
|
468
476
|
assert_empty install_result.stderr
|
|
469
|
-
assert_equal 1, install_result.exit_status,
|
|
477
|
+
assert_equal 1, install_result.exit_status, "Exit status should be 1"
|
|
470
478
|
|
|
471
479
|
fail_message = install_result.stdout.split("\n").grep(/failed/).last
|
|
472
|
-
refute_nil fail_message,
|
|
473
|
-
assert_includes fail_message,
|
|
474
|
-
assert_includes fail_message,
|
|
475
|
-
assert_includes fail_message,
|
|
476
|
-
assert_includes fail_message,
|
|
480
|
+
refute_nil fail_message, "Should find a failure message at the end"
|
|
481
|
+
assert_includes fail_message, "inspec-test-fixture"
|
|
482
|
+
assert_includes fail_message, "99.99.99"
|
|
483
|
+
assert_includes fail_message, "no such version"
|
|
484
|
+
assert_includes fail_message, "on rubygems.org"
|
|
477
485
|
end
|
|
478
486
|
|
|
479
487
|
def test_refuse_install_when_missing_prefix
|
|
480
|
-
install_result = run_inspec_process_with_this_plugin(
|
|
488
|
+
install_result = run_inspec_process_with_this_plugin("plugin install test-fixture")
|
|
481
489
|
|
|
482
490
|
assert_empty install_result.stderr
|
|
483
|
-
assert_equal 1, install_result.exit_status,
|
|
491
|
+
assert_equal 1, install_result.exit_status, "Exit status should be 1"
|
|
484
492
|
|
|
485
493
|
fail_message = install_result.stdout.split("\n").grep(/failed/).last
|
|
486
|
-
refute_nil fail_message,
|
|
487
|
-
assert_includes fail_message,
|
|
494
|
+
refute_nil fail_message, "Should find a failure message at the end"
|
|
495
|
+
assert_includes fail_message, "test-fixture"
|
|
488
496
|
assert_includes fail_message, "All inspec plugins must begin with either 'inspec-' or 'train-'"
|
|
489
497
|
end
|
|
490
498
|
|
|
491
499
|
def test_refuse_install_when_already_installed_same_version
|
|
492
500
|
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
|
493
501
|
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
|
494
|
-
copy_in_core_config_dir(
|
|
502
|
+
copy_in_core_config_dir("test-fixture-2-float", tmp_dir)
|
|
495
503
|
end
|
|
496
504
|
|
|
497
|
-
install_result = run_inspec_process_with_this_plugin(
|
|
505
|
+
install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture", pre_run: pre_block)
|
|
498
506
|
assert_empty install_result.stderr
|
|
499
|
-
assert_equal 2, install_result.exit_status,
|
|
507
|
+
assert_equal 2, install_result.exit_status, "Exit status should be 2"
|
|
500
508
|
|
|
501
509
|
refusal_message = install_result.stdout.split("\n").grep(/refusing/).last
|
|
502
|
-
refute_nil refusal_message,
|
|
503
|
-
assert_includes refusal_message,
|
|
504
|
-
assert_includes refusal_message,
|
|
505
|
-
assert_includes refusal_message,
|
|
510
|
+
refute_nil refusal_message, "Should find a failure message at the end"
|
|
511
|
+
assert_includes refusal_message, "inspec-test-fixture"
|
|
512
|
+
assert_includes refusal_message, "0.2.0"
|
|
513
|
+
assert_includes refusal_message, "Plugin already installed at latest version"
|
|
506
514
|
end
|
|
507
515
|
|
|
508
516
|
def test_refuse_install_when_already_installed_can_update
|
|
509
517
|
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
|
510
518
|
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
|
511
|
-
copy_in_core_config_dir(
|
|
519
|
+
copy_in_core_config_dir("test-fixture-1-float", tmp_dir)
|
|
512
520
|
end
|
|
513
521
|
|
|
514
|
-
install_result = run_inspec_process_with_this_plugin(
|
|
522
|
+
install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture", pre_run: pre_block)
|
|
515
523
|
assert_empty install_result.stderr
|
|
516
|
-
assert_equal 2, install_result.exit_status,
|
|
524
|
+
assert_equal 2, install_result.exit_status, "Exit status should be 2"
|
|
517
525
|
|
|
518
526
|
refusal_message = install_result.stdout.split("\n").grep(/refusing/).last
|
|
519
|
-
refute_nil refusal_message,
|
|
520
|
-
assert_includes refusal_message,
|
|
521
|
-
assert_includes refusal_message,
|
|
522
|
-
assert_includes refusal_message,
|
|
523
|
-
assert_includes refusal_message,
|
|
524
|
-
assert_includes refusal_message,
|
|
527
|
+
refute_nil refusal_message, "Should find a failure message at the end"
|
|
528
|
+
assert_includes refusal_message, "inspec-test-fixture"
|
|
529
|
+
assert_includes refusal_message, "0.1.0"
|
|
530
|
+
assert_includes refusal_message, "0.2.0"
|
|
531
|
+
assert_includes refusal_message, "Update required"
|
|
532
|
+
assert_includes refusal_message, "inspec plugin update"
|
|
525
533
|
end
|
|
526
534
|
|
|
527
535
|
def test_install_from_rubygems_latest_with_train_plugin
|
|
528
|
-
install_result = run_inspec_process_with_this_plugin(
|
|
536
|
+
install_result = run_inspec_process_with_this_plugin("plugin install train-test-fixture", post_run: list_after_run)
|
|
529
537
|
|
|
530
538
|
assert_empty install_result.stderr
|
|
531
|
-
assert_equal 0, install_result.exit_status,
|
|
539
|
+
assert_equal 0, install_result.exit_status, "Exit status should be 0"
|
|
532
540
|
|
|
533
541
|
success_message = install_result.stdout.split("\n").grep(/installed/).last
|
|
534
|
-
refute_nil success_message,
|
|
535
|
-
assert_includes success_message,
|
|
536
|
-
assert_includes success_message,
|
|
537
|
-
assert_includes success_message,
|
|
542
|
+
refute_nil success_message, "Should find a success message at the end"
|
|
543
|
+
assert_includes success_message, "train-test-fixture"
|
|
544
|
+
assert_includes success_message, "0.1.0"
|
|
545
|
+
assert_includes success_message, "installed from rubygems.org"
|
|
538
546
|
|
|
539
547
|
list_result = install_result.payload.list_result
|
|
540
548
|
itf_line = list_result.stdout.split("\n").grep(/train-test-fixture/).first
|
|
541
|
-
refute_nil itf_line,
|
|
542
|
-
assert_match(/\s*train-test-fixture\s+0.1.0\s+gem\s+/, itf_line,
|
|
549
|
+
refute_nil itf_line, "train-test-fixture should now appear in the output of inspec list"
|
|
550
|
+
assert_match(/\s*train-test-fixture\s+0.1.0\s+gem\s+/, itf_line, "list output should show that it is a gem installation with version")
|
|
543
551
|
end
|
|
544
552
|
|
|
545
553
|
def test_refuse_install_when_plugin_on_exclusion_list
|
|
546
|
-
|
|
547
554
|
# Here, 'inspec-core', 'inspec-multi-server', and 'train-tax-collector'
|
|
548
555
|
# are the names of real rubygems. They are not InSpec/Train plugins, though,
|
|
549
556
|
# and installing them would be a jam-up.
|
|
550
557
|
# This is configured in 'etc/plugin-filter.json'.
|
|
551
558
|
[
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
559
|
+
"inspec-core",
|
|
560
|
+
"inspec-multi-server",
|
|
561
|
+
"train-tax-calculator",
|
|
555
562
|
].each do |plugin_name|
|
|
556
563
|
install_result = run_inspec_process_with_this_plugin("plugin install #{plugin_name}")
|
|
557
564
|
assert_empty install_result.stderr
|
|
558
|
-
assert_equal 2, install_result.exit_status,
|
|
565
|
+
assert_equal 2, install_result.exit_status, "Exit status should be 2"
|
|
559
566
|
|
|
560
567
|
refusal_message = install_result.stdout
|
|
561
|
-
refute_nil refusal_message,
|
|
568
|
+
refute_nil refusal_message, "Should find a failure message at the end"
|
|
562
569
|
assert_includes refusal_message, plugin_name
|
|
563
|
-
assert_includes refusal_message,
|
|
564
|
-
assert_includes refusal_message,
|
|
565
|
-
assert_includes refusal_message,
|
|
566
|
-
assert_includes refusal_message,
|
|
567
|
-
assert_includes refusal_message,
|
|
570
|
+
assert_includes refusal_message, "Plugin on Exclusion List"
|
|
571
|
+
assert_includes refusal_message, "refusing to install"
|
|
572
|
+
assert_includes refusal_message, "Rationale:"
|
|
573
|
+
assert_includes refusal_message, "etc/plugin_filters.json"
|
|
574
|
+
assert_includes refusal_message, "github.com/inspec/inspec/issues/new"
|
|
568
575
|
end
|
|
569
576
|
end
|
|
570
577
|
|
|
571
578
|
def test_error_install_with_debug_enabled
|
|
572
|
-
|
|
579
|
+
skip "this test requires bundler to pass" unless defined? ::Bundler
|
|
580
|
+
|
|
581
|
+
install_result = run_inspec_process_with_this_plugin("plugin install inspec-test-fixture -v 0.1.1 --log-level debug")
|
|
573
582
|
|
|
574
|
-
assert_equal 1, install_result.exit_status,
|
|
575
|
-
assert_includes install_result.stdout,
|
|
583
|
+
assert_equal 1, install_result.exit_status, "Exit status should be 1"
|
|
584
|
+
assert_includes install_result.stdout, "DEBUG"
|
|
576
585
|
assert_includes install_result.stderr, "can't activate rake"
|
|
577
586
|
end
|
|
578
587
|
end
|
|
579
588
|
|
|
580
|
-
|
|
581
589
|
#-----------------------------------------------------------------------------------------#
|
|
582
590
|
# inspec plugin update
|
|
583
591
|
#-----------------------------------------------------------------------------------------#
|
|
584
|
-
class PluginManagerCliUpdate <
|
|
592
|
+
class PluginManagerCliUpdate < Minitest::Test
|
|
585
593
|
include CorePluginFunctionalHelper
|
|
586
594
|
include PluginManagerHelpers
|
|
587
595
|
|
|
588
596
|
def test_when_a_plugin_can_be_updated
|
|
597
|
+
skip "this test requires bundler to pass" unless defined? ::Bundler
|
|
598
|
+
|
|
589
599
|
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
|
590
600
|
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
|
591
|
-
copy_in_core_config_dir(
|
|
601
|
+
copy_in_core_config_dir("test-fixture-1-float", tmp_dir)
|
|
592
602
|
end
|
|
593
603
|
|
|
594
|
-
update_result = run_inspec_process_with_this_plugin(
|
|
604
|
+
update_result = run_inspec_process_with_this_plugin("plugin update inspec-test-fixture", pre_run: pre_block, post_run: list_after_run)
|
|
595
605
|
assert_empty update_result.stderr
|
|
596
|
-
assert_equal 0, update_result.exit_status,
|
|
606
|
+
assert_equal 0, update_result.exit_status, "Exit status should be 0"
|
|
597
607
|
|
|
598
608
|
success_message = update_result.stdout.split("\n").grep(/updated/).last
|
|
599
|
-
refute_nil success_message,
|
|
600
|
-
assert_includes success_message,
|
|
601
|
-
assert_includes success_message,
|
|
602
|
-
assert_includes success_message,
|
|
603
|
-
assert_includes success_message,
|
|
609
|
+
refute_nil success_message, "Should find a success message at the end"
|
|
610
|
+
assert_includes success_message, "inspec-test-fixture"
|
|
611
|
+
assert_includes success_message, "0.1.0"
|
|
612
|
+
assert_includes success_message, "0.2.0"
|
|
613
|
+
assert_includes success_message, "updated from rubygems.org"
|
|
604
614
|
|
|
605
615
|
list_result = update_result.payload.list_result
|
|
606
616
|
itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
|
607
|
-
refute_nil itf_line,
|
|
608
|
-
assert_match(/\s*inspec-test-fixture\s+0.2.0\s+gem\s+/, itf_line,
|
|
617
|
+
refute_nil itf_line, "inspec-test-fixture should appear in the output of inspec list"
|
|
618
|
+
assert_match(/\s*inspec-test-fixture\s+0.2.0\s+gem\s+/, itf_line, "list output should show that it is a gem installation with version 0.2.0")
|
|
609
619
|
end
|
|
610
620
|
|
|
611
621
|
def test_refuse_update_when_already_current
|
|
612
622
|
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
|
613
623
|
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
|
614
|
-
copy_in_core_config_dir(
|
|
624
|
+
copy_in_core_config_dir("test-fixture-2-float", tmp_dir)
|
|
615
625
|
end
|
|
616
626
|
|
|
617
|
-
update_result = run_inspec_process_with_this_plugin(
|
|
627
|
+
update_result = run_inspec_process_with_this_plugin("plugin update inspec-test-fixture", pre_run: pre_block)
|
|
618
628
|
assert_empty update_result.stderr
|
|
619
|
-
assert_equal 2, update_result.exit_status,
|
|
629
|
+
assert_equal 2, update_result.exit_status, "Exit status should be 2"
|
|
620
630
|
|
|
621
631
|
refusal_message = update_result.stdout.split("\n").grep(/refusing/).last
|
|
622
|
-
refute_nil refusal_message,
|
|
623
|
-
assert_includes refusal_message,
|
|
624
|
-
assert_includes refusal_message,
|
|
625
|
-
assert_includes refusal_message,
|
|
632
|
+
refute_nil refusal_message, "Should find a failure message at the end"
|
|
633
|
+
assert_includes refusal_message, "inspec-test-fixture"
|
|
634
|
+
assert_includes refusal_message, "0.2.0"
|
|
635
|
+
assert_includes refusal_message, "Already installed at latest version"
|
|
626
636
|
end
|
|
627
637
|
|
|
628
638
|
def test_fail_update_from_nonexistant_gem
|
|
629
|
-
update_result = run_inspec_process_with_this_plugin(
|
|
639
|
+
update_result = run_inspec_process_with_this_plugin("plugin update inspec-test-fixture-nonesuch")
|
|
630
640
|
|
|
631
641
|
assert_empty update_result.stderr
|
|
632
|
-
assert_equal 1, update_result.exit_status,
|
|
642
|
+
assert_equal 1, update_result.exit_status, "Exit status should be 1"
|
|
633
643
|
assert_match(/No such plugin installed: .+ - update failed/, update_result.stdout)
|
|
634
644
|
end
|
|
635
645
|
|
|
636
646
|
def test_fail_update_path
|
|
637
647
|
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
|
638
648
|
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
|
639
|
-
copy_in_core_config_dir(
|
|
649
|
+
copy_in_core_config_dir("meaning_by_path", tmp_dir)
|
|
640
650
|
end
|
|
641
651
|
|
|
642
|
-
update_result = run_inspec_process_with_this_plugin(
|
|
652
|
+
update_result = run_inspec_process_with_this_plugin("plugin update inspec-meaning-of-life", pre_run: pre_block)
|
|
643
653
|
assert_empty update_result.stderr
|
|
644
|
-
assert_equal 2, update_result.exit_status,
|
|
654
|
+
assert_equal 2, update_result.exit_status, "Exit status should be 2"
|
|
645
655
|
|
|
646
656
|
refusal_message = update_result.stdout.split("\n").grep(/refusing/).last
|
|
647
|
-
refute_nil refusal_message,
|
|
648
|
-
assert_includes refusal_message,
|
|
649
|
-
assert_includes refusal_message,
|
|
650
|
-
assert_includes refusal_message,
|
|
657
|
+
refute_nil refusal_message, "Should find a failure message at the end"
|
|
658
|
+
assert_includes refusal_message, "inspec-meaning-of-life"
|
|
659
|
+
assert_includes refusal_message, "inspec plugin uninstall"
|
|
660
|
+
assert_includes refusal_message, "Cannot update path-based install"
|
|
651
661
|
end
|
|
652
662
|
end
|
|
653
663
|
|
|
654
664
|
#-----------------------------------------------------------------------------------------#
|
|
655
665
|
# inspec plugin uninstall
|
|
656
666
|
#-----------------------------------------------------------------------------------------#
|
|
657
|
-
class PluginManagerCliUninstall <
|
|
667
|
+
class PluginManagerCliUninstall < Minitest::Test
|
|
658
668
|
include CorePluginFunctionalHelper
|
|
659
669
|
include PluginManagerHelpers
|
|
660
670
|
|
|
661
671
|
def test_when_a_gem_plugin_can_be_uninstalled
|
|
662
672
|
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
|
663
673
|
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
|
664
|
-
copy_in_core_config_dir(
|
|
674
|
+
copy_in_core_config_dir("test-fixture-1-float", tmp_dir)
|
|
665
675
|
end
|
|
666
676
|
|
|
667
677
|
# Attempt uninstall
|
|
668
|
-
uninstall_result = run_inspec_process_with_this_plugin(
|
|
678
|
+
uninstall_result = run_inspec_process_with_this_plugin("plugin uninstall inspec-test-fixture", pre_run: pre_block, post_run: list_after_run)
|
|
669
679
|
assert_empty uninstall_result.stderr
|
|
670
|
-
assert_equal 0, uninstall_result.exit_status,
|
|
680
|
+
assert_equal 0, uninstall_result.exit_status, "Exit status should be 0"
|
|
671
681
|
|
|
672
682
|
success_message = uninstall_result.stdout.split("\n").grep(/uninstalled/).last
|
|
673
|
-
refute_nil success_message,
|
|
674
|
-
assert_includes success_message,
|
|
675
|
-
assert_includes success_message,
|
|
676
|
-
assert_includes success_message,
|
|
683
|
+
refute_nil success_message, "Should find a success message at the end"
|
|
684
|
+
assert_includes success_message, "inspec-test-fixture"
|
|
685
|
+
assert_includes success_message, "0.1.0"
|
|
686
|
+
assert_includes success_message, "has been uninstalled"
|
|
677
687
|
|
|
678
688
|
list_result = uninstall_result.payload.list_result
|
|
679
689
|
itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
|
680
|
-
assert_nil itf_line,
|
|
690
|
+
assert_nil itf_line, "inspec-test-fixture should not appear in the output of inspec list"
|
|
681
691
|
end
|
|
682
692
|
|
|
683
693
|
def test_when_a_path_plugin_can_be_uninstalled
|
|
684
694
|
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
|
685
695
|
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
|
686
696
|
# This fixture includes a path install for inspec-meaning-of-life
|
|
687
|
-
copy_in_core_config_dir(
|
|
697
|
+
copy_in_core_config_dir("test-fixture-1-float", tmp_dir)
|
|
688
698
|
end
|
|
689
699
|
|
|
690
|
-
uninstall_result = run_inspec_process_with_this_plugin(
|
|
700
|
+
uninstall_result = run_inspec_process_with_this_plugin("plugin uninstall inspec-meaning-of-life", pre_run: pre_block, post_run: list_after_run)
|
|
691
701
|
assert_empty uninstall_result.stderr
|
|
692
|
-
assert_equal 0, uninstall_result.exit_status,
|
|
702
|
+
assert_equal 0, uninstall_result.exit_status, "Exit status should be 0"
|
|
693
703
|
|
|
694
704
|
success_message = uninstall_result.stdout.split("\n").grep(/uninstalled/).last
|
|
695
|
-
refute_nil success_message,
|
|
696
|
-
assert_includes success_message,
|
|
697
|
-
assert_includes success_message,
|
|
698
|
-
assert_includes success_message,
|
|
705
|
+
refute_nil success_message, "Should find a success message at the end"
|
|
706
|
+
assert_includes success_message, "inspec-meaning-of-life"
|
|
707
|
+
assert_includes success_message, "path-based plugin install"
|
|
708
|
+
assert_includes success_message, "has been uninstalled"
|
|
699
709
|
|
|
700
710
|
list_result = uninstall_result.payload.list_result
|
|
701
711
|
itf_line = list_result.stdout.split("\n").grep(/inspec-meaning-of-life/).first
|
|
702
|
-
assert_nil itf_line,
|
|
712
|
+
assert_nil itf_line, "inspec-meaning-of-life should not appear in the output of inspec list"
|
|
703
713
|
end
|
|
704
714
|
|
|
705
715
|
def test_fail_uninstall_from_plugin_that_is_not_installed
|
|
706
|
-
uninstall_result = run_inspec_process_with_this_plugin(
|
|
716
|
+
uninstall_result = run_inspec_process_with_this_plugin("plugin uninstall inspec-test-fixture-nonesuch")
|
|
707
717
|
|
|
708
718
|
assert_empty uninstall_result.stderr
|
|
709
|
-
assert_equal 1, uninstall_result.exit_status,
|
|
710
|
-
refute_includes
|
|
719
|
+
assert_equal 1, uninstall_result.exit_status, "Exit status should be 1"
|
|
720
|
+
refute_includes "Inspec::Plugin::V2::UnInstallError", uninstall_result.stdout # Stacktrace marker
|
|
711
721
|
assert_match(/No such plugin installed: .+ - uninstall failed/, uninstall_result.stdout)
|
|
712
722
|
end
|
|
713
723
|
end
|