Skip to content

Commit

Permalink
Merge pull request #1621 from eliblock/eb/fix-1588
Browse files Browse the repository at this point in the history
fix(sarifOutput): nil-safe render_message
  • Loading branch information
presidentbeef committed Jul 16, 2021
2 parents d46a0d6 + ffb7f65 commit 0448534
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/brakeman/report/report_sarif.rb
Expand Up @@ -111,6 +111,8 @@ def render_id warning
end

def render_message message
return message if message.nil?

# Ensure message ends with a period
if message.end_with? "."
message
Expand Down
14 changes: 13 additions & 1 deletion test/tests/sarif_output.rb
Expand Up @@ -2,11 +2,23 @@
require 'json'

class SARIFOutputTests < Minitest::Test

def tracker_3_2
@@tracker_3_2 ||= Brakeman.run("#{TEST_PATH}/apps/rails3.2") # has no brakeman.ignore
end

def setup
@@sarif ||= JSON.parse(Brakeman.run(File.join(TEST_PATH, 'apps', 'rails3.2')).report.to_sarif) # has no brakeman.ignore
@@sarif ||= JSON.parse(tracker_3_2.report.to_sarif)
@@sarif_with_ignore ||= JSON.parse(Brakeman.run(File.join(TEST_PATH, 'apps', 'rails4')).report.to_sarif) # has ignored warnings
end

def test_render_message
report = Brakeman::Report::SARIF.new tracker_3_2
assert_nil report.render_message(nil)
assert_equal 'Very serious sentence.', report.render_message('Very serious sentence')
assert_equal 'Nothing to see here.', report.render_message('Nothing to see here.')
end

def test_log_shape
assert_equal '2.1.0', @@sarif['version']
assert_equal 'https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json', @@sarif['$schema']
Expand Down

0 comments on commit 0448534

Please sign in to comment.