Skip to content

Commit

Permalink
Merge pull request #83 from daveworth/nowarn_update_attributes
Browse files Browse the repository at this point in the history
Stop alerting for Mass Assignment on `#update_attribute`
  • Loading branch information
presidentbeef committed Apr 19, 2012
2 parents 85e5216 + 73b9d2b commit 1d93763
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/brakeman/checks/check_mass_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def run_check
Brakeman.debug "Finding possible mass assignment calls on #{models.length} models"
calls = tracker.find_call :chained => true, :targets => models, :methods => [:new,
:attributes=,
:update_attribute,
:update_attributes,
:update_attributes!,
:create,
Expand Down
1 change: 0 additions & 1 deletion lib/brakeman/checks/check_without_protection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def run_check
Brakeman.debug "Finding all mass assignments"
calls = tracker.find_call :targets => models, :methods => [:new,
:attributes=,
:update_attribute,
:update_attributes,
:update_attributes!,
:create,
Expand Down
5 changes: 5 additions & 0 deletions test/apps/rails2/app/controllers/other_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ def test_iteration
def test_send_file
send_file params[:file]
end

def test_update_attribute
@user = User.first
@user.update_attribute(:attr, params[:attr])
end
end
5 changes: 5 additions & 0 deletions test/apps/rails3/app/controllers/other_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ def test_iteration
def test_send_file
send_file params[:file]
end

def test_update_attribute
@user = User.first
@user.update_attribute(:attr, params[:attr])
end
end
9 changes: 9 additions & 0 deletions test/tests/test_rails2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ def test_mass_assignment
:file => /home_controller\.rb/
end

def test_update_attribute_no_mass_assignment
assert_no_warning :type => :warning,
:warning_type => "Mass Assignment",
:line => 26,
:message => /^Unprotected mass assignment/,
:confidence => 0,
:file => /other_controller\.rb/
end

def test_redirect
assert_warning :type => :warning,
:warning_type => "Redirect",
Expand Down
9 changes: 9 additions & 0 deletions test/tests/test_rails3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ def test_protected_mass_assignment_update
:file => /products_controller\.rb/
end

def test_update_attribute_no_mass_assignment
assert_no_warning :type => :warning,
:warning_type => "Mass Assignment",
:line => 26,
:message => /^Unprotected mass assignment near line 26/,
:confidence => 0,
:file => /other_controller\.rb/
end

def test_redirect
assert_warning :type => :warning,
:warning_type => "Redirect",
Expand Down

0 comments on commit 1d93763

Please sign in to comment.