mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
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:
commit
984ebc4075
3 changed files with 13 additions and 9 deletions
|
@ -95,6 +95,8 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
||||||
desc "check PATH", "verify all tests at the specified PATH"
|
desc "check PATH", "verify all tests at the specified PATH"
|
||||||
option :format, type: :string,
|
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."
|
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
|
profile_options
|
||||||
def check(path) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
def check(path) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
||||||
o = config
|
o = config
|
||||||
|
|
|
@ -105,6 +105,7 @@ module Inspec
|
||||||
@check_mode = options[:check_mode] || false
|
@check_mode = options[:check_mode] || false
|
||||||
@parent_profile = options[:parent_profile]
|
@parent_profile = options[:parent_profile]
|
||||||
@legacy_profile_path = options[:profiles_path] || false
|
@legacy_profile_path = options[:profiles_path] || false
|
||||||
|
@check_cookstyle = options[:with_cookstyle]
|
||||||
Metadata.finalize(@source_reader.metadata, @profile_id, options)
|
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
|
# 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
|
end
|
||||||
|
|
||||||
# Running cookstyle to check for code offenses
|
# Running cookstyle to check for code offenses
|
||||||
cookstyle_linting_check.each do |lint_output|
|
if @check_cookstyle
|
||||||
data = lint_output.split(":")
|
cookstyle_linting_check.each do |lint_output|
|
||||||
msg = "#{data[-2]}:#{data[-1]}"
|
data = lint_output.split(":")
|
||||||
offense.call(data[0], data[1], data[2], nil, msg)
|
msg = "#{data[-2]}:#{data[-1]}"
|
||||||
|
offense.call(data[0], data[1], data[2], nil, msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# profile is valid if we could not find any error & offenses
|
# profile is valid if we could not find any error & offenses
|
||||||
result[:summary][:valid] = result[:errors].empty? && result[:offenses].empty?
|
result[:summary][:valid] = result[:errors].empty? && result[:offenses].empty?
|
||||||
|
|
||||||
|
|
|
@ -118,16 +118,16 @@ describe "inspec check" do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "inspec check also check for cookstyle offenses" do
|
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
|
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/)
|
_(out.stdout).must_match(/No errors, warnings, or offenses/)
|
||||||
assert_exit_code 0, out
|
assert_exit_code 0, out
|
||||||
end
|
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
|
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/)
|
_(out.stdout).must_match(/1 offenses/)
|
||||||
assert_exit_code 1, out
|
assert_exit_code 1, out
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue