Merge pull request #5989 from inspec/vasundhara/fix-compliance-profile-upload

CFINSPEC-181: Fix unable to upload inspec compliance profile using to…
This commit is contained in:
Clinton Wolfe 2022-04-18 17:46:25 -04:00 committed by GitHub
commit 984ebc4075
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View file

@ -95,6 +95,8 @@ class Inspec::InspecCLI < Inspec::BaseCLI
desc "check PATH", "verify all tests at the specified PATH"
option :format, type: :string,
desc: "The output format to use doc (default), json. If valid format is not provided then it will use the default."
option :with_cookstyle, type: :boolean,
desc: "Enable or disable cookstyle checks.", default: false
profile_options
def check(path) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
o = config

View file

@ -105,6 +105,7 @@ module Inspec
@check_mode = options[:check_mode] || false
@parent_profile = options[:parent_profile]
@legacy_profile_path = options[:profiles_path] || false
@check_cookstyle = options[:with_cookstyle]
Metadata.finalize(@source_reader.metadata, @profile_id, options)
# if a backend has already been created, clone it so each profile has its own unique backend object
@ -655,12 +656,13 @@ module Inspec
end
# Running cookstyle to check for code offenses
cookstyle_linting_check.each do |lint_output|
data = lint_output.split(":")
msg = "#{data[-2]}:#{data[-1]}"
offense.call(data[0], data[1], data[2], nil, msg)
if @check_cookstyle
cookstyle_linting_check.each do |lint_output|
data = lint_output.split(":")
msg = "#{data[-2]}:#{data[-1]}"
offense.call(data[0], data[1], data[2], nil, msg)
end
end
# profile is valid if we could not find any error & offenses
result[:summary][:valid] = result[:errors].empty? && result[:offenses].empty?

View file

@ -118,16 +118,16 @@ describe "inspec check" do
end
describe "inspec check also check for cookstyle offenses" do
it "finds no offenses in a complete profile" do
it "finds no offenses in a complete profile when --with-cookstyle option is provided" do
skip if windows? # see #5723
out = inspec("check #{profile_path}/complete-profile")
out = inspec("check #{profile_path}/complete-profile --with-cookstyle")
_(out.stdout).must_match(/No errors, warnings, or offenses/)
assert_exit_code 0, out
end
it "fails and returns offenses in a profile" do
it "fails and returns offenses in a profile when --with-cookstyle option is provided" do
skip if windows? # see #5723
out = inspec("check #{profile_path}/inputs/metadata-basic")
out = inspec("check #{profile_path}/inputs/metadata-basic --with-cookstyle")
_(out.stdout).must_match(/1 offenses/)
assert_exit_code 1, out
end