instiki/vendor/rails/actionpack/test/controller/filter_params_test.rb

50 lines
2 KiB
Ruby
Raw Normal View History

require 'abstract_unit'
2007-01-22 14:43:50 +01:00
class FilterParamController < ActionController::Base
end
class FilterParamTest < Test::Unit::TestCase
def setup
@controller = FilterParamController.new
end
2008-06-02 08:35:38 +02:00
2007-01-22 14:43:50 +01:00
def test_filter_parameters
assert FilterParamController.respond_to?(:filter_parameter_logging)
assert !@controller.respond_to?(:filter_parameters)
2008-06-02 08:35:38 +02:00
2007-01-22 14:43:50 +01:00
FilterParamController.filter_parameter_logging
assert @controller.respond_to?(:filter_parameters)
2008-06-02 08:35:38 +02:00
2007-01-22 14:43:50 +01:00
test_hashes = [[{},{},[]],
[{'foo'=>nil},{'foo'=>nil},[]],
2007-01-22 14:43:50 +01:00
[{'foo'=>'bar'},{'foo'=>'bar'},[]],
[{'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']]
2008-06-02 08:35:38 +02:00
2007-01-22 14:43:50 +01:00
test_hashes.each do |before_filter, after_filter, filter_words|
FilterParamController.filter_parameter_logging(*filter_words)
assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter)
2008-06-02 08:35:38 +02:00
2007-01-22 14:43:50 +01:00
filter_words.push('blah')
FilterParamController.filter_parameter_logging(*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, @controller.__send__(:filter_parameters, before_filter)
2007-01-22 14:43:50 +01:00
end
end
2008-06-02 08:35:38 +02:00
def test_filter_parameters_is_protected
FilterParamController.filter_parameter_logging(:foo)
assert !FilterParamController.action_methods.include?('filter_parameters')
assert_raise(NoMethodError) { @controller.filter_parameters([{'password' => '[FILTERED]'}]) }
end
2007-01-22 14:43:50 +01:00
end