Sha256: f2cad7a89726083982f249880dfd100d9bd6a49fb0fbfdc9f8da61d88d98710d

Contents?: true

Size: 1.97 KB

Versions: 16

Compression:

Stored size: 1.97 KB

Contents

require 'abstract_unit'

class FilterParamController < ActionController::Base
end

class FilterParamTest < Test::Unit::TestCase
  def setup
    @controller = FilterParamController.new
  end

  def test_filter_parameters
    assert FilterParamController.respond_to?(:filter_parameter_logging)
    assert !@controller.respond_to?(:filter_parameters)

    FilterParamController.filter_parameter_logging
    assert @controller.respond_to?(:filter_parameters)

    test_hashes = [[{},{},[]],
    [{'foo'=>nil},{'foo'=>nil},[]],
    [{'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']]

    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)

      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)
    end
  end

  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
end

Version data entries

16 entries across 15 versions & 8 rubygems

Version Path
elkinsware-erubis_rails_helper-0.6.0 test/controller/filter_params_test.rb
elkinsware-erubis_rails_helper-0.6.1 test/controller/filter_params_test.rb
elkinsware-erubis_rails_helper-0.9.0 test/controller/filter_params_test.rb
elkinsware-erubis_rails_helper-0.9.1 test/controller/filter_params_test.rb
elkinsware-erubis_rails_helper-0.9.5 test/controller/filter_params_test.rb
ghazel-erubis_rails_helper-0.9.5 test/controller/filter_params_test.rb
mitio-erubis_rails_helper-1.0.1 test/controller/filter_params_test.rb
erubis_rails_helper-1.0.0 test/controller/filter_params_test.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/actionpack/test/controller/filter_params_test.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/actionpack/pkg/actionpack-2.2.2/test/controller/filter_params_test.rb
ghazel-erubis_rails_helper-0.9.5.1 test/controller/filter_params_test.rb
actionpack-2.2.3 test/controller/filter_params_test.rb
webroar-0.2.2 src/admin_panel/vendor/rails/actionpack/test/controller/filter_params_test.rb
actionpack-2.3.2 test/controller/filter_params_test.rb
actionpack-2.2.2 test/controller/filter_params_test.rb
radiant-0.8.0 vendor/rails/actionpack/test/controller/filter_params_test.rb