2019-06-11 22:24:35 +00:00
|
|
|
require_relative "../../../shared/core_plugin_test_helper.rb"
|
|
|
|
require "fileutils"
|
|
|
|
require "securerandom"
|
2018-09-19 00:19:56 +00:00
|
|
|
|
2019-04-24 00:21:31 +00:00
|
|
|
class ArtifactCli < Minitest::Test
|
2018-09-19 00:19:56 +00:00
|
|
|
include CorePluginFunctionalHelper
|
|
|
|
|
|
|
|
def test_generating_archive_keys
|
|
|
|
Dir.mktmpdir do |dir|
|
2019-07-09 00:20:30 +00:00
|
|
|
unique_key_name = SecureRandom.uuid
|
2018-09-19 00:19:56 +00:00
|
|
|
out = run_inspec_process("artifact generate --keyname #{unique_key_name}", prefix: "cd #{dir} &&")
|
|
|
|
|
|
|
|
stdout = out.stdout.force_encoding(Encoding::UTF_8)
|
2019-07-25 00:26:11 +00:00
|
|
|
skip_windows!
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes stdout, "Generating private key"
|
|
|
|
assert_includes stdout, "Generating public key"
|
2019-07-23 01:44:43 +00:00
|
|
|
|
|
|
|
assert_exit_code 0, out
|
2018-09-19 00:19:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_verify_and_install_signed_profile
|
|
|
|
Dir.mktmpdir do |dir|
|
2019-07-09 00:20:30 +00:00
|
|
|
unique_key_name = SecureRandom.uuid
|
|
|
|
install_dir = File.join(dir, SecureRandom.uuid)
|
2018-09-19 00:19:56 +00:00
|
|
|
FileUtils.mkdir(install_dir)
|
|
|
|
|
|
|
|
# create profile
|
2019-06-11 22:24:35 +00:00
|
|
|
profile = File.join(dir, "artifact-profile")
|
2018-09-19 00:19:56 +00:00
|
|
|
run_inspec_process("init profile artifact-profile", prefix: "cd #{dir} &&")
|
|
|
|
|
|
|
|
out = run_inspec_process("artifact generate --keyname #{unique_key_name}", prefix: "cd #{dir} &&")
|
2019-07-25 00:26:11 +00:00
|
|
|
skip_windows!
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2018-09-19 00:19:56 +00:00
|
|
|
|
|
|
|
out = run_inspec_process("artifact sign-profile --profile #{profile} --keyname #{unique_key_name}", prefix: "cd #{dir} &&")
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2018-09-19 00:19:56 +00:00
|
|
|
|
|
|
|
out = run_inspec_process("artifact install-profile --infile artifact-profile-0.1.0.iaf --destdir #{install_dir}", prefix: "cd #{dir} &&")
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2018-09-19 00:19:56 +00:00
|
|
|
|
|
|
|
assert_includes out.stdout.force_encoding(Encoding::UTF_8), "Installing to #{install_dir}"
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_includes Dir.entries(install_dir).join, "inspec.yml"
|
2018-09-19 00:19:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|