Skip to content

Commit

Permalink
feat: Add config option to force redaction. (#23)
Browse files Browse the repository at this point in the history
Add ability to force redaction even if attribute value is blank.
  • Loading branch information
DRBragg authored Nov 10, 2022
1 parent b27ce23 commit 0dbb4bc
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 81 deletions.
152 changes: 72 additions & 80 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,75 +9,75 @@ 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)

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)
Expand All @@ -90,73 +90,66 @@ 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)
mini_mime (>= 0.1.1)
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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/redaction/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/redaction/redactable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/redaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0dbb4bc

Please sign in to comment.