diff --git a/Gemfile.lock b/Gemfile.lock index f926a32..7ae6cde 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,7 +9,7 @@ GIT PATH remote: . specs: - redaction (0.2.0) + redaction (0.3.0) faker (>= 2.20.0) rails (>= 5.1.0) ruby-progressbar (>= 1.11.0) @@ -17,67 +17,67 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (7.0.2.4) - actionpack (= 7.0.2.4) - activesupport (= 7.0.2.4) + actioncable (7.0.4) + actionpack (= 7.0.4) + activesupport (= 7.0.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.2.4) - actionpack (= 7.0.2.4) - activejob (= 7.0.2.4) - activerecord (= 7.0.2.4) - activestorage (= 7.0.2.4) - activesupport (= 7.0.2.4) + actionmailbox (7.0.4) + actionpack (= 7.0.4) + activejob (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.2.4) - actionpack (= 7.0.2.4) - actionview (= 7.0.2.4) - activejob (= 7.0.2.4) - activesupport (= 7.0.2.4) + actionmailer (7.0.4) + actionpack (= 7.0.4) + actionview (= 7.0.4) + activejob (= 7.0.4) + activesupport (= 7.0.4) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.2.4) - actionview (= 7.0.2.4) - activesupport (= 7.0.2.4) + actionpack (7.0.4) + actionview (= 7.0.4) + activesupport (= 7.0.4) rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.2.4) - actionpack (= 7.0.2.4) - activerecord (= 7.0.2.4) - activestorage (= 7.0.2.4) - activesupport (= 7.0.2.4) + actiontext (7.0.4) + actionpack (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.2.4) - activesupport (= 7.0.2.4) + actionview (7.0.4) + activesupport (= 7.0.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.2.4) - activesupport (= 7.0.2.4) + activejob (7.0.4) + activesupport (= 7.0.4) globalid (>= 0.3.6) - activemodel (7.0.2.4) - activesupport (= 7.0.2.4) - activerecord (7.0.2.4) - activemodel (= 7.0.2.4) - activesupport (= 7.0.2.4) - activestorage (7.0.2.4) - actionpack (= 7.0.2.4) - activejob (= 7.0.2.4) - activerecord (= 7.0.2.4) - activesupport (= 7.0.2.4) + activemodel (7.0.4) + activesupport (= 7.0.4) + activerecord (7.0.4) + activemodel (= 7.0.4) + activesupport (= 7.0.4) + activestorage (7.0.4) + actionpack (= 7.0.4) + activejob (= 7.0.4) + activerecord (= 7.0.4) + activesupport (= 7.0.4) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.2.4) + activesupport (7.0.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -90,17 +90,16 @@ GEM builder (3.2.4) concurrent-ruby (1.1.10) crass (1.0.6) - digest (3.1.0) encryptor (3.0.0) - erubi (1.10.0) - faker (2.20.0) + erubi (1.11.0) + faker (3.0.0) i18n (>= 1.8.11, < 2) globalid (1.0.0) activesupport (>= 5.0) - i18n (1.10.0) + i18n (1.12.0) concurrent-ruby (~> 1.0) lockbox (0.6.8) - loofah (2.18.0) + loofah (2.19.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -108,55 +107,49 @@ GEM marcel (1.0.2) method_source (1.0.0) mini_mime (1.1.2) - mini_portile2 (2.8.0) - minitest (5.15.0) - net-imap (0.2.3) - digest + minitest (5.16.3) + net-imap (0.3.1) net-protocol - strscan - net-pop (0.1.1) - digest + net-pop (0.1.2) net-protocol - timeout net-protocol (0.1.3) timeout - net-smtp (0.3.1) - digest + net-smtp (0.3.3) net-protocol - timeout nio4r (2.5.8) - nokogiri (1.13.3) - mini_portile2 (~> 2.8.0) + nokogiri (1.13.9-arm64-darwin) + racc (~> 1.4) + nokogiri (1.13.9-x86_64-darwin) racc (~> 1.4) parallel (1.21.0) parser (3.1.0.0) ast (~> 2.4.1) racc (1.6.0) - rack (2.2.3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (7.0.2.4) - actioncable (= 7.0.2.4) - actionmailbox (= 7.0.2.4) - actionmailer (= 7.0.2.4) - actionpack (= 7.0.2.4) - actiontext (= 7.0.2.4) - actionview (= 7.0.2.4) - activejob (= 7.0.2.4) - activemodel (= 7.0.2.4) - activerecord (= 7.0.2.4) - activestorage (= 7.0.2.4) - activesupport (= 7.0.2.4) + rack (2.2.4) + rack-test (2.0.2) + rack (>= 1.3) + rails (7.0.4) + actioncable (= 7.0.4) + actionmailbox (= 7.0.4) + actionmailer (= 7.0.4) + actionpack (= 7.0.4) + actiontext (= 7.0.4) + actionview (= 7.0.4) + activejob (= 7.0.4) + activemodel (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) bundler (>= 1.15.0) - railties (= 7.0.2.4) + railties (= 7.0.4) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) + rails-html-sanitizer (1.4.3) loofah (~> 2.3) - railties (7.0.2.4) - actionpack (= 7.0.2.4) - activesupport (= 7.0.2.4) + railties (7.0.4) + actionpack (= 7.0.4) + activesupport (= 7.0.4) method_source rake (>= 12.2) thor (~> 1.0) @@ -184,16 +177,15 @@ GEM standard (1.7.2) rubocop (= 1.25.1) rubocop-performance (= 1.13.2) - strscan (3.0.1) thor (1.2.1) - timeout (0.2.0) - tzinfo (2.0.4) + timeout (0.3.0) + tzinfo (2.0.5) concurrent-ruby (~> 1.0) unicode-display_width (2.1.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.5.4) + zeitwerk (2.6.6) PLATFORMS arm64-darwin-21 diff --git a/lib/redaction/railtie.rb b/lib/redaction/railtie.rb index 3e47617..65c98e9 100644 --- a/lib/redaction/railtie.rb +++ b/lib/redaction/railtie.rb @@ -13,6 +13,7 @@ class Railtie < ::Rails::Railtie options.email_domain = options.email_domain options.progress_bar = options.key?(:progress_bar) ? options.progress_bar : true + options.force_redaction = options.key?(:force_redaction) ? options.force_redaction : false ActiveSupport.on_load(:active_record) do include Redaction::Redactable diff --git a/lib/redaction/redactable.rb b/lib/redaction/redactable.rb index 76e289e..1d6bb9f 100644 --- a/lib/redaction/redactable.rb +++ b/lib/redaction/redactable.rb @@ -17,7 +17,7 @@ def redact! redactor = Redaction.find(redactor_type) attributes.each do |attribute| - if send(attribute).present? + if Redaction.config.force_redaction || send(attribute).present? send("#{attribute}=", redactor.call(self, {attribute: attribute})) end end diff --git a/test/redaction_test.rb b/test/redaction_test.rb index ebd64f9..e94bf6a 100644 --- a/test/redaction_test.rb +++ b/test/redaction_test.rb @@ -276,4 +276,17 @@ class RedactionTest < ActiveSupport::TestCase assert_not_equal "", out end + + test "it generates redacted content even if the attribute is empty if configured" do + Redaction.config.force_redaction = true + + user = users(:one) + user.update(email: nil) + user.redact! + + Redaction.config.force_redaction = false # Reset + + assert_not_nil user.email + assert_match(/@/, user.email) + end end