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:
Vasundhara Jagdale 2022-09-20 20:03:10 +05:30 committed by GitHub
parent 361c19a006
commit 572524b7ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View file

@ -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)

View file

@ -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")