<commit_before>require 'test_helper'
require 'action_controller/parameters'

class ParametersTaintTest < ActiveSupport::TestCase
  setup do
    @params = ActionController::Parameters.new({ :person => {
      :age => "32", :name => { :first => "David", :last => "<NAME>" }
    }})
  end

  test "fetch raises ParameterMissing exception" do
    e = assert_raises(ActionController::ParameterMissing) do
      @params.fetch :foo
    end
    assert_equal :foo, e.param
  end

  test "fetch doesnt raise ParameterMissing exception if there is a default" do
    assert_nothing_raised do
      assert_equal "monkey", @params.fetch(:foo, "monkey")
      assert_equal "monkey", @params.fetch(:foo) { "monkey" }
    end
  end

  test "permitted is sticky on accessors" do
    assert !@params.slice(:person).permitted?
    assert !@params[:person][:name].permitted?

    @params.each { |key, value| assert(!value.permitted?) if key == "person" }

    assert !@params.fetch(:person).permitted?

    assert !@params.values_at(:person).first.permitted?
  end

  test "permitted is sticky on mutators" do
    assert !@params.delete_if { |k, v| k == "person" }.permitted?
    assert !@params.keep_if { |k, v| k == "person" }.permitted?
  end

  test "permitted is sticky beyond merges" do
    assert !@params.merge(:a => "b").permitted?
  end
<commit_msg>Current tests are testing stickiness of non-permitted parameters<commit_after>require 'test_helper'
require 'action_controller/parameters'

class ParametersTaintTest < ActiveSupport::TestCase
  setup do
    @params = ActionController::Parameters.new({ :person => {
      :age => "32", :name => { :first => "David", :last => "<NAME>" }
    }})
  end

  test "fetch raises ParameterMissing exception" do
    e = assert_raises(ActionController::ParameterMissing) do
      @params.fetch :foo
    end
    assert_equal :foo, e.param
  end

  test "fetch doesnt raise ParameterMissing exception if there is a default" do
    assert_nothing_raised do
      assert_equal "monkey", @params.fetch(:foo, "monkey")
      assert_equal "monkey", @params.fetch(:foo) { "monkey" }
    end
  end

  test "not permitted is sticky on accessors" do
    assert !@params.slice(:person).permitted?
    assert !@params[:person][:name].permitted?

    @params.each { |key, value| assert(!value.permitted?) if key == "person" }

    assert !@params.fetch(:person).permitted?

    assert !@params.values_at(:person).first.permitted?
  end

  test "not permitted is sticky on mutators" do
    assert !@params.delete_if { |k, v| k == "person" }.permitted?
    assert !@params.keep_if { |k, v| k == "person" }.permitted?
  end

  test "not permitted is sticky beyond merges" do
    assert !@params.merge(:a => "b").permitted?
  end

{'fraction_non_alphanumeric': 0.13472070098576122, 'fraction_numerical': 0.0014603870025556773, 'mean_word_length': 3.8409893992932864, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5191128', 'n_tokens_mistral': 876, 'n_tokens_neox': 843, 'n_words': 242}