Skip to content

Commit

Permalink
Only filter out fatal errors rather than actual violations (#556)
Browse files Browse the repository at this point in the history
* Only filter out fatal errors rather than actual violations
Fixes #555

* Add tests
  • Loading branch information
Kevin Formsma authored Jun 15, 2021
1 parent dde65bf commit 6eaefdd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/cfn-nag/cfn_nag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def audit(cloudformation_string:, parameter_values_string: nil, condition_values
end

def prune_fatal_violations(violations)
violations.reject { |violation| violation.type == Violation::FAILING_VIOLATION }
violations.reject { |violation| violation.id == 'FATAL' }
end

def render_results(aggregate_results:,
Expand Down
31 changes: 30 additions & 1 deletion spec/cfn_nag_integration/cfn_nag_executor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@
cli_options = @default_cli_options.clone
cli_options[:input_path] = 'spec/test_templates/json/neptune'
expect(Options).to receive(:scan_options).and_return(cli_options)
puts cli_options

cfn_nag_executor = CfnNagExecutor.new

Expand Down Expand Up @@ -200,4 +199,34 @@
expect {Options.for('invalid')}.to raise_error(RuntimeError)
end
end

context 'multi file cfn_nag with ignore fatal' do
it 'returns failed result' do
cli_options = @default_cli_options.clone
cli_options[:input_path] = 'spec/test_templates/yaml/ignore_fatal'
cli_options[:ignore_fatal] = true
expect(Options).to receive(:scan_options).and_return(cli_options)

cfn_nag_executor = CfnNagExecutor.new

result = cfn_nag_executor.scan(options_type: 'scan')

expect(result).to eq 1
end
end

context 'multi file cfn_nag not ignornig fatal errors' do
it 'returns two failed results' do
cli_options = @default_cli_options.clone
cli_options[:input_path] = 'spec/test_templates/yaml/ignore_fatal'
cli_options[:ignore_fatal] = false
expect(Options).to receive(:scan_options).and_return(cli_options)

cfn_nag_executor = CfnNagExecutor.new

result = cfn_nag_executor.scan(options_type: 'scan')

expect(result).to eq 2
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
Resources:
IAMUser:
Type: AWS::IAM::User
Properties:
LoginProfile:
PasswordResetRequired: True
4 changes: 4 additions & 0 deletions spec/test_templates/yaml/ignore_fatal/non_cfn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TestYaml:
Hello:
- example
- list

0 comments on commit 6eaefdd

Please sign in to comment.