aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2010-01-21 04:37:10 +0700
committerJosé Valim <jose.valim@gmail.com>2010-01-21 10:08:26 +0100
commitbd4f21fbac495fb28b6be993be808509e567239e (patch)
treefacad12a926cd08f40ebf97da6d336cb8e03e6d9 /actionpack/test/dispatch
parentfa9f000246c2f6010f18bf40237d105b782873e2 (diff)
downloadrails-bd4f21fbac495fb28b6be993be808509e567239e.tar.gz
rails-bd4f21fbac495fb28b6be993be808509e567239e.tar.bz2
rails-bd4f21fbac495fb28b6be993be808509e567239e.zip
Move filter_parameter_logging logic out of the controller and create ActionDispatch::ParametersFilter to handle parameter filteration instead. This will make filteration not depending on controller anymore.
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/request_test.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb
index cb95ecea50..0a6180959e 100644
--- a/actionpack/test/dispatch/request_test.rb
+++ b/actionpack/test/dispatch/request_test.rb
@@ -453,6 +453,40 @@ class RequestTest < ActiveSupport::TestCase
request.expects(:parameters).at_least_once.returns({})
assert_equal Mime::XML, request.negotiate_mime([Mime::XML, Mime::CSV])
end
+
+ test "filter_parameters" do
+ request = stub_request
+ request.stubs(:request_parameters).returns({ "foo" => 1 })
+ request.stubs(:query_parameters).returns({ "bar" => 2 })
+
+ assert_raises RuntimeError do
+ ActionDispatch::Http::ParametersFilter.filter_parameters
+ end
+
+ test_hashes = [
+ [{'foo'=>'bar'},{'foo'=>'bar'},%w'food'],
+ [{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'],
+ [{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'],
+ [{'foo'=>'bar', 'baz'=>'foo'},{'foo'=>'[FILTERED]', 'baz'=>'[FILTERED]'},%w'foo baz'],
+ [{'bar'=>{'foo'=>'bar','bar'=>'foo'}},{'bar'=>{'foo'=>'[FILTERED]','bar'=>'foo'}},%w'fo'],
+ [{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana'],
+ [{'baz'=>[{'foo'=>'baz'}]}, {'baz'=>[{'foo'=>'[FILTERED]'}]}, %w(foo)]]
+
+ test_hashes.each do |before_filter, after_filter, filter_words|
+ ActionDispatch::Http::ParametersFilter.filter_parameters(*filter_words)
+ assert_equal after_filter, request.__send__(:process_parameter_filter, before_filter)
+
+ filter_words.push('blah')
+ ActionDispatch::Http::ParametersFilter.filter_parameters(*filter_words) do |key, value|
+ value.reverse! if key =~ /bargain/
+ end
+
+ before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}}
+ after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}}
+
+ assert_equal after_filter, request.__send__(:process_parameter_filter, before_filter)
+ end
+ end
protected