Skip to content

Commit d6c99c7

Browse files
committed
Test for Rails 5.2 CSRF warning with no defaults
1 parent 022a0c9 commit d6c99c7

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

test/tests/rails52_csrf.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require_relative '../test'
2+
require 'brakeman/rescanner'
3+
4+
class Rails52CSRFTest < Minitest::Test
5+
include BrakemanTester::RescanTestHelper
6+
include BrakemanTester::FindWarning
7+
8+
def report
9+
@report
10+
end
11+
12+
def test_csrf_with_no_load_defaults
13+
tracker = nil
14+
15+
# Terribly abusing the rescan functionality here.
16+
# Actually don't want the rescan, just want to run a regular scan
17+
# because we don't have the capability to rescan with on config changes
18+
# like this and I don't feel like building it right now.
19+
before_rescan_of ['config/application.rb'], 'rails5.2' do |app_dir|
20+
replace 'config/application.rb', 'config.load_defaults 5.2', ''
21+
tracker = Brakeman.run(app_path: app_dir, parallel_checks: false)
22+
end
23+
24+
@report = tracker.report.to_hash
25+
26+
assert_warning check_name: "ForgerySetting",
27+
type: :controller,
28+
warning_code: 7,
29+
fingerprint: "6f5239fb87c64764d0c209014deb5cf504c2c10ee424bd33590f0a4f22e01d8f",
30+
warning_type: "Cross-Site Request Forgery",
31+
line: 1,
32+
message: /^`protect_from_forgery`\ should\ be\ called\ /,
33+
confidence: 0,
34+
relative_path: "app/controllers/application_controller.rb",
35+
code: nil,
36+
user_input: nil
37+
end
38+
end

0 commit comments

Comments
 (0)