inspec-core 3.7.11 → 3.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/inspec/reporters/automate.rb +0 -4
- data/lib/inspec/reporters/json_automate.rb +7 -1
- data/lib/inspec/version.rb +1 -1
- metadata +2 -39
- data/lib/plugins/inspec-artifact/test/functional/inspec_artifact_test.rb +0 -46
- data/lib/plugins/inspec-compliance/test/functional/inspec_compliance_test.rb +0 -43
- data/lib/plugins/inspec-compliance/test/integration/default/cli.rb +0 -93
- data/lib/plugins/inspec-compliance/test/unit/api/login_test.rb +0 -190
- data/lib/plugins/inspec-compliance/test/unit/api_test.rb +0 -385
- data/lib/plugins/inspec-compliance/test/unit/target_test.rb +0 -155
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/Berksfile +0 -2
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/README.md +0 -3
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/files/hab_setup.exp +0 -28
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/metadata.rb +0 -9
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/recipes/default.rb +0 -61
- data/lib/plugins/inspec-habitat/test/functional/inspec_habitat_test.rb +0 -38
- data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/README.md +0 -3
- data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/controls/inspec_habitat.rb +0 -40
- data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/inspec.yml +0 -10
- data/lib/plugins/inspec-habitat/test/support/example_profile/README.md +0 -3
- data/lib/plugins/inspec-habitat/test/support/example_profile/controls/example.rb +0 -7
- data/lib/plugins/inspec-habitat/test/support/example_profile/inspec.yml +0 -10
- data/lib/plugins/inspec-habitat/test/unit/profile_test.rb +0 -240
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/fixtures/README.md +0 -24
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/README.md +0 -12
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/inspec_plugin_template_test.rb +0 -110
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/helper.rb +0 -26
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/README.md +0 -17
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/cli_args_test.rb +0 -67
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/plugin_def_test.rb +0 -51
- data/lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb +0 -173
- data/lib/plugins/inspec-init/test/functional/inspec_init_profile_test.rb +0 -100
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/config_dirs/empty/.gitkeep +0 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette.rb +0 -2
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette/.gitkeep +0 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-wrong-structure/.gitkeep +0 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name.rb +0 -1
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name/.gitkeep +0 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb +0 -713
- data/lib/plugins/inspec-plugin-manager-cli/test/unit/cli_args_test.rb +0 -75
- data/lib/plugins/inspec-plugin-manager-cli/test/unit/plugin_def_test.rb +0 -20
@@ -1,100 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'yaml'
|
4
|
-
require_relative '../../../shared/core_plugin_test_helper.rb'
|
5
|
-
|
6
|
-
class InitCli < MiniTest::Test
|
7
|
-
include CorePluginFunctionalHelper
|
8
|
-
|
9
|
-
def test_generating_inspec_profile
|
10
|
-
Dir.mktmpdir do |dir|
|
11
|
-
profile = File.join(dir, 'test-profile')
|
12
|
-
out = run_inspec_process("init profile test-profile", prefix: "cd #{dir} &&")
|
13
|
-
assert_equal 0, out.exit_status
|
14
|
-
assert_includes out.stdout, 'Creating new profile at'
|
15
|
-
assert_includes out.stdout, profile
|
16
|
-
assert_includes Dir.entries(profile).join, 'inspec.yml'
|
17
|
-
assert_includes Dir.entries(profile).join, 'README.md'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_generating_inspec_profile_with_explicit_platform
|
22
|
-
Dir.mktmpdir do |dir|
|
23
|
-
profile = File.join(dir, 'test-profile')
|
24
|
-
out = run_inspec_process("init profile --platform os test-profile", prefix: "cd #{dir} &&")
|
25
|
-
assert_equal 0, out.exit_status
|
26
|
-
assert_includes out.stdout, 'Creating new profile at'
|
27
|
-
assert_includes out.stdout, profile
|
28
|
-
assert_includes Dir.entries(profile).join, 'inspec.yml'
|
29
|
-
assert_includes Dir.entries(profile).join, 'README.md'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_generating_inspec_profile_with_bad_platform
|
34
|
-
Dir.mktmpdir do |dir|
|
35
|
-
out = run_inspec_process("init profile --platform nonesuch test-profile", prefix: "cd #{dir} &&")
|
36
|
-
assert_equal 1, out.exit_status
|
37
|
-
assert_includes out.stdout, 'Unable to generate profile'
|
38
|
-
assert_includes out.stdout, "No template available for platform 'nonesuch'"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_profile_with_slash_name
|
43
|
-
Dir.mktmpdir do |dir|
|
44
|
-
profile = dir + '/test/deeper/profile'
|
45
|
-
out = run_inspec_process("init profile test/deeper/profile", prefix: "cd #{dir} &&")
|
46
|
-
assert_equal 0, out.exit_status
|
47
|
-
assert_equal true, File.exist?(profile)
|
48
|
-
profile = YAML.load_file("#{profile}/inspec.yml")
|
49
|
-
assert_equal 'profile', profile['name']
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_generating_inspec_profile_gcp
|
54
|
-
Dir.mktmpdir do |dir|
|
55
|
-
profile = File.join(dir, 'test-gcp-profile')
|
56
|
-
out = run_inspec_process("init profile --platform gcp test-gcp-profile", prefix: "cd #{dir} &&")
|
57
|
-
assert_equal 0, out.exit_status
|
58
|
-
assert_includes out.stdout, 'Creating new profile at'
|
59
|
-
assert_includes out.stdout, profile
|
60
|
-
assert_includes Dir.entries(profile).join, 'inspec.yml'
|
61
|
-
assert_includes Dir.entries(profile).join, 'README.md'
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_generating_inspec_profile_aws
|
66
|
-
Dir.mktmpdir do |dir|
|
67
|
-
profile = File.join(dir, 'test-aws-profile')
|
68
|
-
out = run_inspec_process("init profile --platform aws test-aws-profile", prefix: "cd #{dir} &&")
|
69
|
-
assert_equal 0, out.exit_status
|
70
|
-
assert_includes out.stdout, 'Creating new profile at'
|
71
|
-
assert_includes out.stdout, profile
|
72
|
-
assert_includes Dir.entries(profile).join, 'inspec.yml'
|
73
|
-
assert_includes Dir.entries(profile).join, 'README.md'
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_generating_inspec_profile_azure
|
78
|
-
Dir.mktmpdir do |dir|
|
79
|
-
profile = File.join(dir, 'test-azure-profile')
|
80
|
-
out = run_inspec_process("init profile --platform azure test-azure-profile", prefix: "cd #{dir} &&")
|
81
|
-
assert_equal 0, out.exit_status
|
82
|
-
assert_includes out.stdout, 'Creating new profile at'
|
83
|
-
assert_includes out.stdout, profile
|
84
|
-
assert_includes Dir.entries(profile).join, 'inspec.yml'
|
85
|
-
assert_includes Dir.entries(profile).join, 'README.md'
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_generating_inspec_profile_os
|
90
|
-
Dir.mktmpdir do |dir|
|
91
|
-
profile = File.join(dir, 'test-os-profile')
|
92
|
-
out = run_inspec_process("init profile --platform os test-os-profile", prefix: "cd #{dir} &&")
|
93
|
-
assert_equal 0, out.exit_status
|
94
|
-
assert_includes out.stdout, 'Creating new profile at'
|
95
|
-
assert_includes out.stdout, profile
|
96
|
-
assert_includes Dir.entries(profile).join, 'inspec.yml'
|
97
|
-
assert_includes Dir.entries(profile).join, 'README.md'
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
File without changes
|
File without changes
|
data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-wrong-structure/.gitkeep
DELETED
File without changes
|
data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# This should should never even be loaded.
|
data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name/.gitkeep
DELETED
File without changes
|
@@ -1,713 +0,0 @@
|
|
1
|
-
#=========================================================================================#
|
2
|
-
# `inspec plugin SUBCOMMAND` facility
|
3
|
-
#=========================================================================================#
|
4
|
-
require_relative '../../../shared/core_plugin_test_helper.rb'
|
5
|
-
|
6
|
-
#-----------------------------------------------------------------------------------------#
|
7
|
-
# utilities
|
8
|
-
#-----------------------------------------------------------------------------------------#
|
9
|
-
module PluginManagerHelpers
|
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
|
-
|
15
|
-
let(:list_after_run) do
|
16
|
-
Proc.new do |run_result, tmp_dir|
|
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('plugin list', env: { INSPEC_CONFIG_DIR: tmp_dir })
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
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, 'empty')
|
25
|
-
src.each { |path| FileUtils.cp_r(path, dest) }
|
26
|
-
end
|
27
|
-
|
28
|
-
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, 'empty')
|
31
|
-
src.each { |path| FileUtils.cp_r(path, dest) }
|
32
|
-
end
|
33
|
-
|
34
|
-
def clear_empty_config_dir
|
35
|
-
Dir.glob(File.join(project_config_dirs_path, 'empty', '*')).each do |path|
|
36
|
-
next if path.end_with? '.gitkeep'
|
37
|
-
FileUtils.rm_rf(path)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def teardown
|
42
|
-
clear_empty_config_dir
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
#-----------------------------------------------------------------------------------------#
|
47
|
-
# inspec help
|
48
|
-
#-----------------------------------------------------------------------------------------#
|
49
|
-
class PluginManagerCliHelp < MiniTest::Test
|
50
|
-
include CorePluginFunctionalHelper
|
51
|
-
|
52
|
-
# Main inspec help subcommand listing
|
53
|
-
def test_inspec_help_includes_plugin
|
54
|
-
result = run_inspec_process_with_this_plugin('help')
|
55
|
-
assert_includes result.stdout, 'inspec plugin'
|
56
|
-
end
|
57
|
-
|
58
|
-
# inspec plugin help subcommand listing
|
59
|
-
def test_inspec_plugin_help_includes_plugin
|
60
|
-
result = run_inspec_process_with_this_plugin('plugin help')
|
61
|
-
assert_includes result.stdout, 'inspec plugin list'
|
62
|
-
assert_includes result.stdout, 'inspec plugin search'
|
63
|
-
assert_includes result.stdout, 'inspec plugin install'
|
64
|
-
assert_includes result.stdout, 'inspec plugin update'
|
65
|
-
assert_includes result.stdout, 'inspec plugin uninstall'
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
#-----------------------------------------------------------------------------------------#
|
70
|
-
# inspec plugin list
|
71
|
-
#-----------------------------------------------------------------------------------------#
|
72
|
-
class PluginManagerCliList < MiniTest::Test
|
73
|
-
include CorePluginFunctionalHelper
|
74
|
-
include PluginManagerHelpers
|
75
|
-
|
76
|
-
def test_list_when_no_user_plugins_installed
|
77
|
-
result = run_inspec_process_with_this_plugin('plugin list')
|
78
|
-
assert_equal 0, result.exit_status, 'exist status must be 0'
|
79
|
-
assert_includes result.stdout, '0 plugin(s) total', 'Empty list should include zero count'
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_list_all_when_no_user_plugins_installed
|
83
|
-
result = run_inspec_process_with_this_plugin('plugin list --all')
|
84
|
-
assert_equal 0, result.exit_status, 'exist status must be 0'
|
85
|
-
assert_includes result.stdout, '6 plugin(s) total', '--all list should find six'
|
86
|
-
assert_includes result.stdout, 'inspec-plugin-manager-cli', '--all list should find inspec-plugin-manager-cli'
|
87
|
-
assert_includes result.stdout, 'habitat', '--all list should find habitat'
|
88
|
-
|
89
|
-
result = run_inspec_process_with_this_plugin('plugin list -a')
|
90
|
-
assert_equal 0, result.exit_status, 'exist status must be 0'
|
91
|
-
assert_includes result.stdout, '6 plugin(s) total', '-a list should find six'
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_list_when_gem_and_path_plugins_installed
|
95
|
-
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
96
|
-
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
97
|
-
copy_in_core_config_dir('test-fixture-1-float', tmp_dir)
|
98
|
-
end
|
99
|
-
|
100
|
-
result = run_inspec_process_with_this_plugin('plugin list', pre_run: pre_block)
|
101
|
-
assert_equal 0, result.exit_status, 'exist status must be 0'
|
102
|
-
assert_includes result.stdout, '2 plugin(s) total', 'gem+path should show two plugins'
|
103
|
-
|
104
|
-
# Plugin Name Version Via ApiVer
|
105
|
-
# -------------------------------------------------------
|
106
|
-
# inspec-meaning-of-life src path 2
|
107
|
-
# inspec-test-fixture 0.1.0 gem 2
|
108
|
-
# -------------------------------------------------------
|
109
|
-
# 2 plugin(s) total
|
110
|
-
gem_line = result.stdout.split("\n").grep(/gem/).first
|
111
|
-
assert_match(/\s*inspec-\S+\s+\d+\.\d+\.\d+\s+gem\s+2/, gem_line)
|
112
|
-
path_line = result.stdout.split("\n").grep(/path/).first
|
113
|
-
assert_match(/\s*inspec-\S+\s+src\s+path\s+2/, path_line)
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_list_when_a_train_plugin_is_installed
|
117
|
-
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
118
|
-
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
119
|
-
copy_in_core_config_dir('train-test-fixture', tmp_dir)
|
120
|
-
end
|
121
|
-
|
122
|
-
result = run_inspec_process_with_this_plugin('plugin list', pre_run: pre_block)
|
123
|
-
assert_equal 0, result.exit_status, 'exist status must be 0'
|
124
|
-
assert_includes result.stdout, '1 plugin(s) total', 'list train should show one plugins'
|
125
|
-
|
126
|
-
# Plugin Name Version Via ApiVer
|
127
|
-
# -------------------------------------------------------
|
128
|
-
# train-test-fixture 0.1.0 gem train-1
|
129
|
-
# -------------------------------------------------------
|
130
|
-
# 1 plugin(s) total
|
131
|
-
train_line = result.stdout.split("\n").grep(/train/).first
|
132
|
-
assert_includes(train_line, 'train-test-fixture')
|
133
|
-
assert_includes(train_line, '0.1.0')
|
134
|
-
assert_includes(train_line, 'gem')
|
135
|
-
assert_includes(train_line, 'train-1')
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
#-----------------------------------------------------------------------------------------#
|
140
|
-
# inspec plugin search
|
141
|
-
#-----------------------------------------------------------------------------------------#
|
142
|
-
class PluginManagerCliSearch < MiniTest::Test
|
143
|
-
include CorePluginFunctionalHelper
|
144
|
-
include PluginManagerHelpers
|
145
|
-
|
146
|
-
# TODO: Thor can't hide options, but we wish it could.
|
147
|
-
# def test_search_include_fixture_hidden_option
|
148
|
-
# result = run_inspec_process_with_this_plugin('plugin help search')
|
149
|
-
# refute_includes result.stdout, '--include-test-fixture'
|
150
|
-
# end
|
151
|
-
|
152
|
-
def test_search_for_a_real_gem_with_full_name_no_options
|
153
|
-
result = run_inspec_process('plugin search --include-test-fixture inspec-test-fixture')
|
154
|
-
assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
|
155
|
-
assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the gem name'
|
156
|
-
assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'
|
157
|
-
line = result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
158
|
-
assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/,line,'Plugin line should include name and exactly one version')
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_search_for_a_real_gem_with_stub_name_no_options
|
162
|
-
result = run_inspec_process('plugin search --include-test-fixture inspec-test-')
|
163
|
-
assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
|
164
|
-
assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the gem name'
|
165
|
-
assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'
|
166
|
-
|
167
|
-
line = result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
168
|
-
assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/,line,'Plugin line should include name and exactly one version')
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_search_for_a_real_gem_with_full_name_and_exact_option
|
172
|
-
result = run_inspec_process('plugin search --exact --include-test-fixture inspec-test-fixture')
|
173
|
-
assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
|
174
|
-
assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the gem name'
|
175
|
-
assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'
|
176
|
-
|
177
|
-
result = run_inspec_process('plugin search -e --include-test-fixture inspec-test-fixture')
|
178
|
-
assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_search_for_a_real_gem_with_stub_name_and_exact_option
|
182
|
-
result = run_inspec_process('plugin search --exact --include-test-fixture inspec-test-')
|
183
|
-
assert_equal 2, result.exit_status, 'Search should exit 2 on a miss'
|
184
|
-
assert_includes result.stdout, '0 plugin(s) found', 'Search result should find 0 plugins'
|
185
|
-
|
186
|
-
result = run_inspec_process('plugin search -e --include-test-fixture inspec-test-')
|
187
|
-
assert_equal 2, result.exit_status, 'Search should exit 2 on a miss'
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_search_for_a_real_gem_with_full_name_and_all_option
|
191
|
-
result = run_inspec_process('plugin search --all --include-test-fixture inspec-test-fixture')
|
192
|
-
assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
|
193
|
-
assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the gem name'
|
194
|
-
assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'
|
195
|
-
|
196
|
-
line = result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
197
|
-
assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+(,\s)?){2,}\)/,line,'Plugin line should include name and at least two versions')
|
198
|
-
|
199
|
-
result = run_inspec_process('plugin search -a --include-test-fixture inspec-test-fixture')
|
200
|
-
assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_search_for_a_gem_with_missing_prefix
|
204
|
-
result = run_inspec_process('plugin search --include-test-fixture test-fixture')
|
205
|
-
assert_equal 1, result.exit_status, 'Search should exit 1 on user error'
|
206
|
-
assert_includes result.stdout, "All inspec plugins must begin with either 'inspec-' or 'train-'"
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_search_for_a_gem_that_does_not_exist
|
210
|
-
result = run_inspec_process('plugin search --include-test-fixture inspec-test-fixture-nonesuch')
|
211
|
-
assert_equal 2, result.exit_status, 'Search should exit 2 on a miss'
|
212
|
-
assert_includes result.stdout, '0 plugin(s) found', 'Search result should find 0 plugins'
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_search_for_a_real_gem_with_full_name_no_options_and_train_name
|
216
|
-
result = run_inspec_process('plugin search --include-test-fixture train-test-fixture')
|
217
|
-
assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
|
218
|
-
assert_includes result.stdout, 'train-test-fixture', 'Search result should contain the gem name'
|
219
|
-
assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'
|
220
|
-
line = result.stdout.split("\n").grep(/train-test-fixture/).first
|
221
|
-
assert_match(/\s*train-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/,line,'Plugin line should include name and exactly one version')
|
222
|
-
end
|
223
|
-
|
224
|
-
def test_search_omit_excluded_inspec_plugins
|
225
|
-
result = run_inspec_process('plugin search --include-test-fixture inspec-')
|
226
|
-
assert_equal 0, result.exit_status, 'Search should exit 0'
|
227
|
-
assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the test gem'
|
228
|
-
[
|
229
|
-
'inspec-core',
|
230
|
-
'inspec-multi-server',
|
231
|
-
].each do |plugin_name|
|
232
|
-
refute_includes result.stdout, plugin_name, 'Search result should not contain excluded gems'
|
233
|
-
end
|
234
|
-
end
|
235
|
-
def test_search_for_a_real_gem_with_full_name_no_options_filter_fixtures
|
236
|
-
result = run_inspec_process('plugin search inspec-test-fixture')
|
237
|
-
refute_includes result.stdout, 'inspec-test-fixture', 'Search result should not contain the fixture gem name'
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_search_for_a_real_gem_with_full_name_no_options_filter_fixtures_train
|
241
|
-
result = run_inspec_process('plugin search train-test-fixture')
|
242
|
-
refute_includes result.stdout, 'train-test-fixture', 'Search result should not contain the fixture gem name'
|
243
|
-
end
|
244
|
-
|
245
|
-
|
246
|
-
end
|
247
|
-
|
248
|
-
#-----------------------------------------------------------------------------------------#
|
249
|
-
# inspec plugin install
|
250
|
-
#-----------------------------------------------------------------------------------------#
|
251
|
-
class PluginManagerCliInstall < MiniTest::Test
|
252
|
-
include CorePluginFunctionalHelper # gives us instance methods, like `let` aliases inside test methods
|
253
|
-
extend CorePluginFunctionalHelper # gives us class methods, like `let` aliases out here outside test methods
|
254
|
-
|
255
|
-
include PluginManagerHelpers
|
256
|
-
ruby_abi_version = (Gem.ruby_version.segments[0, 2] << 0).join('.')
|
257
|
-
# Test multiple hueristics of the path-mode install.
|
258
|
-
# These are all positive tests; they should resolve the entry point to the same path in each case.
|
259
|
-
{
|
260
|
-
'is_perfect' => {
|
261
|
-
given: File.join(core_fixture_plugins_path, 'inspec-test-fixture', 'lib', 'inspec-test-fixture.rb'),
|
262
|
-
},
|
263
|
-
'refers_to_the_entry_point_with_no_extension' => {
|
264
|
-
given: File.join(core_fixture_plugins_path, 'inspec-test-fixture', 'lib', 'inspec-test-fixture'),
|
265
|
-
},
|
266
|
-
'refers_to_the_src_root_of_a_plugin' => {
|
267
|
-
given: File.join(core_fixture_plugins_path, 'inspec-test-fixture'),
|
268
|
-
},
|
269
|
-
'refers_to_a_versioned_gem_install' => {
|
270
|
-
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'),
|
271
|
-
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
|
-
},
|
273
|
-
'refers_to_a_versioned_gem_install_missing_extension' => {
|
274
|
-
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'),
|
275
|
-
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
|
-
},
|
277
|
-
'refers_to_a_relative_path' => {
|
278
|
-
given: File.join('test', 'unit', 'mock', 'plugins', 'inspec-test-fixture', 'lib', 'inspec-test-fixture.rb'),
|
279
|
-
},
|
280
|
-
'refers_to_a_train_plugin' => {
|
281
|
-
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'),
|
282
|
-
plugin_name: 'train-test-fixture',
|
283
|
-
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
|
-
},
|
285
|
-
}.each do |test_name, fixture_info|
|
286
|
-
define_method(('test_install_from_path_when_path_' + test_name).to_sym) do
|
287
|
-
fixture_info = {
|
288
|
-
plugin_name: 'inspec-test-fixture',
|
289
|
-
resolved_path: File.join(core_fixture_plugins_path, 'inspec-test-fixture', 'lib', 'inspec-test-fixture.rb')
|
290
|
-
}.merge(fixture_info)
|
291
|
-
|
292
|
-
install_result = run_inspec_process_with_this_plugin("plugin install #{fixture_info[:given]}", post_run: list_after_run)
|
293
|
-
|
294
|
-
assert_empty install_result.stderr
|
295
|
-
assert_equal 0, install_result.exit_status, 'Exit status should be 0'
|
296
|
-
|
297
|
-
# Check UX messaging
|
298
|
-
success_message = install_result.stdout.split("\n").grep(/installed/).last
|
299
|
-
refute_nil success_message, 'Should find a success message at the end'
|
300
|
-
assert_includes success_message, fixture_info[:plugin_name]
|
301
|
-
assert_includes success_message, 'plugin installed via source path reference'
|
302
|
-
|
303
|
-
# Check round-trip UX via list
|
304
|
-
list_result = install_result.payload.list_result
|
305
|
-
itf_line = list_result.stdout.split("\n").grep(Regexp.new(fixture_info[:plugin_name])).first
|
306
|
-
refute_nil itf_line, 'plugin name should now appear in the output of inspec list'
|
307
|
-
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
|
-
|
309
|
-
# Check plugin statefile. Extra important in this case, since all should resolve to the same entry point.
|
310
|
-
plugin_data = install_result.payload.plugin_data
|
311
|
-
entry = plugin_data['plugins'].detect { |e| e['name'] == fixture_info[:plugin_name] }
|
312
|
-
assert_equal fixture_info[:resolved_path], entry['installation_path'], 'Regardless of input, the entry point should be correct.'
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
def test_fail_install_from_nonexistant_path
|
317
|
-
bad_path = File.join(project_fixtures_path, 'none', 'such', 'inspec-test-fixture-nonesuch.rb')
|
318
|
-
install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
|
319
|
-
|
320
|
-
assert_empty install_result.stderr
|
321
|
-
assert_equal 1, install_result.exit_status, 'Exit status should be 1'
|
322
|
-
|
323
|
-
error_message = install_result.stdout.split("\n").last
|
324
|
-
assert_includes error_message, "No such source code path"
|
325
|
-
assert_includes error_message, 'inspec-test-fixture-nonesuch.rb'
|
326
|
-
assert_includes error_message, 'installation failed'
|
327
|
-
end
|
328
|
-
|
329
|
-
def test_fail_install_from_path_with_wrong_name
|
330
|
-
bad_path = File.join(project_fixtures_path, 'plugins', 'wrong-name', 'lib', 'wrong-name.rb')
|
331
|
-
install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
|
332
|
-
|
333
|
-
assert_empty install_result.stderr
|
334
|
-
assert_equal 1, install_result.exit_status, 'Exit status should be 1'
|
335
|
-
|
336
|
-
error_message = install_result.stdout.split("\n").last
|
337
|
-
assert_includes error_message, "Invalid plugin name"
|
338
|
-
assert_includes error_message, 'wrong-name'
|
339
|
-
assert_includes error_message, "All inspec plugins must begin with either 'inspec-' or 'train-'"
|
340
|
-
assert_includes error_message, 'installation failed'
|
341
|
-
end
|
342
|
-
|
343
|
-
def test_fail_install_from_path_when_it_is_not_a_plugin
|
344
|
-
bad_path = File.join(project_fixtures_path, 'plugins', 'inspec-egg-white-omelette', 'lib', 'inspec-egg-white-omelette.rb')
|
345
|
-
install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
|
346
|
-
|
347
|
-
assert_empty install_result.stderr
|
348
|
-
assert_equal 1, install_result.exit_status, 'Exit status should be 1'
|
349
|
-
|
350
|
-
error_message = install_result.stdout.split("\n").last
|
351
|
-
assert_includes error_message, "Does not appear to be a plugin"
|
352
|
-
assert_includes error_message, 'inspec-egg-white-omelette'
|
353
|
-
assert_includes error_message, "After probe-loading the supposed plugin, it did not register"
|
354
|
-
assert_includes error_message, "Ensure something inherits from 'Inspec.plugin(2)'"
|
355
|
-
assert_includes error_message, 'installation failed'
|
356
|
-
end
|
357
|
-
|
358
|
-
def test_fail_install_from_path_when_it_is_already_installed
|
359
|
-
plugin_path = File.join(core_fixture_plugins_path, 'inspec-test-fixture', 'lib', 'inspec-test-fixture.rb')
|
360
|
-
pre_block = Proc.new do |plugin_data, _tmp_dir|
|
361
|
-
plugin_data["plugins"] << {
|
362
|
-
"name" => "inspec-test-fixture",
|
363
|
-
"installation_type" => "path",
|
364
|
-
"installation_path" => plugin_path,
|
365
|
-
}
|
366
|
-
end
|
367
|
-
|
368
|
-
install_result = run_inspec_process_with_this_plugin("plugin install #{plugin_path}", pre_run: pre_block)
|
369
|
-
assert_empty install_result.stderr
|
370
|
-
assert_equal 2, install_result.exit_status, 'Exit status on second install should be 2'
|
371
|
-
|
372
|
-
error_message = install_result.stdout.split("\n").last
|
373
|
-
assert_includes error_message, "Plugin already installed"
|
374
|
-
assert_includes error_message, 'inspec-test-fixture'
|
375
|
-
assert_includes error_message, "Use 'inspec plugin list' to see previously installed plugin"
|
376
|
-
assert_includes error_message, 'installation failed'
|
377
|
-
end
|
378
|
-
|
379
|
-
def test_fail_install_from_path_when_the_dir_structure_is_wrong
|
380
|
-
bad_path = File.join(project_fixtures_path, 'plugins', 'inspec-wrong-structure')
|
381
|
-
install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
|
382
|
-
|
383
|
-
assert_empty install_result.stderr
|
384
|
-
assert_equal 1, install_result.exit_status, 'Exit status should be 1'
|
385
|
-
|
386
|
-
error_message = install_result.stdout.split("\n").last
|
387
|
-
assert_includes error_message, "Unrecognizable plugin structure"
|
388
|
-
assert_includes error_message, 'inspec-wrong-structure'
|
389
|
-
assert_includes error_message, ' When installing from a path, please provide the path of the entry point file'
|
390
|
-
assert_includes error_message, 'installation failed'
|
391
|
-
end
|
392
|
-
|
393
|
-
def test_install_from_gemfile
|
394
|
-
fixture_gemfile_path = File.join(core_fixture_plugins_path, 'inspec-test-fixture', 'pkg', 'inspec-test-fixture-0.1.0.gem')
|
395
|
-
install_result = run_inspec_process_with_this_plugin("plugin install #{fixture_gemfile_path}", post_run: list_after_run)
|
396
|
-
|
397
|
-
assert_empty install_result.stderr
|
398
|
-
assert_equal 0, install_result.exit_status, 'Exit status should be 0'
|
399
|
-
|
400
|
-
success_message = install_result.stdout.split("\n").grep(/installed/).last
|
401
|
-
refute_nil success_message, 'Should find a success message at the end'
|
402
|
-
assert_includes success_message, 'inspec-test-fixture'
|
403
|
-
assert_includes success_message, '0.1.0'
|
404
|
-
assert_includes success_message, 'installed from local .gem file'
|
405
|
-
|
406
|
-
list_result = install_result.payload.list_result
|
407
|
-
itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
408
|
-
refute_nil itf_line, 'inspec-test-fixture should now appear in the output of inspec list'
|
409
|
-
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
|
-
end
|
411
|
-
|
412
|
-
def test_fail_install_from_nonexistant_gemfile
|
413
|
-
bad_path = File.join(project_fixtures_path, 'none', 'such', 'inspec-test-fixture-nonesuch-0.3.0.gem')
|
414
|
-
install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")
|
415
|
-
|
416
|
-
assert_empty install_result.stderr
|
417
|
-
assert_equal 1, install_result.exit_status, 'Exit status should be 1'
|
418
|
-
assert_match(/No such plugin gem file .+ - installation failed./, install_result.stdout)
|
419
|
-
end
|
420
|
-
|
421
|
-
def test_install_from_rubygems_latest
|
422
|
-
install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture', post_run: list_after_run)
|
423
|
-
|
424
|
-
assert_empty install_result.stderr
|
425
|
-
assert_equal 0, install_result.exit_status, 'Exit status should be 0'
|
426
|
-
|
427
|
-
success_message = install_result.stdout.split("\n").grep(/installed/).last
|
428
|
-
refute_nil success_message, 'Should find a success message at the end'
|
429
|
-
assert_includes success_message, 'inspec-test-fixture'
|
430
|
-
assert_includes success_message, '0.2.0'
|
431
|
-
assert_includes success_message, 'installed from rubygems.org'
|
432
|
-
|
433
|
-
list_result = install_result.payload.list_result
|
434
|
-
itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
435
|
-
refute_nil itf_line, 'inspec-test-fixture should now appear in the output of inspec list'
|
436
|
-
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
|
-
end
|
438
|
-
|
439
|
-
def test_fail_install_from_nonexistant_remote_rubygem
|
440
|
-
install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture-nonesuch')
|
441
|
-
|
442
|
-
assert_empty install_result.stderr
|
443
|
-
assert_equal 1, install_result.exit_status, 'Exit status should be 1'
|
444
|
-
assert_match(/No such plugin gem .+ could be found on rubygems.org - installation failed./, install_result.stdout)
|
445
|
-
end
|
446
|
-
|
447
|
-
def test_install_from_rubygems_with_pinned_version
|
448
|
-
install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture -v 0.1.0', post_run: list_after_run)
|
449
|
-
|
450
|
-
assert_empty install_result.stderr
|
451
|
-
assert_equal 0, install_result.exit_status, 'Exit status should be 0'
|
452
|
-
|
453
|
-
success_message = install_result.stdout.split("\n").grep(/installed/).last
|
454
|
-
refute_nil success_message, 'Should find a success message at the end'
|
455
|
-
assert_includes success_message, 'inspec-test-fixture'
|
456
|
-
assert_includes success_message, '0.1.0'
|
457
|
-
assert_includes success_message, 'installed from rubygems.org'
|
458
|
-
|
459
|
-
list_result = install_result.payload.list_result
|
460
|
-
itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
461
|
-
refute_nil itf_line, 'inspec-test-fixture should now appear in the output of inspec list'
|
462
|
-
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
|
-
end
|
464
|
-
|
465
|
-
def test_fail_install_from_nonexistant_rubygem_version
|
466
|
-
install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture -v 99.99.99')
|
467
|
-
|
468
|
-
assert_empty install_result.stderr
|
469
|
-
assert_equal 1, install_result.exit_status, 'Exit status should be 1'
|
470
|
-
|
471
|
-
fail_message = install_result.stdout.split("\n").grep(/failed/).last
|
472
|
-
refute_nil fail_message, 'Should find a failure message at the end'
|
473
|
-
assert_includes fail_message, 'inspec-test-fixture'
|
474
|
-
assert_includes fail_message, '99.99.99'
|
475
|
-
assert_includes fail_message, 'no such version'
|
476
|
-
assert_includes fail_message, 'on rubygems.org'
|
477
|
-
end
|
478
|
-
|
479
|
-
def test_refuse_install_when_missing_prefix
|
480
|
-
install_result = run_inspec_process_with_this_plugin('plugin install test-fixture')
|
481
|
-
|
482
|
-
assert_empty install_result.stderr
|
483
|
-
assert_equal 1, install_result.exit_status, 'Exit status should be 1'
|
484
|
-
|
485
|
-
fail_message = install_result.stdout.split("\n").grep(/failed/).last
|
486
|
-
refute_nil fail_message, 'Should find a failure message at the end'
|
487
|
-
assert_includes fail_message, 'test-fixture'
|
488
|
-
assert_includes fail_message, "All inspec plugins must begin with either 'inspec-' or 'train-'"
|
489
|
-
end
|
490
|
-
|
491
|
-
def test_refuse_install_when_already_installed_same_version
|
492
|
-
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
493
|
-
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
494
|
-
copy_in_core_config_dir('test-fixture-2-float', tmp_dir)
|
495
|
-
end
|
496
|
-
|
497
|
-
install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture', pre_run: pre_block)
|
498
|
-
assert_empty install_result.stderr
|
499
|
-
assert_equal 2, install_result.exit_status, 'Exit status should be 2'
|
500
|
-
|
501
|
-
refusal_message = install_result.stdout.split("\n").grep(/refusing/).last
|
502
|
-
refute_nil refusal_message, 'Should find a failure message at the end'
|
503
|
-
assert_includes refusal_message, 'inspec-test-fixture'
|
504
|
-
assert_includes refusal_message, '0.2.0'
|
505
|
-
assert_includes refusal_message, 'Plugin already installed at latest version'
|
506
|
-
end
|
507
|
-
|
508
|
-
def test_refuse_install_when_already_installed_can_update
|
509
|
-
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
510
|
-
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
511
|
-
copy_in_core_config_dir('test-fixture-1-float', tmp_dir)
|
512
|
-
end
|
513
|
-
|
514
|
-
install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture', pre_run: pre_block)
|
515
|
-
assert_empty install_result.stderr
|
516
|
-
assert_equal 2, install_result.exit_status, 'Exit status should be 2'
|
517
|
-
|
518
|
-
refusal_message = install_result.stdout.split("\n").grep(/refusing/).last
|
519
|
-
refute_nil refusal_message, 'Should find a failure message at the end'
|
520
|
-
assert_includes refusal_message, 'inspec-test-fixture'
|
521
|
-
assert_includes refusal_message, '0.1.0'
|
522
|
-
assert_includes refusal_message, '0.2.0'
|
523
|
-
assert_includes refusal_message, 'Update required'
|
524
|
-
assert_includes refusal_message, 'inspec plugin update'
|
525
|
-
end
|
526
|
-
|
527
|
-
def test_install_from_rubygems_latest_with_train_plugin
|
528
|
-
install_result = run_inspec_process_with_this_plugin('plugin install train-test-fixture', post_run: list_after_run)
|
529
|
-
|
530
|
-
assert_empty install_result.stderr
|
531
|
-
assert_equal 0, install_result.exit_status, 'Exit status should be 0'
|
532
|
-
|
533
|
-
success_message = install_result.stdout.split("\n").grep(/installed/).last
|
534
|
-
refute_nil success_message, 'Should find a success message at the end'
|
535
|
-
assert_includes success_message, 'train-test-fixture'
|
536
|
-
assert_includes success_message, '0.1.0'
|
537
|
-
assert_includes success_message, 'installed from rubygems.org'
|
538
|
-
|
539
|
-
list_result = install_result.payload.list_result
|
540
|
-
itf_line = list_result.stdout.split("\n").grep(/train-test-fixture/).first
|
541
|
-
refute_nil itf_line, 'train-test-fixture should now appear in the output of inspec list'
|
542
|
-
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
|
-
end
|
544
|
-
|
545
|
-
def test_refuse_install_when_plugin_on_exclusion_list
|
546
|
-
|
547
|
-
# Here, 'inspec-core', 'inspec-multi-server', and 'train-tax-collector'
|
548
|
-
# are the names of real rubygems. They are not InSpec/Train plugins, though,
|
549
|
-
# and installing them would be a jam-up.
|
550
|
-
# This is configured in 'etc/plugin-filter.json'.
|
551
|
-
[
|
552
|
-
'inspec-core',
|
553
|
-
'inspec-multi-server',
|
554
|
-
'train-tax-calculator',
|
555
|
-
].each do |plugin_name|
|
556
|
-
install_result = run_inspec_process_with_this_plugin("plugin install #{plugin_name}")
|
557
|
-
assert_empty install_result.stderr
|
558
|
-
assert_equal 2, install_result.exit_status, 'Exit status should be 2'
|
559
|
-
|
560
|
-
refusal_message = install_result.stdout
|
561
|
-
refute_nil refusal_message, 'Should find a failure message at the end'
|
562
|
-
assert_includes refusal_message, plugin_name
|
563
|
-
assert_includes refusal_message, 'Plugin on Exclusion List'
|
564
|
-
assert_includes refusal_message, 'refusing to install'
|
565
|
-
assert_includes refusal_message, 'Rationale:'
|
566
|
-
assert_includes refusal_message, 'etc/plugin_filters.json'
|
567
|
-
assert_includes refusal_message, 'github.com/inspec/inspec/issues/new'
|
568
|
-
end
|
569
|
-
end
|
570
|
-
|
571
|
-
def test_error_install_with_debug_enabled
|
572
|
-
install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture -v 0.1.1 --log-level debug')
|
573
|
-
|
574
|
-
assert_equal 1, install_result.exit_status, 'Exit status should be 1'
|
575
|
-
assert_includes install_result.stdout, 'DEBUG'
|
576
|
-
assert_includes install_result.stderr, "can't activate rake"
|
577
|
-
end
|
578
|
-
end
|
579
|
-
|
580
|
-
|
581
|
-
#-----------------------------------------------------------------------------------------#
|
582
|
-
# inspec plugin update
|
583
|
-
#-----------------------------------------------------------------------------------------#
|
584
|
-
class PluginManagerCliUpdate < MiniTest::Test
|
585
|
-
include CorePluginFunctionalHelper
|
586
|
-
include PluginManagerHelpers
|
587
|
-
|
588
|
-
def test_when_a_plugin_can_be_updated
|
589
|
-
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
590
|
-
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
591
|
-
copy_in_core_config_dir('test-fixture-1-float', tmp_dir)
|
592
|
-
end
|
593
|
-
|
594
|
-
update_result = run_inspec_process_with_this_plugin('plugin update inspec-test-fixture', pre_run: pre_block, post_run: list_after_run)
|
595
|
-
assert_empty update_result.stderr
|
596
|
-
assert_equal 0, update_result.exit_status, 'Exit status should be 0'
|
597
|
-
|
598
|
-
success_message = update_result.stdout.split("\n").grep(/updated/).last
|
599
|
-
refute_nil success_message, 'Should find a success message at the end'
|
600
|
-
assert_includes success_message, 'inspec-test-fixture'
|
601
|
-
assert_includes success_message, '0.1.0'
|
602
|
-
assert_includes success_message, '0.2.0'
|
603
|
-
assert_includes success_message, 'updated from rubygems.org'
|
604
|
-
|
605
|
-
list_result = update_result.payload.list_result
|
606
|
-
itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
607
|
-
refute_nil itf_line, 'inspec-test-fixture should appear in the output of inspec list'
|
608
|
-
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
|
-
end
|
610
|
-
|
611
|
-
def test_refuse_update_when_already_current
|
612
|
-
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
613
|
-
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
614
|
-
copy_in_core_config_dir('test-fixture-2-float', tmp_dir)
|
615
|
-
end
|
616
|
-
|
617
|
-
update_result = run_inspec_process_with_this_plugin('plugin update inspec-test-fixture', pre_run: pre_block)
|
618
|
-
assert_empty update_result.stderr
|
619
|
-
assert_equal 2, update_result.exit_status, 'Exit status should be 2'
|
620
|
-
|
621
|
-
refusal_message = update_result.stdout.split("\n").grep(/refusing/).last
|
622
|
-
refute_nil refusal_message, 'Should find a failure message at the end'
|
623
|
-
assert_includes refusal_message, 'inspec-test-fixture'
|
624
|
-
assert_includes refusal_message, '0.2.0'
|
625
|
-
assert_includes refusal_message, 'Already installed at latest version'
|
626
|
-
end
|
627
|
-
|
628
|
-
def test_fail_update_from_nonexistant_gem
|
629
|
-
update_result = run_inspec_process_with_this_plugin('plugin update inspec-test-fixture-nonesuch')
|
630
|
-
|
631
|
-
assert_empty update_result.stderr
|
632
|
-
assert_equal 1, update_result.exit_status, 'Exit status should be 1'
|
633
|
-
assert_match(/No such plugin installed: .+ - update failed/, update_result.stdout)
|
634
|
-
end
|
635
|
-
|
636
|
-
def test_fail_update_path
|
637
|
-
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
638
|
-
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
639
|
-
copy_in_core_config_dir('meaning_by_path', tmp_dir)
|
640
|
-
end
|
641
|
-
|
642
|
-
update_result = run_inspec_process_with_this_plugin('plugin update inspec-meaning-of-life', pre_run: pre_block)
|
643
|
-
assert_empty update_result.stderr
|
644
|
-
assert_equal 2, update_result.exit_status, 'Exit status should be 2'
|
645
|
-
|
646
|
-
refusal_message = update_result.stdout.split("\n").grep(/refusing/).last
|
647
|
-
refute_nil refusal_message, 'Should find a failure message at the end'
|
648
|
-
assert_includes refusal_message, 'inspec-meaning-of-life'
|
649
|
-
assert_includes refusal_message, 'inspec plugin uninstall'
|
650
|
-
assert_includes refusal_message, 'Cannot update path-based install'
|
651
|
-
end
|
652
|
-
end
|
653
|
-
|
654
|
-
#-----------------------------------------------------------------------------------------#
|
655
|
-
# inspec plugin uninstall
|
656
|
-
#-----------------------------------------------------------------------------------------#
|
657
|
-
class PluginManagerCliUninstall < MiniTest::Test
|
658
|
-
include CorePluginFunctionalHelper
|
659
|
-
include PluginManagerHelpers
|
660
|
-
|
661
|
-
def test_when_a_gem_plugin_can_be_uninstalled
|
662
|
-
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
663
|
-
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
664
|
-
copy_in_core_config_dir('test-fixture-1-float', tmp_dir)
|
665
|
-
end
|
666
|
-
|
667
|
-
# Attempt uninstall
|
668
|
-
uninstall_result = run_inspec_process_with_this_plugin('plugin uninstall inspec-test-fixture', pre_run: pre_block, post_run: list_after_run)
|
669
|
-
assert_empty uninstall_result.stderr
|
670
|
-
assert_equal 0, uninstall_result.exit_status, 'Exit status should be 0'
|
671
|
-
|
672
|
-
success_message = uninstall_result.stdout.split("\n").grep(/uninstalled/).last
|
673
|
-
refute_nil success_message, 'Should find a success message at the end'
|
674
|
-
assert_includes success_message, 'inspec-test-fixture'
|
675
|
-
assert_includes success_message, '0.1.0'
|
676
|
-
assert_includes success_message, 'has been uninstalled'
|
677
|
-
|
678
|
-
list_result = uninstall_result.payload.list_result
|
679
|
-
itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first
|
680
|
-
assert_nil itf_line, 'inspec-test-fixture should not appear in the output of inspec list'
|
681
|
-
end
|
682
|
-
|
683
|
-
def test_when_a_path_plugin_can_be_uninstalled
|
684
|
-
pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
|
685
|
-
plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
|
686
|
-
# This fixture includes a path install for inspec-meaning-of-life
|
687
|
-
copy_in_core_config_dir('test-fixture-1-float', tmp_dir)
|
688
|
-
end
|
689
|
-
|
690
|
-
uninstall_result = run_inspec_process_with_this_plugin('plugin uninstall inspec-meaning-of-life', pre_run: pre_block, post_run: list_after_run)
|
691
|
-
assert_empty uninstall_result.stderr
|
692
|
-
assert_equal 0, uninstall_result.exit_status, 'Exit status should be 0'
|
693
|
-
|
694
|
-
success_message = uninstall_result.stdout.split("\n").grep(/uninstalled/).last
|
695
|
-
refute_nil success_message, 'Should find a success message at the end'
|
696
|
-
assert_includes success_message, 'inspec-meaning-of-life'
|
697
|
-
assert_includes success_message, 'path-based plugin install'
|
698
|
-
assert_includes success_message, 'has been uninstalled'
|
699
|
-
|
700
|
-
list_result = uninstall_result.payload.list_result
|
701
|
-
itf_line = list_result.stdout.split("\n").grep(/inspec-meaning-of-life/).first
|
702
|
-
assert_nil itf_line, 'inspec-meaning-of-life should not appear in the output of inspec list'
|
703
|
-
end
|
704
|
-
|
705
|
-
def test_fail_uninstall_from_plugin_that_is_not_installed
|
706
|
-
uninstall_result = run_inspec_process_with_this_plugin('plugin uninstall inspec-test-fixture-nonesuch')
|
707
|
-
|
708
|
-
assert_empty uninstall_result.stderr
|
709
|
-
assert_equal 1, uninstall_result.exit_status, 'Exit status should be 1'
|
710
|
-
refute_includes 'Inspec::Plugin::V2::UnInstallError', uninstall_result.stdout # Stacktrace marker
|
711
|
-
assert_match(/No such plugin installed: .+ - uninstall failed/, uninstall_result.stdout)
|
712
|
-
end
|
713
|
-
end
|