forked from attr-encrypted/attr_encrypted
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optional update encrypted attributes only when values changed
- Loading branch information
Twan Maus
committed
May 16, 2023
1 parent
dee8d41
commit b33467a
Showing
7 changed files
with
114 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
ruby-version: ['2.7', '3.0', '3.1', '3.2'] | ||
rails-version: ['5.1.1', '5.2.8', '6.0.6', '6.1.7', '7.0.4'] | ||
exclude: | ||
- ruby-version: 2.7 | ||
rails-version: 7.0.4 | ||
- ruby-version: 3.0 | ||
rails-version: 5.1.1 | ||
- ruby-version: 3.0 | ||
rails-version: 5.2.8 | ||
- ruby-version: 3.1 | ||
rails-version: 5.1.1 | ||
- ruby-version: 3.1 | ||
rails-version: 5.2.8 | ||
- ruby-version: 3.2 | ||
rails-version: 5.1.1 | ||
- ruby-version: 3.2 | ||
rails-version: 5.2.8 | ||
env: | ||
ACTIVERECORD: ${{ matrix.rails-version }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby-version }} | ||
bundler-cache: true | ||
- name: Run tests | ||
run: bundle exec rake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
pkg | ||
Gemfile.lock | ||
coverage | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
attr_encrypted |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ class User | |
attr_encrypted :with_false_unless, :key => SECRET_KEY, :unless => false, mode: :per_attribute_iv_and_salt | ||
attr_encrypted :with_if_changed, :key => SECRET_KEY, :if => :should_encrypt | ||
attr_encrypted :with_allow_empty_value, key: SECRET_KEY, allow_empty_value: true, marshal: true | ||
attr_encrypted :with_unchanged_false, key: SECRET_KEY, update_unchanged: false | ||
|
||
attr_encryptor :aliased, :key => SECRET_KEY | ||
|
||
|
@@ -469,6 +470,43 @@ def test_should_not_by_default_generate_iv_when_attribute_is_empty | |
assert_nil user.encrypted_with_true_if_iv | ||
end | ||
|
||
def test_should_not_generate_iv_if_same_value_when_option_is_false | ||
user = User.new | ||
assert_nil user.encrypted_with_unchanged_false_iv | ||
user.with_unchanged_false = '[email protected]' | ||
old_value = user.encrypted_with_unchanged_false_iv | ||
refute_nil(old_value) | ||
user.with_unchanged_false = '[email protected]' | ||
assert_equal old_value, user.encrypted_with_unchanged_false_iv | ||
end | ||
|
||
def test_should_generate_iv_if_same_value_when_option_is_true | ||
user = User.new | ||
assert_nil user.encrypted_email_iv | ||
user.email = '[email protected]' | ||
refute_nil(old_value = user.encrypted_email_iv) | ||
user.email = '[email protected]' | ||
refute_equal old_value, user.encrypted_email_iv | ||
end | ||
|
||
def test_should_not_update_iv_if_same_value_when_option_is_false | ||
user = User.new | ||
user.with_unchanged_false = '[email protected]' | ||
old_encrypted_with_unchanged_false_iv = user.encrypted_with_unchanged_false_iv | ||
refute_nil old_encrypted_with_unchanged_false_iv | ||
user.with_unchanged_false = '[email protected]' | ||
assert_equal old_encrypted_with_unchanged_false_iv, user.encrypted_with_unchanged_false_iv | ||
end | ||
|
||
def test_should_not_update_iv_if_same_value_when_option_is_true | ||
user = User.new(email: '[email protected]') | ||
old_encrypted_email_iv = user.encrypted_email_iv | ||
refute_nil old_encrypted_email_iv | ||
user.email = '[email protected]' | ||
refute_nil user.encrypted_email_iv | ||
refute_equal old_encrypted_email_iv, user.encrypted_email_iv | ||
end | ||
|
||
def test_encrypted_attributes_state_is_not_shared | ||
user = User.new | ||
user.ssn = '123456789' | ||
|