aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/tainted_params_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/controller/tainted_params_test.rb')
-rw-r--r--actionpack/test/controller/tainted_params_test.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/actionpack/test/controller/tainted_params_test.rb b/actionpack/test/controller/tainted_params_test.rb
new file mode 100644
index 0000000000..881b9d40fa
--- /dev/null
+++ b/actionpack/test/controller/tainted_params_test.rb
@@ -0,0 +1,25 @@
+require 'abstract_unit'
+
+class PeopleController < ActionController::Base
+ def create
+ render text: params[:person].permitted? ? "untainted" : "tainted"
+ end
+
+ def create_with_permit
+ render text: params[:person].permit(:name).permitted? ? "untainted" : "tainted"
+ end
+end
+
+class ActionControllerTaintedParamsTest < ActionController::TestCase
+ tests PeopleController
+
+ test "parameters are tainted" do
+ post :create, { person: { name: "Mjallo!" } }
+ assert_equal "tainted", response.body
+ end
+
+ test "parameters can be permitted and are then not tainted" do
+ post :create_with_permit, { person: { name: "Mjallo!" } }
+ assert_equal "untainted", response.body
+ end
+end