Coder Social home page Coder Social logo

attr_masker's People

Contributors

bogdanap avatar hsbt avatar kwkwan avatar ribose-jeffreylau avatar ronaldtse avatar skalee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

attr_masker's Issues

Drop support for Rails 4.2 and some older Rubies

The latest Rails 6.1 is two major versions ahead Rails 4.2. Upcoming API changes will be a good occasion to drop support for the latter. Also, we should drop support for some older Rubies, I haven't decided yet which ones.

Upgrade gem version and make release

@skalee since there have been many changes (positive changes) it's probably time to make a release.

Let me know when you're going to bump version, to make a release.

Then we'll change our code to adopt the latest version ๐Ÿ‘

Incompatibility when using attr_masker with attr_encryptor

When the gem is used with another attribute modifier, such as attr_encryptor like below:

attr_encryptor :test_field, key: proc { |k| k.key }
attr_masker :test_field, column_name: :encrypted_test_field
  1. This configuration is highly dependent on the order of definition.
  2. The masker (and the encryptor) will produce an error because the "masked" field is not a valid value to the encryptor (and vice versa)

Is there a way we can avoid this problem and have it compatible?

Thanks!

Weird specs output

  • A lot of warnings and weird output produced by specs.
  • Cannot reliably test without Mongoid or ActiveRecord โ€” WITHOUT_MONGOID etc. stopped working.

GitHub Actions and my own workstation are affected. Surprisingly, all works in Travis CI we are migrating away from.

Update for Ruby 3.0

  • Builds on master against 2.7 output lots of deprecation warnings.
  • Builds on master against Ruby HEAD do fail.

Release v0.2.1

@ronaldtse, I've just released v0.2.1 which contains some important bugfixes. Please push it to Rubygems.

I18n of the default "(redacted)" phrase

Currently, the default redaction action is to slap a "(redacted)" on the original String.

This could be made more flexible. But by default it should also be internationalized (i18n).

Target these languages first:

  • en (default)
  • zh_CN
  • zh_TW
  • ja
  • ko
  • fr
  • de
  • es
  • pt

More masking options!

  • Proc as parameter
  • create some default scrambling algorithms
  • structured-text-preserving algorithms
    • e.g., keeping an HTML snippet valid HTML, but with masked inner text
  • structured Object preserving algorithms
    • i.e. generalization of the above HTML scenario

Rails 5 compatibility

At the moment attr_masker doesn't work with Rails 5 due to breaking changes in ActiveRecord.

Incomplete RSpec tests

Currently, there's basically zero tests.

Write tests to cover all configurations.

  • Write specs for the default (optionless) usage
  • Write specs for using custom maskers
  • Write specs for using if/unless filters
  • Write specs for using the column_name option
  • Write specs for masking the marshalled data
  • Write specs for the existing simplistic masker
  • Write specs which prove that data is safe in the production environment

Enhancement: Brand new DSL

First, Thank you for this gem!

So, I definitely see an argument for putting the attr_masker calls inside the models as its currently implemented. But there is also an argument for a centralized global configuration so all the masker calls are together and managed independently of the ORM (ActiveRecord) models. Further, this enables common conditions and custom maskers to be reused across models.

Thanks to the beauty of ruby, this is easy to do. Here is a sample from our app

# config/initializers/attr_masker.rb
require 'faker' # Faker gem for simple realistic data masking
leave_alone_domains = ["primarydomain.com", "secondarydomain.io"]

Company.class_eval do
  condition = ->(company) { !company.domain.in?(leave_alone_domains) }
  domain_mask = ->(**) { "#{Faker::Internet.unique.domain_word}.fake.#{Faker::Internet.domain_suffix}" }

  attr_masker :domain, if: condition, masker: domain_mask
end

User.class_eval do
  condition = ->(user) { user.network.in?(leave_alone_domains) }
  email_mask = ->(model:, **) { "user#{model.id}@example.com" }

  attr_masker :email, unless: condition, masker: email_mask
  attr_masker :name, unless: condition
end

The above works beautifully but obviously is a bit cumbersome syntax. We can do better if this gem supported a higher level dsl. Here is one suggestion:

# config/initializers/attr_masker.rb

condition = ->(company) { !company.domain.in?(leave_alone_domains) }
domain_mask = ->(**) { "#{Faker::Internet.unique.domain_word}.fake.#{Faker::Internet.domain_suffix}" }
email_mask = ->(model:, **) { "user#{model.id}@example.com" }

attr_masker Company, :domain, if: condition, masker: domain_mask
attr_masker User, :email, if: condition, masker: email_mask

# or alternately do it in a block

attr_masker do
  mask Company, :domain, if: condition, masker: domain_mask
  mask User, :email, if: condition, masker: email_mask
end

I think something like this would be fairly simple to implement. I could potentially submit a PR if you think this is useful. Let me know! Thanks again!

Masking may make records invalid

No record should become invalid in the result of masking. The Rake task should loudly fail in the attempt of invalid record creation. Or, if it's difficult, we should at least add a clear warning to the README file.

@ronaldtse's comment:

Masking MUST make sure the record is still valid. However, it might be up to the user of the attr_masker gem to get this right, i.e. it's not the burden of attr_masker to ensure validity. I don't think it is trivial at all to make attr_masker reuse the validation rules (which can be very arbitrary) for its attribute to generate random but valid values.

In the case of masking causing bad records, it is up to the user to have done DB backups and to restore it to its valid state, and to fix up any bad masking settings before re-running db:mask.

Maybe we should make this point clear in the README, etc.

DatabaseCleaner error when running RSpec

As reported in #109 (comment)

I'm working on a fix #110 , but stuck on the part where the gems database_cleaner-* with versions 2.x get installed when it shouldn't. These newer versions removed the called_externally? method from DatabaseCleaner, which caused the errors seen in https://github.com/riboseinc/attr_masker/runs/2021552398?check_suite_focus=true#step:8:14

Then there's this seemingly unrelated error reported by CodeCov:

https://github.com/riboseinc/attr_masker/runs/2021552207?check_suite_focus=true#step:8:32

The questions remain:

  1. How to reliably pin the versions for database_cleaner-*?
  2. What is happening with CodeCov? Is this something caused by something on our end?

Some models cannot be loaded

When calling ::ActiveRecord::Base.descendants in all_models, some models cannot be loaded.

May consider to use Rails.application.eager_load! to load all models.

Tests failing for Rails 4.2 with Ruby 2.4, 2.5 and 2.6

Currently tests are failing, e.g. in #97 with these:

Bundler could not find compatible versions for gem "activerecord":
In Rails-4.2.gemfile:
  activerecord (~> 4.2.0)

  attr_masker was resolved to 0.2.1, which depends on
    rails (>= 4.0.0, < 7) was resolved to 5.0.5.rc1, which depends on
      activerecord (= 5.0.5.rc1)

Update for modular Database Cleaner

They just went modular, which will complicate our dependency set a bit. (IMO controversial move for a rather small project which doesn't pull runtime dependencies, but whatever.)

Anyway, we probably want to reorganize our dependencies. For now, < 1.8 version constraint has been added.

Migrate CI to GitHub Actions

Already started, but there are some dependency issues, probably due to missing dependencies, which cause build failures.

The purpose of the :column option and its possible enhancement (replacement)

This question is somewhat a continuation of my discussion with @ronaldtse in the #5, which consisted of following two comments.

skalee: I wonder what the :column_name option is for. Apparently it overrides the column name when it's different from the attribute name. However, I cannot think of a good reason to support it at the moment. It isn't present in the original gem, and has been added in commit 82cab53, so I bet it is used by one of your projects. Therefore, I ask you for some concrete example or green light on its removal.

ronaldtse: @skalee I suspect it was used to support attributes that uses different column names like attr_encrypted does, but it might no longer be used. @ribose-jeffreylau should be able to clarify this with authority since he wrote it.

However, after some thinking I am coming to conclusion that :column_name option is too limited to be useful. In most cases, the attribute name is the same as the column name. I can imagine rare cases when this assumption is false, like attachment attribute handled by Paperclip or Carrierwave gem, or some serialized data stored in a column which name is suffixed. However in some cases things tend to go even more complex, for example Paperclip may use up to 4 columns. Passing single column name to that parameter is not enough.

I suggest renaming :column_name to :column_names and allow passing an array of column names. For example,

attr_masker :photo, column_names: %i[photo_file_name photo_content_type]

would update two columns.

I am going to implement it this way unless someone opposes.

Support Rails 5.2

We are not testing this gem against Rails 5.2. Compatibility is unknown.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.