inspec-core 3.7.11 → 3.9.0

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/lib/inspec/reporters/automate.rb +0 -4
  4. data/lib/inspec/reporters/json_automate.rb +7 -1
  5. data/lib/inspec/version.rb +1 -1
  6. metadata +2 -39
  7. data/lib/plugins/inspec-artifact/test/functional/inspec_artifact_test.rb +0 -46
  8. data/lib/plugins/inspec-compliance/test/functional/inspec_compliance_test.rb +0 -43
  9. data/lib/plugins/inspec-compliance/test/integration/default/cli.rb +0 -93
  10. data/lib/plugins/inspec-compliance/test/unit/api/login_test.rb +0 -190
  11. data/lib/plugins/inspec-compliance/test/unit/api_test.rb +0 -385
  12. data/lib/plugins/inspec-compliance/test/unit/target_test.rb +0 -155
  13. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/Berksfile +0 -2
  14. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/README.md +0 -3
  15. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/files/hab_setup.exp +0 -28
  16. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/metadata.rb +0 -9
  17. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/recipes/default.rb +0 -61
  18. data/lib/plugins/inspec-habitat/test/functional/inspec_habitat_test.rb +0 -38
  19. data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/README.md +0 -3
  20. data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/controls/inspec_habitat.rb +0 -40
  21. data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/inspec.yml +0 -10
  22. data/lib/plugins/inspec-habitat/test/support/example_profile/README.md +0 -3
  23. data/lib/plugins/inspec-habitat/test/support/example_profile/controls/example.rb +0 -7
  24. data/lib/plugins/inspec-habitat/test/support/example_profile/inspec.yml +0 -10
  25. data/lib/plugins/inspec-habitat/test/unit/profile_test.rb +0 -240
  26. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/fixtures/README.md +0 -24
  27. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/README.md +0 -12
  28. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/inspec_plugin_template_test.rb +0 -110
  29. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/helper.rb +0 -26
  30. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/README.md +0 -17
  31. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/cli_args_test.rb +0 -67
  32. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/plugin_def_test.rb +0 -51
  33. data/lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb +0 -173
  34. data/lib/plugins/inspec-init/test/functional/inspec_init_profile_test.rb +0 -100
  35. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/config_dirs/empty/.gitkeep +0 -0
  36. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette.rb +0 -2
  37. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette/.gitkeep +0 -0
  38. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-wrong-structure/.gitkeep +0 -0
  39. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name.rb +0 -1
  40. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name/.gitkeep +0 -0
  41. data/lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb +0 -713
  42. data/lib/plugins/inspec-plugin-manager-cli/test/unit/cli_args_test.rb +0 -75
  43. data/lib/plugins/inspec-plugin-manager-cli/test/unit/plugin_def_test.rb +0 -20
@@ -1,2 +0,0 @@
1
- source 'https://supermarket.chef.io'
2
- metadata
@@ -1,3 +0,0 @@
1
- # InSpec Habitat Fixture
2
-
3
- Used to setup a server for testing the `inspec-habitat` plugin
@@ -1,28 +0,0 @@
1
- #!/usr/bin/expect -f
2
-
3
- set timeout -1
4
-
5
- spawn hab setup
6
-
7
- expect "Connect to an on-premises bldr instance?"
8
- send -- "No\r"
9
-
10
- expect "Set up a default origin?"
11
- send -- "Yes\r"
12
-
13
- expect "Default origin name"
14
- send -- "vagrant\r"
15
-
16
- expect "Create an origin key for `vagrant'?"
17
- send -- "Yes\r"
18
-
19
- expect "Set up a default Habitat personal access token?"
20
- send -- "No\r"
21
-
22
- expect "Set up a default Habitat Supervisor CtlGateway secret?"
23
- send -- "No\r"
24
-
25
- expect "Enable analytics?"
26
- send -- "No\r"
27
-
28
- expect eof
@@ -1,9 +0,0 @@
1
- name 'inspec_habitat_fixture'
2
- maintainer 'The Authors'
3
- maintainer_email 'you@example.com'
4
- license 'All Rights Reserved'
5
- description 'Used for testing the inspec-habitat plugin'
6
- version '0.1.0'
7
- chef_version '>= 13.0'
8
-
9
- depends 'habitat'
@@ -1,61 +0,0 @@
1
- #
2
- # Cookbook:: kitchen_setup_cookbook
3
- # Recipe:: default
4
- #
5
- # Copyright:: 2019, The Authors, All Rights Reserved.
6
-
7
- package %w(ruby ruby-dev gcc g++ make expect)
8
-
9
- base_dir = '/home/vagrant'
10
-
11
- cookbook_file "#{base_dir}/inspec-local.gem" do
12
- source 'inspec-local.gem'
13
- action :create
14
- end
15
-
16
- gem_package 'inspec' do
17
- source "#{base_dir}/inspec-local.gem"
18
- subscribes :install, "cookbook_file[#{base_dir}/inspec-local.gem]", :immediately
19
- end
20
-
21
- cookbook_file "#{base_dir}/hab_setup.exp" do
22
- source 'hab_setup.exp'
23
- mode '0755'
24
- action :create
25
- end
26
-
27
- hab_install 'install habitat'
28
- hab_sup 'setup hab supervisor'
29
-
30
- execute 'setup hab cli' do
31
- command "#{base_dir}/hab_setup.exp"
32
- live_stream true
33
- not_if { ::File.exist?('/hab/etc/cli.toml') }
34
- not_if { ::File.exist?('~/.hab/etc/cli.toml') }
35
- end
36
-
37
- execute 'create inspec profile for testing' do
38
- command "inspec init profile #{base_dir}/hab_test_profile"
39
- live_stream true
40
- creates "#{base_dir}/hab_test_profile"
41
- end
42
-
43
- directory "#{base_dir}/output"
44
-
45
- execute 'create hart file from profile' do
46
- command "inspec habitat profile create #{base_dir}/hab_test_profile --output_dir '#{base_dir}/output'"
47
- live_stream true
48
- not_if "find #{base_dir}/output | grep vagrant-inspec-profile-hab_test_profile-0.1.0-.*.hart"
49
- end
50
-
51
- execute 'install vagrant/inspec-profile-hab_test_profile' do
52
- command "hab pkg install #{base_dir}/output/*.hart"
53
- live_stream true
54
- not_if 'hab pkg list --origin vagrant | grep inspec-profile'
55
- end
56
-
57
- execute 'load vagrant/inspec-profile-hab_test_profile into supervisor' do
58
- command 'hab svc load vagrant/inspec-profile-hab_test_profile'
59
- live_stream true
60
- not_if 'sudo hab svc status | grep "vagrant/inspec-profile-hab_test_profile"'
61
- end
@@ -1,38 +0,0 @@
1
- require_relative '../../../shared/core_plugin_test_helper.rb'
2
- require 'fileutils'
3
-
4
- class ProfileCli < MiniTest::Test
5
- include CorePluginFunctionalHelper
6
-
7
- def setup
8
- @tmpdir = Dir.mktmpdir
9
- @habitat_profile = File.join(@tmpdir, 'habitat-profile')
10
- run_inspec_process('init profile ' + @habitat_profile)
11
- end
12
-
13
- def teardown
14
- FileUtils.remove_entry_secure(@tmpdir)
15
- end
16
-
17
- def test_setup_subcommand
18
- result = run_inspec_process('habitat profile setup ' + @habitat_profile + ' --log-level debug')
19
-
20
- # Command runs without error
21
- assert_empty result.stderr
22
- assert_equal 0, result.exit_status
23
-
24
- # Command creates only expected files
25
- base_dir = File.join(@tmpdir, 'habitat-profile', 'habitat')
26
- files = %w{
27
- default.toml
28
- plan.sh
29
- config
30
- config/inspec_exec_config.json
31
- hooks
32
- hooks/run
33
- }
34
- actual_files = Dir.glob(File.join(base_dir, '**/*'))
35
- expected_files = files.map { |x| File.join(base_dir, x) }
36
- assert_equal actual_files.sort, expected_files.sort
37
- end
38
- end
@@ -1,3 +0,0 @@
1
- # Habitat InSpec Test Profile
2
-
3
- This profile is used to test `inspec habitat profile` commands
@@ -1,40 +0,0 @@
1
- control 'inspec-habitat-create' do
2
- title 'Create command'
3
-
4
- output_hart_dir = '/home/vagrant/output'
5
- find_hart_output = command("find #{output_hart_dir} -name '*.hart'").stdout
6
- hart_files = find_hart_output.split("\n")
7
-
8
- hab_profile_path = '/home/vagrant/hab_test_profile'
9
- find_profile_files_command = "find #{hab_profile_path} -type f -printf '%f\n'"
10
- profile_files = command(find_profile_files_command).stdout.split("\n").sort
11
- expected_files = %w{
12
- .gitkeep
13
- README.md
14
- example.rb
15
- inspec.yml
16
- }
17
-
18
- describe '`inspec habitat profile create`' do
19
- it 'should create exactly 1 hart file' do
20
- expect(hart_files.length).to eq(1)
21
- end
22
- it 'does not add any extra files to a default generated profile' do
23
- expect(profile_files).to eq(expected_files)
24
- end
25
- end
26
- end
27
-
28
- control 'inspec-habitat-service' do
29
- title 'inspec-profile-hab_test_profile service'
30
- describe 'The running service' do
31
- it 'should create a log file' do
32
- log = '/hab/svc/inspec-profile-hab_test_profile/logs/inspec_log.txt'
33
- expect(file(log).exist?).to be(true)
34
- end
35
- it 'should create a JSON file for the last run' do
36
- log = '/hab/svc/inspec-profile-hab_test_profile/logs/inspec_last_run.json'
37
- JSON.parse(file(log).content)
38
- end
39
- end
40
- end
@@ -1,10 +0,0 @@
1
- name: inspec_habitat
2
- title: InSpec Profile
3
- maintainer: The Authors
4
- copyright: The Authors
5
- copyright_email: you@example.com
6
- license: Apache-2.0
7
- summary: An InSpec Compliance Profile
8
- version: 0.1.0
9
- supports:
10
- platform: os
@@ -1,3 +0,0 @@
1
- # Example InSpec Profile
2
-
3
- This profile is used for unit testing the `inspec-habitat` profile
@@ -1,7 +0,0 @@
1
- control 'example' do
2
- impact 0.7
3
- title 'Example control'
4
- describe 'example' do
5
- it { should cmp 'example' }
6
- end
7
- end
@@ -1,10 +0,0 @@
1
- name: example_profile
2
- title: InSpec Profile
3
- maintainer: The Authors
4
- copyright: The Authors
5
- copyright_email: you@example.com
6
- license: Apache-2.0
7
- summary: An InSpec Compliance Profile
8
- version: 0.1.0
9
- supports:
10
- platform: os
@@ -1,240 +0,0 @@
1
- require 'mixlib/log'
2
- require 'fileutils'
3
- require 'minitest/autorun'
4
- require_relative '../../lib/inspec-habitat/profile.rb'
5
-
6
- class InspecPlugins::Habitat::ProfileTest < MiniTest::Unit::TestCase
7
- def setup
8
- @tmpdir = Dir.mktmpdir
9
-
10
- @output_dir = File.join(@tmpdir, 'output')
11
- FileUtils.mkdir(@output_dir)
12
-
13
- @fake_hart_file = FileUtils.touch(File.join(@tmpdir, 'fake-hart.hart'))[0]
14
-
15
- # Path from `__FILE__` needed to support running tests in `inspec/inspec`
16
- @test_profile_path = File.join(
17
- File.expand_path(File.dirname(__FILE__)),
18
- '../',
19
- 'support',
20
- 'example_profile'
21
- )
22
- @test_profile = Inspec::Profile.for_target(
23
- @test_profile_path,
24
- backend: Inspec::Backend.create(Inspec::Config.mock),
25
- )
26
-
27
- @hab_profile = InspecPlugins::Habitat::Profile.new(
28
- @test_profile_path,
29
- { output_dir: @output_dir },
30
- )
31
-
32
- @mock_hab_config = {
33
- 'auth_token' => 'FAKETOKEN',
34
- 'origin' => 'fake_origin',
35
- }
36
-
37
- Inspec::Log.level(:fatal)
38
- end
39
-
40
- def after_run
41
- FileUtils.remove_entry_secure(@tmpdir)
42
- end
43
-
44
- def test_create_raises_if_output_dir_does_not_exist
45
- profile = InspecPlugins::Habitat::Profile.new(
46
- @test_profile_path,
47
- {
48
- output_dir: '/not/a/real/path',
49
- log_level: 'fatal',
50
- },
51
- )
52
-
53
- assert_raises(SystemExit) { profile.create }
54
- # TODO: Figure out how to capture and validate `Inspec::Log.error`
55
- end
56
-
57
- def test_create
58
- file_count = Dir.glob(File.join(@test_profile_path, '**/*')).count
59
-
60
- @hab_profile.stub :read_habitat_config, @mock_hab_config do
61
- @hab_profile.stub :verify_habitat_setup, nil do
62
- @hab_profile.stub :build_hart, @fake_hart_file do
63
- @hab_profile.create
64
- end
65
- end
66
- end
67
-
68
- # It should not modify target profile
69
- new_file_count = Dir.glob(File.join(@test_profile_path, '**/*')).count
70
- assert_equal new_file_count, file_count
71
-
72
- # It should create 1 Habitat artifact
73
- output_files = Dir.glob(File.join(@output_dir, '**/*'))
74
- assert_equal 1, output_files.count
75
- assert_equal 'fake-hart.hart', File.basename(output_files.first)
76
- end
77
-
78
- def test_create_rasies_if_habitat_is_not_installed
79
- cmd = MiniTest::Mock.new
80
- cmd.expect(:error?, true)
81
- cmd.expect(:run_command, nil)
82
-
83
- Mixlib::ShellOut.stub :new, cmd, 'hab --version' do
84
- assert_raises(SystemExit) { @hab_profile.create }
85
- # TODO: Figure out how to capture and validate `Inspec::Log.error`
86
- end
87
-
88
- cmd.verify
89
- end
90
-
91
- def test_upload
92
- @hab_profile.stub :read_habitat_config, @mock_hab_config do
93
- @hab_profile.stub :create, @fake_hart_file do
94
- @hab_profile.stub :upload_hart, nil do
95
- @hab_profile.upload
96
- # TODO: Figure out how to capture and validate `Inspec::Log.error`
97
- end
98
- end
99
- end
100
- end
101
-
102
- def test_upload_raises_if_no_habitat_auth_token_is_found
103
- @hab_profile.stub :read_habitat_config, {} do
104
- assert_raises(SystemExit) { @hab_profile.upload }
105
- # TODO: Figure out how to capture and validate `Inspec::Log.error`
106
- end
107
- end
108
-
109
- def test_create_working_dir
110
- Dir.stub :mktmpdir, '/tmp/fakedir' do
111
- assert_equal '/tmp/fakedir', @hab_profile.send(:create_working_dir)
112
- end
113
- end
114
-
115
- def test_duplicate_profile
116
- current_profile = @test_profile
117
- duplicated_profile = @hab_profile.send(:duplicate_profile,
118
- @test_profile_path,
119
- @tmpdir)
120
- assert duplicated_profile.is_a?(Inspec::Profile)
121
- assert duplicated_profile.sha256 == current_profile.sha256.to_s
122
- refute_same duplicated_profile.root_path, current_profile.root_path
123
- end
124
-
125
- def test_profile_from_path
126
- profile = @hab_profile.send(:profile_from_path, @test_profile_path)
127
- assert profile.is_a?(Inspec::Profile)
128
- end
129
-
130
- def test_copy_profile_to_working_dir
131
- duplicated_profile = @hab_profile.send(:duplicate_profile,
132
- @test_profile_path,
133
- @tmpdir)
134
-
135
- dst = File.join(@tmpdir, 'working_dir')
136
- FileUtils.mkdir_p(dst)
137
- @hab_profile.send(:copy_profile_to_working_dir, duplicated_profile, dst)
138
-
139
- expected_files = %w{
140
- README.md
141
- inspec.yml
142
- example.rb
143
- }
144
-
145
- actual_files = Dir.glob(File.join(dst, '**/*')).map do |path|
146
- next unless File.file?(path)
147
- File.basename(path)
148
- end.compact
149
-
150
- assert(actual_files.sort == expected_files.sort)
151
- end
152
-
153
- def test_verify_profile_raises_if_profile_is_not_valid
154
- bad_profile_path = File.join(@tmpdir, 'bad_profile')
155
- FileUtils.mkdir_p(File.join(bad_profile_path))
156
- FileUtils.touch(File.join(bad_profile_path, 'inspec.yml'))
157
- bad_profile = Inspec::Profile.for_target(
158
- bad_profile_path,
159
- backend: Inspec::Backend.create(Inspec::Config.mock),
160
- )
161
- assert_raises(SystemExit) { @hab_profile.send(:verify_profile, bad_profile) }
162
- # TODO: Figure out how to capture and validate `Inspec::Log.error`
163
- end
164
-
165
- def test_vendor_profile_dependencies_does_not_vendor_if_already_vendored
166
- mock_lock_file = MiniTest::Mock.new
167
- mock_lock_file.expect(:exist?, true)
168
- mock_cache_path = MiniTest::Mock.new
169
- mock_cache_path.expect(:exist?, true)
170
-
171
- mock = MiniTest::Mock.new
172
- mock.expect(:lockfile, mock_lock_file)
173
- mock.expect(:cache_path, mock_cache_path)
174
-
175
- Inspec::ProfileVendor.stub :new, mock do
176
- new_profile = @hab_profile.send(:vendor_profile_dependencies!,
177
- @test_profile)
178
- assert new_profile.is_a?(Inspec::Profile)
179
- end
180
- end
181
-
182
- def test_vendor_profile_dependencies
183
- mock_lock_file = MiniTest::Mock.new
184
- mock_lock_file.expect(:exist?, false)
185
-
186
- mock = MiniTest::Mock.new
187
- mock.expect(:lockfile, mock_lock_file)
188
- mock.expect(:vendor!, nil)
189
- mock.expect(:make_readable, nil)
190
-
191
- Inspec::ProfileVendor.stub :new, mock do
192
- new_profile = @hab_profile.send(:vendor_profile_dependencies!,
193
- @test_profile)
194
- assert new_profile.is_a?(Inspec::Profile)
195
- end
196
- mock.verify
197
- end
198
-
199
- def test_verify_habitat_setup_raises_if_hab_version_errors
200
- mock = MiniTest::Mock.new
201
- mock.expect(:run_command, nil)
202
- mock.expect(:error?, true)
203
- mock.expect(:stderr, 'This would be an error message')
204
-
205
- Mixlib::ShellOut.stub(:new, mock) do
206
- assert_raises(SystemExit) { @hab_profile.send(:verify_habitat_setup, {}) }
207
- # TODO: Figure out how to capture and validate `Inspec::Log.error`
208
- end
209
- mock.verify
210
- end
211
-
212
- def test_verify_habitat_setup_raises_if_not_habitat_origin
213
- mock = MiniTest::Mock.new
214
- mock.expect(:run_command, nil)
215
- mock.expect(:error?, false)
216
-
217
- Mixlib::ShellOut.stub(:new, mock) do
218
- assert_raises(SystemExit) { @hab_profile.send(:verify_habitat_setup, {}) }
219
- # TODO: Figure out how to capture and validate `Inspec::Log.error`
220
- end
221
- mock.verify
222
- end
223
-
224
- # TODO: Figure out how to stub system()
225
- # def test_build_hart
226
- # end
227
-
228
- def test_upload_hart_raises_if_hab_pkg_upload_fails
229
- mock = MiniTest::Mock.new
230
- mock.expect(:run_command, nil)
231
- mock.expect(:error?, true)
232
- mock.expect(:stdout, 'This would contain output from `hab`')
233
- mock.expect(:stderr, 'This would be an error message')
234
-
235
- Mixlib::ShellOut.stub(:new, mock) do
236
- assert_raises(SystemExit) { @hab_profile.send(:upload_hart, @fake_hart_file, {}) }
237
- # TODO: Figure out how to capture and validate `Inspec::Log.error`
238
- end
239
- end
240
- end