This commit is contained in:
Rafael Mendonça França 2022-02-25 22:05:28 +00:00
commit 8137932a05
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
3 changed files with 23 additions and 3 deletions

View File

@ -50,9 +50,15 @@ module ActiveRecord
def install_auto_filtered_parameters_hook(application) # :nodoc:
ActiveRecord::Encryption.on_encrypted_attribute_declared do |klass, encrypted_attribute_name|
application.config.filter_parameters << encrypted_attribute_name unless ActiveRecord::Encryption.config.excluded_from_filter_parameters.include?(encrypted_attribute_name)
filter_parameter = [("#{klass.model_name.element}" if klass.name), encrypted_attribute_name.to_s].compact.join(".")
application.config.filter_parameters << filter_parameter unless excluded_from_filter_parameters?(filter_parameter)
end
end
private
def excluded_from_filter_parameters?(filter_parameter)
ActiveRecord::Encryption.config.excluded_from_filter_parameters.find { |excluded_filter| excluded_filter.to_s == filter_parameter }
end
end
end
end

View File

@ -41,7 +41,19 @@ class ActiveRecord::Encryption::ConfigurableTest < ActiveRecord::EncryptionTestC
assert_equal :isbn, @attribute_name
end
test "install autofiltered params" do
test "installing autofiltered parameters will add the encrypted attribute as a filter parameter using the dot notation" do
application = OpenStruct.new(config: OpenStruct.new(filter_parameters: []))
ActiveRecord::Encryption.install_auto_filtered_parameters_hook(application)
NamedPirate = Class.new(Pirate) do
self.table_name = "pirates"
end
NamedPirate.encrypts :catchphrase
assert_includes application.config.filter_parameters, "named_pirate.catchphrase"
end
test "installing autofiltered parameters will work with unnamed classes" do
application = OpenStruct.new(config: OpenStruct.new(filter_parameters: []))
ActiveRecord::Encryption.install_auto_filtered_parameters_hook(application)
@ -50,7 +62,7 @@ class ActiveRecord::Encryption::ConfigurableTest < ActiveRecord::EncryptionTestC
encrypts :catchphrase
end
assert_includes application.config.filter_parameters, :catchphrase
assert_includes application.config.filter_parameters, "catchphrase"
end
test "exclude the installation of autofiltered params" do

View File

@ -241,6 +241,8 @@ end
By default, encrypted columns are configured to be [automatically filtered in Rails logs](https://guides.rubyonrails.org/action_controller_overview.html#parameters-filtering). You can disable this behavior by adding the following to your `application.rb`:
When generating the filter parameter, it will use the model name as a prefix. E.g: For `Person#name` the filter parameter will be `person.name`.
```ruby
config.active_record.encryption.add_to_filter_parameters = false
```