Skip to content

Commit 98885f3

Browse files
Add obsolete entries to comparison report (#1777)
Fixes #1758
1 parent a301e6a commit 98885f3

3 files changed

Lines changed: 31 additions & 26 deletions

File tree

lib/brakeman.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,14 @@ def self.compare options
493493
end
494494

495495
tracker = run(options)
496+
new_report = JSON.parse(tracker.report.to_json, symbolize_names: true)
496497

497-
new_results = JSON.parse(tracker.report.to_json, :symbolize_names => true)[:warnings]
498+
new_results = new_report[:warnings]
499+
obsolete_ignored = tracker.unused_fingerprints
498500

499-
Brakeman::Differ.new(new_results, previous_results).diff
501+
Brakeman::Differ.new(new_results, previous_results).diff.tap do |diff|
502+
diff[:obsolete] = obsolete_ignored
503+
end
500504
end
501505

502506
def self.load_brakeman_dependency name, allow_fail = false

test/test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def before_rescan_of changed, app = "rails3.2", options = {}
176176
begin
177177
yield dir if block_given?
178178

179-
# Not reqally sure why we do this..?
179+
# Not really sure why we do this..?
180180
t = Marshal.load(Marshal.dump(@original))
181181

182182
@rescanner = Brakeman::Rescanner.new(t.options, t.processor, changed)

test/tests/json_compare.rb

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
require_relative '../test'
2+
require 'brakeman/rescanner'
23
require 'json'
34

45
class JSONCompareTests < Minitest::Test
6+
include BrakemanTester::RescanTestHelper
57
include BrakemanTester::DiffHelper
68

7-
def setup
8-
@path = File.expand_path "#{TEST_PATH}/apps/rails3.2"
9-
@json_path = File.join @path, "doesnt_exist", "report.json"
10-
teardown # just to be sure
11-
Brakeman.run :app_path => @path, :output_files => [@json_path]
12-
@report = JSON.parse File.read(@json_path)
13-
end
14-
15-
def teardown
16-
File.delete @json_path if File.exist? @json_path
17-
Dir.delete File.dirname(@json_path) if Dir.exist? File.dirname(@json_path)
18-
end
9+
def test_sanity
10+
json_report = 'test-report.json'
11+
ignored_warnings = [
12+
'cd83ecf615b17f849ba28050e7faf1d54f218dfa9435c3f65f47cb378c18cf98',
13+
'abcdef01234567890ba28050e7faf1d54f218dfa9435c3f65f47cb378c18cf98'
14+
]
1915

20-
def update_json
21-
File.open @json_path, "w" do |f|
22-
f.puts @report.to_json
23-
end
24-
end
16+
# Here I go, abusing the rescan functionality again.
17+
before_rescan_of ['app/models/account.rb', json_report], 'rails4' do |app_dir|
18+
first = Brakeman.run(app_path: app_dir,
19+
parallel_checks: false,
20+
output_files: [json_report])
2521

26-
def diff
27-
@diff = Brakeman.compare :app_path => @path, :previous_results_json => @json_path
28-
end
22+
write_file json_report, first.report.to_json
23+
remove 'app/models/account.rb'
2924

30-
def test_sanity
31-
diff
25+
@diff = Brakeman.compare(app_path: app_dir,
26+
parallel_checks: false,
27+
previous_results_json: json_report)
28+
end
3229

33-
assert_fixed 0
30+
assert_fixed 7
3431
assert_new 0
32+
assert_equal ignored_warnings, @diff[:obsolete]
33+
34+
# Man is obsolete!
35+
# Our world, obsolete!
3536
end
3637
end

0 commit comments

Comments
 (0)