Skip to content

Commit

Permalink
Merge pull request #1281 from presidentbeef/template_render_path_test…
Browse files Browse the repository at this point in the history
…_coverage

Adjust JSON tests for template info in render path
  • Loading branch information
presidentbeef committed Nov 13, 2018
2 parents dd0b5d2 + 3d5159f commit bb060e3
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions test/tests/json_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class JSONOutputTests < Minitest::Test
def setup
@@json ||= JSON.parse(Brakeman.run("#{TEST_PATH}/apps/rails4").report.to_json)
@@json ||= JSON.parse(Brakeman.run("#{TEST_PATH}/apps/rails3.2").report.to_json)
end

def test_for_render_path
Expand All @@ -14,23 +14,25 @@ def test_for_render_path
end

def test_for_render_path_keys
controller_keys = %w[type class method line file].sort
template_keys = %w[type name line file].sort
controller_keys = %w[type class method line file rendered].sort
template_keys = %w[type name line file rendered].sort
rendered_keys = %w[name file].sort

@@json["warnings"].each do |warning|
if rp = warning["render_path"]
case rp["type"]
when "controller"
assert_equal controller_keys, rp.keys.sort
when "template"
assert_equal template_keys, rp.keys.sort
else
raise "Unknown render path type: #{rp["type"]}"
end
if warning["render_path"]
warning["render_path"].each do |rp|
case rp["type"]
when "controller"
assert_equal controller_keys, rp.keys.sort
when "template"
assert_equal template_keys, rp.keys.sort
else
raise "Unknown render path type: #{rp["type"]}"
end

if rp["rendered"]
assert_equal rendered_keys, rp["rendered"].keys.sort
if rp["rendered"]
assert_equal rendered_keys, rp["rendered"].keys.sort
end
end
end
end
Expand Down Expand Up @@ -62,7 +64,8 @@ def test_for_errors
end

def test_for_obsolete
assert_equal ["abcdef01234567890ba28050e7faf1d54f218dfa9435c3f65f47cb378c18cf98"], @@json["obsolete"]
json = JSON.parse(Brakeman.run("#{TEST_PATH}/apps/rails4").report.to_json)
assert_equal ["abcdef01234567890ba28050e7faf1d54f218dfa9435c3f65f47cb378c18cf98"], json["obsolete"]
end

def test_paths
Expand Down

0 comments on commit bb060e3

Please sign in to comment.