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.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6060db98285f1a0cdb5d521ad533a502a0481c57ad613baf2c0469d520966f23
|
4
|
+
data.tar.gz: 0ccdf80c41296d07328c5fd7bb172e75aca2e9c40acbef9813d7aa442be95c89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5199f204d872c74e1091021828b28f210ba2eb81d164af3365edcddb9ffe6bdb45b261fddb3109c27bd77ac5345cf009145e7c0606754a27530c594e2e511d63
|
7
|
+
data.tar.gz: e2c1e9ac924684a2dfb26665a88ee31fc66c6813c7aeb04bf6e312875c5efd69aea924da4e1bf43b27483adaaa1516c35711d8b69aa12c40b0853ac70c234e9a
|
data/README.md
CHANGED
@@ -28,10 +28,6 @@ module Inspec::Reporters
|
|
28
28
|
|
29
29
|
final_report[:report_uuid] = @config['report_uuid'] || uuid_from_string(final_report[:end_time] + final_report[:node_uuid])
|
30
30
|
|
31
|
-
# optional json-config passthrough options
|
32
|
-
%w{node_name environment roles recipies job_uuid}.each do |option|
|
33
|
-
final_report[option.to_sym] = @config[option] unless @config[option].nil?
|
34
|
-
end
|
35
31
|
final_report
|
36
32
|
end
|
37
33
|
|
@@ -17,7 +17,7 @@ module Inspec::Reporters
|
|
17
17
|
# grab profiles from the json parent class
|
18
18
|
@profiles = profiles
|
19
19
|
|
20
|
-
{
|
20
|
+
output = {
|
21
21
|
platform: platform,
|
22
22
|
profiles: merge_profiles,
|
23
23
|
statistics: {
|
@@ -25,6 +25,12 @@ module Inspec::Reporters
|
|
25
25
|
},
|
26
26
|
version: run_data[:version],
|
27
27
|
}
|
28
|
+
|
29
|
+
# optional json-config passthrough options
|
30
|
+
%w{node_name environment roles job_uuid passthrough}.each do |option|
|
31
|
+
output[option.to_sym] = @config[option] unless @config[option].nil?
|
32
|
+
end
|
33
|
+
output
|
28
34
|
end
|
29
35
|
|
30
36
|
private
|
data/lib/inspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspec-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: train-core
|
@@ -474,7 +474,6 @@ files:
|
|
474
474
|
- lib/plugins/inspec-artifact/lib/inspec-artifact.rb
|
475
475
|
- lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb
|
476
476
|
- lib/plugins/inspec-artifact/lib/inspec-artifact/cli.rb
|
477
|
-
- lib/plugins/inspec-artifact/test/functional/inspec_artifact_test.rb
|
478
477
|
- lib/plugins/inspec-compliance/README.md
|
479
478
|
- lib/plugins/inspec-compliance/lib/inspec-compliance.rb
|
480
479
|
- lib/plugins/inspec-compliance/lib/inspec-compliance/api.rb
|
@@ -485,11 +484,6 @@ files:
|
|
485
484
|
- lib/plugins/inspec-compliance/lib/inspec-compliance/images/cc-token.png
|
486
485
|
- lib/plugins/inspec-compliance/lib/inspec-compliance/support.rb
|
487
486
|
- lib/plugins/inspec-compliance/lib/inspec-compliance/target.rb
|
488
|
-
- lib/plugins/inspec-compliance/test/functional/inspec_compliance_test.rb
|
489
|
-
- lib/plugins/inspec-compliance/test/integration/default/cli.rb
|
490
|
-
- lib/plugins/inspec-compliance/test/unit/api/login_test.rb
|
491
|
-
- lib/plugins/inspec-compliance/test/unit/api_test.rb
|
492
|
-
- lib/plugins/inspec-compliance/test/unit/target_test.rb
|
493
487
|
- lib/plugins/inspec-habitat/Berksfile
|
494
488
|
- lib/plugins/inspec-habitat/README.md
|
495
489
|
- lib/plugins/inspec-habitat/kitchen.yml
|
@@ -500,19 +494,6 @@ files:
|
|
500
494
|
- lib/plugins/inspec-habitat/templates/habitat/default.toml.erb
|
501
495
|
- lib/plugins/inspec-habitat/templates/habitat/hooks/run.erb
|
502
496
|
- lib/plugins/inspec-habitat/templates/habitat/plan.sh.erb
|
503
|
-
- lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/Berksfile
|
504
|
-
- lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/README.md
|
505
|
-
- lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/files/hab_setup.exp
|
506
|
-
- lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/metadata.rb
|
507
|
-
- lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/recipes/default.rb
|
508
|
-
- lib/plugins/inspec-habitat/test/functional/inspec_habitat_test.rb
|
509
|
-
- lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/README.md
|
510
|
-
- lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/controls/inspec_habitat.rb
|
511
|
-
- lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/inspec.yml
|
512
|
-
- lib/plugins/inspec-habitat/test/support/example_profile/README.md
|
513
|
-
- lib/plugins/inspec-habitat/test/support/example_profile/controls/example.rb
|
514
|
-
- lib/plugins/inspec-habitat/test/support/example_profile/inspec.yml
|
515
|
-
- lib/plugins/inspec-habitat/test/unit/profile_test.rb
|
516
497
|
- lib/plugins/inspec-init/README.md
|
517
498
|
- lib/plugins/inspec-init/lib/inspec-init.rb
|
518
499
|
- lib/plugins/inspec-init/lib/inspec-init/cli.rb
|
@@ -528,32 +509,14 @@ files:
|
|
528
509
|
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.rb
|
529
510
|
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.rb
|
530
511
|
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.rb
|
531
|
-
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/fixtures/README.md
|
532
|
-
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/README.md
|
533
|
-
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/inspec_plugin_template_test.rb
|
534
|
-
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/helper.rb
|
535
|
-
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/README.md
|
536
|
-
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/cli_args_test.rb
|
537
|
-
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/plugin_def_test.rb
|
538
512
|
- lib/plugins/inspec-init/templates/profiles/os/README.md
|
539
513
|
- lib/plugins/inspec-init/templates/profiles/os/controls/example.rb
|
540
514
|
- lib/plugins/inspec-init/templates/profiles/os/inspec.yml
|
541
515
|
- lib/plugins/inspec-init/templates/profiles/os/libraries/.gitkeep
|
542
|
-
- lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb
|
543
|
-
- lib/plugins/inspec-init/test/functional/inspec_init_profile_test.rb
|
544
516
|
- lib/plugins/inspec-plugin-manager-cli/README.md
|
545
517
|
- lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli.rb
|
546
518
|
- lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb
|
547
519
|
- lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/plugin.rb
|
548
|
-
- lib/plugins/inspec-plugin-manager-cli/test/fixtures/config_dirs/empty/.gitkeep
|
549
|
-
- lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette.rb
|
550
|
-
- lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette/.gitkeep
|
551
|
-
- lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-wrong-structure/.gitkeep
|
552
|
-
- lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name.rb
|
553
|
-
- lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name/.gitkeep
|
554
|
-
- lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb
|
555
|
-
- lib/plugins/inspec-plugin-manager-cli/test/unit/cli_args_test.rb
|
556
|
-
- lib/plugins/inspec-plugin-manager-cli/test/unit/plugin_def_test.rb
|
557
520
|
- lib/plugins/shared/core_plugin_test_helper.rb
|
558
521
|
- lib/plugins/things-for-train-integration.rb
|
559
522
|
- lib/resources/aide_conf.rb
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require_relative '../../../shared/core_plugin_test_helper.rb'
|
4
|
-
require 'fileutils'
|
5
|
-
require 'securerandom'
|
6
|
-
|
7
|
-
class ArtifactCli < MiniTest::Test
|
8
|
-
include CorePluginFunctionalHelper
|
9
|
-
|
10
|
-
def test_generating_archive_keys
|
11
|
-
Dir.mktmpdir do |dir|
|
12
|
-
unique_key_name = SecureRandom.uuid()
|
13
|
-
out = run_inspec_process("artifact generate --keyname #{unique_key_name}", prefix: "cd #{dir} &&")
|
14
|
-
assert_equal 0, out.exit_status
|
15
|
-
|
16
|
-
stdout = out.stdout.force_encoding(Encoding::UTF_8)
|
17
|
-
assert_includes stdout, 'Generating private key'
|
18
|
-
assert_includes stdout, 'Generating public key'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_verify_and_install_signed_profile
|
23
|
-
Dir.mktmpdir do |dir|
|
24
|
-
unique_key_name = SecureRandom.uuid()
|
25
|
-
install_dir = File.join(dir, SecureRandom.uuid())
|
26
|
-
profile = File.join(dir, 'profile')
|
27
|
-
FileUtils.mkdir(install_dir)
|
28
|
-
|
29
|
-
# create profile
|
30
|
-
profile = File.join(dir, 'artifact-profile')
|
31
|
-
run_inspec_process("init profile artifact-profile", prefix: "cd #{dir} &&")
|
32
|
-
|
33
|
-
out = run_inspec_process("artifact generate --keyname #{unique_key_name}", prefix: "cd #{dir} &&")
|
34
|
-
assert_equal 0, out.exit_status
|
35
|
-
|
36
|
-
out = run_inspec_process("artifact sign-profile --profile #{profile} --keyname #{unique_key_name}", prefix: "cd #{dir} &&")
|
37
|
-
assert_equal 0, out.exit_status
|
38
|
-
|
39
|
-
out = run_inspec_process("artifact install-profile --infile artifact-profile-0.1.0.iaf --destdir #{install_dir}", prefix: "cd #{dir} &&")
|
40
|
-
assert_equal 0, out.exit_status
|
41
|
-
|
42
|
-
assert_includes out.stdout.force_encoding(Encoding::UTF_8), "Installing to #{install_dir}"
|
43
|
-
assert_includes Dir.entries(install_dir).join, 'inspec.yml'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require_relative '../../../shared/core_plugin_test_helper.rb'
|
4
|
-
|
5
|
-
class ComplianceCli < MiniTest::Test
|
6
|
-
include CorePluginFunctionalHelper
|
7
|
-
|
8
|
-
def test_help_output
|
9
|
-
out = run_inspec_process('compliance help')
|
10
|
-
assert_equal out.exit_status, 0
|
11
|
-
assert_includes out.stdout, 'inspec compliance exec PROFILE'
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_logout_command
|
15
|
-
out = run_inspec_process('compliance logout')
|
16
|
-
assert_equal out.exit_status, 0
|
17
|
-
assert_includes out.stdout, ''
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_error_login_with_invalid_url
|
21
|
-
out = run_inspec_process('compliance login')
|
22
|
-
assert_equal out.exit_status, 1
|
23
|
-
assert_includes out.stderr, 'ERROR: "inspec compliance login" was called with no arguments'
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_profile_list_without_auth
|
27
|
-
out = run_inspec_process('compliance profiles')
|
28
|
-
assert_equal out.exit_status, 0 # TODO: make this error
|
29
|
-
assert_includes out.stdout, 'You need to login first with `inspec compliance login`'
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_error_upload_without_args
|
33
|
-
out = run_inspec_process('compliance upload')
|
34
|
-
assert_equal out.exit_status, 1
|
35
|
-
assert_includes out.stderr, 'ERROR: "inspec compliance upload" was called with no arguments'
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_error_upload_with_fake_path
|
39
|
-
out = run_inspec_process('compliance upload /path/to/dir')
|
40
|
-
assert_equal out.exit_status, 0 # TODO: make this error
|
41
|
-
assert_includes out.stdout, 'You need to login first with `inspec compliance login`'
|
42
|
-
end
|
43
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# options
|
4
|
-
inspec_bin = 'BUNDLE_GEMFILE=/inspec/Gemfile bundle exec inspec'
|
5
|
-
api_url = 'https://0.0.0.0'
|
6
|
-
profile = '/inspec/examples/profile'
|
7
|
-
|
8
|
-
user = command('whoami').stdout.strip
|
9
|
-
pwd = command('pwd').stdout.strip
|
10
|
-
puts "Run test as #{user} in path #{pwd}"
|
11
|
-
|
12
|
-
# TODO: determine tokens automatically, define in kitchen yml
|
13
|
-
access_token = ENV['COMPLIANCE_ACCESSTOKEN']
|
14
|
-
refresh_token = ENV['COMPLIANCE_REFRESHTOKEN']
|
15
|
-
|
16
|
-
%w{refresh_token access_token}.each do |type| # rubocop:disable Metrics/BlockLength
|
17
|
-
case type
|
18
|
-
when 'access_token'
|
19
|
-
token_options = "--token '#{access_token}'"
|
20
|
-
when 'refresh_token'
|
21
|
-
token_options = "--refresh_token '#{refresh_token}'"
|
22
|
-
end
|
23
|
-
|
24
|
-
# verifies that the help command works
|
25
|
-
describe command("#{inspec_bin} compliance help") do
|
26
|
-
its('stdout') { should include 'inspec compliance help [COMMAND]' }
|
27
|
-
its('stderr') { should eq '' }
|
28
|
-
its('exit_status') { should eq 0 }
|
29
|
-
end
|
30
|
-
|
31
|
-
# version command fails gracefully when server not configured
|
32
|
-
describe command("#{inspec_bin} compliance version") do
|
33
|
-
its('stdout') { should include 'Server configuration information is missing' }
|
34
|
-
its('stderr') { should eq '' }
|
35
|
-
its('exit_status') { should eq 1 }
|
36
|
-
end
|
37
|
-
|
38
|
-
# submitting a wrong token should have an exit of 0
|
39
|
-
describe command("#{inspec_bin} compliance login #{api_url} --insecure --user 'admin' --token 'wrong-token'") do
|
40
|
-
its('stdout') { should include 'token stored' }
|
41
|
-
end
|
42
|
-
|
43
|
-
# compliance login --help should give an accurate message for login
|
44
|
-
describe command("#{inspec_bin} compliance login --help") do
|
45
|
-
its('stdout') { should include "inspec compliance login SERVER --insecure --user='USER' --token='TOKEN'" }
|
46
|
-
its('exit_status') { should eq 0 }
|
47
|
-
end
|
48
|
-
|
49
|
-
# profiles command fails gracefully when token/server info is incorrect
|
50
|
-
describe command("#{inspec_bin} compliance profiles") do
|
51
|
-
its('stdout') { should include '401 Unauthorized. Please check your token' }
|
52
|
-
its('stderr') { should eq '' }
|
53
|
-
its('exit_status') { should eq 1 }
|
54
|
-
end
|
55
|
-
|
56
|
-
# login via access token token
|
57
|
-
describe command("#{inspec_bin} compliance login #{api_url} --insecure --user 'admin' #{token_options}") do
|
58
|
-
its('stdout') { should include 'token', 'stored' }
|
59
|
-
its('stdout') { should_not include 'Your server supports --user and --password only' }
|
60
|
-
its('stderr') { should eq '' }
|
61
|
-
its('exit_status') { should eq 0 }
|
62
|
-
end
|
63
|
-
|
64
|
-
# see available resources
|
65
|
-
describe command("#{inspec_bin} compliance profiles") do
|
66
|
-
its('stdout') { should include 'base/ssh' }
|
67
|
-
its('stderr') { should eq '' }
|
68
|
-
its('exit_status') { should eq 0 }
|
69
|
-
end
|
70
|
-
|
71
|
-
# upload a compliance profile
|
72
|
-
describe command("#{inspec_bin} compliance upload #{profile} --overwrite") do
|
73
|
-
its('stdout') { should include 'Profile is valid' }
|
74
|
-
its('stdout') { should include 'Successfully uploaded profile' }
|
75
|
-
its('stdout') { should_not include 'error(s)' }
|
76
|
-
its('stderr') { should eq '' }
|
77
|
-
its('exit_status') { should eq 0 }
|
78
|
-
end
|
79
|
-
|
80
|
-
# returns the version of the server
|
81
|
-
describe command("#{inspec_bin} compliance version") do
|
82
|
-
its('stdout') { should include 'Chef Compliance version:' }
|
83
|
-
its('stderr') { should eq '' }
|
84
|
-
its('exit_status') { should eq 0 }
|
85
|
-
end
|
86
|
-
|
87
|
-
# logout
|
88
|
-
describe command("#{inspec_bin} compliance logout") do
|
89
|
-
its('stdout') { should include 'Successfully logged out' }
|
90
|
-
its('stderr') { should eq '' }
|
91
|
-
its('exit_status') { should eq 0 }
|
92
|
-
end
|
93
|
-
end
|
@@ -1,190 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'mocha/setup'
|
3
|
-
require 'webmock/minitest'
|
4
|
-
require_relative '../../../lib/inspec-compliance/api.rb'
|
5
|
-
|
6
|
-
describe InspecPlugins::Compliance::API do
|
7
|
-
let(:automate_options) do
|
8
|
-
{
|
9
|
-
'server' => 'https://automate.example.com',
|
10
|
-
'ent' => 'automate',
|
11
|
-
'user' => 'someone',
|
12
|
-
'token' => 'token',
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:compliance_options) do
|
17
|
-
{
|
18
|
-
'server' => 'https://compliance.example.com',
|
19
|
-
'user' => 'someone',
|
20
|
-
'password' => 'password',
|
21
|
-
'token' => 'token',
|
22
|
-
'refresh_token' => 'refresh_token',
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
let(:fake_config) do
|
27
|
-
class FakeConfig
|
28
|
-
def initialize
|
29
|
-
@config = {}
|
30
|
-
end
|
31
|
-
|
32
|
-
def [](key)
|
33
|
-
@config[key]
|
34
|
-
end
|
35
|
-
|
36
|
-
def []=(key, value)
|
37
|
-
@config[key] = value
|
38
|
-
end
|
39
|
-
|
40
|
-
def clean
|
41
|
-
@config = {}
|
42
|
-
end
|
43
|
-
|
44
|
-
def store
|
45
|
-
nil
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
FakeConfig.new
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '.login' do
|
53
|
-
describe 'when target is a Chef Automate2 server' do
|
54
|
-
before do
|
55
|
-
InspecPlugins::Compliance::API.expects(:determine_server_type).returns(:automate2)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'raises an error if `--user` is missing' do
|
59
|
-
options = automate_options
|
60
|
-
options.delete('user')
|
61
|
-
err = proc { InspecPlugins::Compliance::API.login(options) }.must_raise(ArgumentError)
|
62
|
-
err.message.must_match(/Please specify a user.*/)
|
63
|
-
err.message.lines.length.must_equal(1)
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'raises an error if `--token` and `--dctoken` are missing' do
|
67
|
-
options = automate_options
|
68
|
-
options.delete('token')
|
69
|
-
options.delete('dctoken')
|
70
|
-
err = proc { InspecPlugins::Compliance::API.login(options) }.must_raise(ArgumentError)
|
71
|
-
err.message.must_match(/Please specify a token.*/)
|
72
|
-
err.message.lines.length.must_equal(1)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'stores an access token' do
|
76
|
-
stub_request(:get, automate_options['server'] + '/compliance/version')
|
77
|
-
.to_return(status: 200, body: '', headers: {})
|
78
|
-
options = automate_options
|
79
|
-
InspecPlugins::Compliance::Configuration.expects(:new).returns(fake_config)
|
80
|
-
|
81
|
-
InspecPlugins::Compliance::API.login(options)
|
82
|
-
fake_config['automate']['ent'].must_equal('automate')
|
83
|
-
fake_config['automate']['token_type'].must_equal('dctoken')
|
84
|
-
fake_config['user'].must_equal('someone')
|
85
|
-
fake_config['server'].must_equal('https://automate.example.com/api/v0')
|
86
|
-
fake_config['server_type'].must_equal('automate2')
|
87
|
-
fake_config['token'].must_equal('token')
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe 'when target is a Chef Automate server' do
|
92
|
-
before do
|
93
|
-
InspecPlugins::Compliance::API.expects(:determine_server_type).returns(:automate)
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'raises an error if `--user` is missing' do
|
97
|
-
options = automate_options
|
98
|
-
options.delete('user')
|
99
|
-
err = proc { InspecPlugins::Compliance::API.login(options) }.must_raise(ArgumentError)
|
100
|
-
err.message.must_match(/Please specify a user.*/)
|
101
|
-
err.message.lines.length.must_equal(1)
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'raises an error if `--ent` is missing' do
|
105
|
-
options = automate_options
|
106
|
-
options.delete('ent')
|
107
|
-
err = proc { InspecPlugins::Compliance::API.login(options) }.must_raise(ArgumentError)
|
108
|
-
err.message.must_match(/Please specify an enterprise.*/)
|
109
|
-
err.message.lines.length.must_equal(1)
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'raises an error if `--token` and `--dctoken` are missing' do
|
113
|
-
options = automate_options
|
114
|
-
options.delete('token')
|
115
|
-
options.delete('dctoken')
|
116
|
-
err = proc { InspecPlugins::Compliance::API.login(options) }.must_raise(ArgumentError)
|
117
|
-
err.message.must_match(/Please specify a token.*/)
|
118
|
-
err.message.lines.length.must_equal(1)
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'stores an access token' do
|
122
|
-
stub_request(:get, automate_options['server'] + '/compliance/version')
|
123
|
-
.to_return(status: 200, body: '', headers: {})
|
124
|
-
options = automate_options
|
125
|
-
InspecPlugins::Compliance::Configuration.expects(:new).returns(fake_config)
|
126
|
-
|
127
|
-
InspecPlugins::Compliance::API.login(options)
|
128
|
-
fake_config['automate']['ent'].must_equal('automate')
|
129
|
-
fake_config['automate']['token_type'].must_equal('usertoken')
|
130
|
-
fake_config['user'].must_equal('someone')
|
131
|
-
fake_config['server'].must_equal('https://automate.example.com/compliance')
|
132
|
-
fake_config['server_type'].must_equal('automate')
|
133
|
-
fake_config['token'].must_equal('token')
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe 'when target is a Chef Compliance server' do
|
138
|
-
before do
|
139
|
-
InspecPlugins::Compliance::API.expects(:determine_server_type).returns(:compliance)
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'raises an error if `--user` and `--refresh-token` are missing' do
|
143
|
-
options = automate_options
|
144
|
-
options.delete('user')
|
145
|
-
options.delete('refresh_token')
|
146
|
-
err = proc { InspecPlugins::Compliance::API.login(options) }.must_raise(ArgumentError)
|
147
|
-
err.message.must_match(/Please specify a.*--user.*--refresh-token.*/)
|
148
|
-
err.message.lines.length.must_equal(1)
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'raises an error if `--user` is present but authentication method missing' do
|
152
|
-
options = automate_options
|
153
|
-
options.delete('password')
|
154
|
-
options.delete('token')
|
155
|
-
options.delete('refresh_token')
|
156
|
-
err = proc { InspecPlugins::Compliance::API.login(options) }.must_raise(ArgumentError)
|
157
|
-
err.message.must_match(/Please specify.*--password.*--token.*--refresh-token.*/)
|
158
|
-
err.message.lines.length.must_equal(1)
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'stores an access token' do
|
162
|
-
stub_request(:get, compliance_options['server'] + '/api/version')
|
163
|
-
.to_return(status: 200, body: '', headers: {})
|
164
|
-
options = compliance_options
|
165
|
-
InspecPlugins::Compliance::Configuration.expects(:new).returns(fake_config)
|
166
|
-
|
167
|
-
InspecPlugins::Compliance::API.login(options)
|
168
|
-
fake_config['user'].must_equal('someone')
|
169
|
-
fake_config['server'].must_equal('https://compliance.example.com/api')
|
170
|
-
fake_config['server_type'].must_equal('compliance')
|
171
|
-
fake_config['token'].must_equal('token')
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe 'when target is neither a Chef Compliance nor Chef Automate server' do
|
176
|
-
it 'raises an error if `https://SERVER` is missing' do
|
177
|
-
options = {}
|
178
|
-
err = proc { InspecPlugins::Compliance::API.login(options) }.must_raise(ArgumentError)
|
179
|
-
err.message.must_match(/Please specify a server.*/)
|
180
|
-
err.message.lines.length.must_equal(1)
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'rasies a `CannotDetermineServerType` error' do
|
184
|
-
InspecPlugins::Compliance::API.expects(:determine_server_type).returns(nil)
|
185
|
-
err = proc { InspecPlugins::Compliance::API.login(automate_options) }.must_raise(StandardError)
|
186
|
-
err.message.must_match(/Unable to determine/)
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|