mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
CFINSPEC-462: Fixes inspec sign breaks when there is period or dot in the profile name (#6261)
Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io> Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
This commit is contained in:
parent
361c19a006
commit
572524b7ff
2 changed files with 30 additions and 2 deletions
|
@ -59,11 +59,14 @@ module InspecPlugins
|
|||
# Read name and version from metadata and use them to form the filename
|
||||
profile_md = artifact.read_profile_metadata(profile_path)
|
||||
|
||||
artifact_filename = "#{profile_md["name"]}-#{profile_md["version"]}.#{SIGNED_PROFILE_SUFFIX}"
|
||||
# Behave same as archive filename for iaf filename
|
||||
slug = profile_md["name"].downcase.strip.tr(" ", "-").gsub(/[^\w-]/, "_")
|
||||
filename = "#{slug}-#{profile_md["version"]}"
|
||||
artifact_filename = "#{filename}.#{SIGNED_PROFILE_SUFFIX}"
|
||||
|
||||
# Generating tar.gz file using archive method of Inspec Cli
|
||||
Inspec::InspecCLI.new.archive(profile_path, "error")
|
||||
tarfile = "#{profile_md["name"]}-#{profile_md["version"]}.tar.gz"
|
||||
tarfile = "#{filename}.tar.gz"
|
||||
tar_content = IO.binread(tarfile)
|
||||
FileUtils.rm(tarfile)
|
||||
|
||||
|
|
|
@ -46,6 +46,31 @@ class SignCli < Minitest::Test
|
|||
end
|
||||
end
|
||||
|
||||
def test_sign_profile_for_profile_name_with_period
|
||||
prepare_examples do |dir|
|
||||
skip_windows! # Breakage confirmed, only on CI: https://buildkite.com/chef-oss/inspec-inspec-master-verify/builds/2355#2c9d032e-4a24-4e7c-aef2-1c9e2317d9e2
|
||||
|
||||
unique_key_name = SecureRandom.uuid
|
||||
|
||||
# create profile
|
||||
profile = File.join(dir, "artifact-profile-5.3")
|
||||
run_inspec_process("init profile artifact-profile-5.3", prefix: "cd #{dir};")
|
||||
|
||||
out = run_inspec_process("sign generate-keys --keyname #{unique_key_name}", prefix: "cd #{dir};")
|
||||
assert_exit_code 0, out
|
||||
|
||||
out = run_inspec_process("sign profile #{profile} --keyname #{unique_key_name}", prefix: "cd #{dir};")
|
||||
assert_exit_code 0, out
|
||||
|
||||
out = run_inspec_process("sign verify artifact-profile-5_3-0.1.0.iaf", prefix: "cd #{dir};")
|
||||
assert_exit_code 0, out
|
||||
|
||||
assert_includes out.stdout.force_encoding(Encoding::UTF_8), "Verifying artifact-profile-5_3-0.1.0.iaf"
|
||||
assert_exit_code 0, out
|
||||
delete_keys(unique_key_name)
|
||||
end
|
||||
end
|
||||
|
||||
def delete_keys(unique_key_name)
|
||||
File.delete("#{Inspec.config_dir}/keys/#{unique_key_name}.pem.key") if File.exist?("#{Inspec.config_dir}/keys/#{unique_key_name}.pem.key")
|
||||
File.delete("#{Inspec.config_dir}/keys/#{unique_key_name}.pem.pub") if File.exist?("#{Inspec.config_dir}/keys/#{unique_key_name}.pem.pub")
|
||||
|
|
Loading…
Add table
Reference in a new issue