Froze rails gems
[depot.git] / vendor / rails / actionpack / test / controller / filter_params_test.rb
1 require 'abstract_unit'
2
3 class FilterParamController < ActionController::Base
4 end
5
6 class FilterParamTest < Test::Unit::TestCase
7 def setup
8 @controller = FilterParamController.new
9 end
10
11 def test_filter_parameters
12 assert FilterParamController.respond_to?(:filter_parameter_logging)
13 assert !@controller.respond_to?(:filter_parameters)
14
15 FilterParamController.filter_parameter_logging
16 assert @controller.respond_to?(:filter_parameters)
17
18 test_hashes = [[{},{},[]],
19 [{'foo'=>nil},{'foo'=>nil},[]],
20 [{'foo'=>'bar'},{'foo'=>'bar'},[]],
21 [{'foo'=>'bar'},{'foo'=>'bar'},%w'food'],
22 [{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'],
23 [{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'],
24 [{'foo'=>'bar', 'baz'=>'foo'},{'foo'=>'[FILTERED]', 'baz'=>'[FILTERED]'},%w'foo baz'],
25 [{'bar'=>{'foo'=>'bar','bar'=>'foo'}},{'bar'=>{'foo'=>'[FILTERED]','bar'=>'foo'}},%w'fo'],
26 [{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana']]
27
28 test_hashes.each do |before_filter, after_filter, filter_words|
29 FilterParamController.filter_parameter_logging(*filter_words)
30 assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter)
31
32 filter_words.push('blah')
33 FilterParamController.filter_parameter_logging(*filter_words) do |key, value|
34 value.reverse! if key =~ /bargain/
35 end
36
37 before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}}
38 after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}}
39
40 assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter)
41 end
42 end
43
44 def test_filter_parameters_is_protected
45 FilterParamController.filter_parameter_logging(:foo)
46 assert !FilterParamController.action_methods.include?('filter_parameters')
47 assert_raise(NoMethodError) { @controller.filter_parameters([{'password' => '[FILTERED]'}]) }
48 end
49 end