2019-06-11 22:24:35 +00:00
|
|
|
require "fileutils"
|
|
|
|
require "functional/helper"
|
|
|
|
require "securerandom"
|
2018-11-08 17:00:14 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "inspec exec" do
|
2018-11-08 17:00:14 +00:00
|
|
|
include FunctionalHelper
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can generate keys" do
|
2018-11-08 17:00:14 +00:00
|
|
|
prepare_examples do |dir|
|
2019-07-09 00:20:30 +00:00
|
|
|
unique_key_name = SecureRandom.uuid
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2018-11-08 17:00:14 +00:00
|
|
|
out = inspec("artifact generate --keyname #{unique_key_name}", "cd #{dir} && ")
|
|
|
|
|
|
|
|
stdout = out.stdout.force_encoding(Encoding::UTF_8)
|
2019-06-11 22:24:35 +00:00
|
|
|
stdout.must_include "Generating private key"
|
|
|
|
stdout.must_include "Generating public key"
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2018-11-08 17:00:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can sign, verify and install a signed profile" do
|
2018-11-08 17:00:14 +00:00
|
|
|
# The arcive install commands do not currently support windows and
|
|
|
|
# use specific linux extract tar commands. Since artifact is still
|
|
|
|
# experimental we are skipping it for now.
|
|
|
|
return if is_windows?
|
2019-07-09 00:20:30 +00:00
|
|
|
|
2018-11-08 17:00:14 +00:00
|
|
|
prepare_examples do |dir|
|
2019-07-09 00:20:30 +00:00
|
|
|
unique_key_name = SecureRandom.uuid
|
|
|
|
install_dir = File.join(dir, SecureRandom.uuid)
|
2019-06-11 22:24:35 +00:00
|
|
|
profile = File.join(dir, "profile")
|
2018-11-08 17:00:14 +00:00
|
|
|
FileUtils.mkdir(install_dir)
|
|
|
|
|
|
|
|
out = inspec("artifact generate --keyname #{unique_key_name}", "cd #{dir} &&")
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2018-11-08 17:00:14 +00:00
|
|
|
|
|
|
|
out = inspec("artifact sign-profile --profile #{profile} --keyname #{unique_key_name}", "cd #{dir} &&")
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2018-11-08 17:00:14 +00:00
|
|
|
|
|
|
|
out = inspec("artifact install-profile --infile profile-1.0.0.iaf --destdir #{install_dir}", "cd #{dir} &&")
|
|
|
|
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "Installing to #{install_dir}"
|
|
|
|
Dir.entries(install_dir).join.must_include "inspec.yml"
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2018-11-08 17:00:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|