From 4ddcc7ac01a23338be5330274fdec7d3f53093a5 Mon Sep 17 00:00:00 2001 From: joshua-ostrom Date: Wed, 17 May 2023 09:28:08 -0400 Subject: [PATCH] Cleanup --- lib/salus/scanners/brakeman.rb | 2 +- lib/sarif/base_sarif.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/salus/scanners/brakeman.rb b/lib/salus/scanners/brakeman.rb index fffa1920..b4b8760e 100644 --- a/lib/salus/scanners/brakeman.rb +++ b/lib/salus/scanners/brakeman.rb @@ -113,7 +113,7 @@ def merged_ignore_file_contents def ignore_list return [] unless user_supplied_ignore? - # ADDED THIS LINE UNTIL PUBLIC SALUS HAS IT + return [] unless File.exist?(@config['ignore']) data = JSON.parse(File.read(@config['ignore'])) return [] unless data.key?('ignored_warnings') diff --git a/lib/sarif/base_sarif.rb b/lib/sarif/base_sarif.rb index 9e61736d..3d9bd476 100644 --- a/lib/sarif/base_sarif.rb +++ b/lib/sarif/base_sarif.rb @@ -84,7 +84,7 @@ def uri_info def build_result(parsed_issue) result = { "ruleId": parsed_issue[:id], - "ruleIndex": @mapped_rules[parsed_issue[:id]], # this is wrong + "ruleIndex": @mapped_rules[parsed_issue[:id]], "level": sarif_level(parsed_issue[:level]), "message": { "text": parsed_issue[:details] @@ -116,7 +116,6 @@ def build_result(parsed_issue) def build_rule(parsed_issue) # only include one entry per rule id if !@mapped_rules.include?(parsed_issue[:id]) - # puts "mapped rules #{@mapped_rules.keys} do not include #{parsed_issue[:id]}" rule = { "id": parsed_issue[:id], "name": parsed_issue[:name], @@ -130,7 +129,6 @@ def build_rule(parsed_issue) "markdown": "[More info](#{parsed_issue[:help_url]})." } } - # puts "Setting @mapped_rules[#{parsed_issue[:id]}] to @rule_index (#{@rule_index}) vs #{@mapped_rules.size}" @mapped_rules[parsed_issue[:id]] = @rule_index @rule_index += 1 rule[:fullDescription][:text] = "errors reported by scanner" if rule[:id] == SCANNER_ERROR @@ -155,7 +153,6 @@ def build_runs_object(supported) rule = build_rule(parsed_issue) rules << rule if rule - result = build_result(parsed_issue) # Add suppresion object for suppressed results @@ -173,12 +170,15 @@ def build_runs_object(supported) # Salus::ScanReport invocation = build_invocations(@scan_report, supported) runs_object = { - "tool" => build_tool(rules: rules.deep_sort), + "tool" => build_tool(rules: rules.deep_sort), # we deep sort here as + # our SARIF needs to be deep sorted for easier comparisions "conversion" => build_conversion, "results" => results, "invocations" => [invocation], "originalUriBaseIds" => uri_info } + # Ensure our ruleIndex values are correct after the + # prior deep sorting remap_rule_ids(runs_object) end