2020-12-18 16:49:35 +00:00
require " fileutils " unless defined? ( FileUtils )
2019-08-13 23:23:01 +00:00
require " plugins/shared/core_plugin_test_helper "
2020-12-18 16:49:35 +00:00
require " securerandom " unless defined? ( 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
2019-08-13 23:23:01 +00:00
prepare_examples do | dir |
2020-08-17 12:27:58 +00:00
skip_windows! # Breakage confirmed, only on CI: https://buildkite.com/chef-oss/inspec-inspec-master-verify/builds/2355#2c9d032e-4a24-4e7c-aef2-1c9e2317d9e2
2019-07-09 00:20:30 +00:00
unique_key_name = SecureRandom . uuid
2019-08-13 23:23:01 +00:00
out = run_inspec_process ( " artifact generate --keyname #{ unique_key_name } " , prefix : " cd #{ dir } ; " )
2018-09-19 00:19:56 +00:00
stdout = out . stdout . force_encoding ( Encoding :: UTF_8 )
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
2019-08-13 23:23:01 +00:00
prepare_examples do | dir |
2020-08-17 12:27:58 +00:00
skip_windows! # Breakage confirmed, only on CI: https://buildkite.com/chef-oss/inspec-inspec-master-verify/builds/2355#2c9d032e-4a24-4e7c-aef2-1c9e2317d9e2
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 " )
2019-08-13 23:23:01 +00:00
run_inspec_process ( " init profile artifact-profile " , prefix : " cd #{ dir } ; " )
2018-09-19 00:19:56 +00:00
2019-08-13 23:23:01 +00:00
out = run_inspec_process ( " artifact generate --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
2019-08-13 23:23:01 +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
2019-08-13 23:23:01 +00:00
# The archive 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?
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 "
2020-05-04 15:42:59 +00:00
assert_includes Dir . entries ( install_dir ) . join , " inspec.json "
2019-08-13 23:23:01 +00:00
assert_exit_code 0 , out
2018-09-19 00:19:56 +00:00
end
end
end