|
1 | 1 | require_relative '../test' |
| 2 | +require 'brakeman/rescanner' |
2 | 3 | require 'json' |
3 | 4 |
|
4 | 5 | class JSONCompareTests < Minitest::Test |
| 6 | + include BrakemanTester::RescanTestHelper |
5 | 7 | include BrakemanTester::DiffHelper |
6 | 8 |
|
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 | + ] |
19 | 15 |
|
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]) |
25 | 21 |
|
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' |
29 | 24 |
|
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 |
32 | 29 |
|
33 | | - assert_fixed 0 |
| 30 | + assert_fixed 7 |
34 | 31 | assert_new 0 |
| 32 | + assert_equal ignored_warnings, @diff[:obsolete] |
| 33 | + |
| 34 | + # Man is obsolete! |
| 35 | + # Our world, obsolete! |
35 | 36 | end |
36 | 37 | end |
0 commit comments