This repository has been archived by the owner on May 16, 2023. It is now read-only.
forked from attr-encrypted/attr_encrypted
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from KentaaNL/fix-concurrency-problem
Fix concurrency problem
- Loading branch information
Showing
2 changed files
with
28 additions
and
15 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
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 |
---|---|---|
|
@@ -29,6 +29,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,17 +470,16 @@ def test_should_not_by_default_generate_iv_when_attribute_is_empty | |
|
||
def test_should_not_generate_iv_if_same_value_when_option_is_false | ||
user = User.new | ||
User.encrypted_attributes[:email][:update_unchanged] = false | ||
assert_nil user.encrypted_email_iv | ||
user.email = '[email protected]' | ||
refute_nil(old_value = user.encrypted_email_iv) | ||
user.email = '[email protected]' | ||
assert_equal old_value, user.encrypted_email_iv | ||
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 | ||
User.encrypted_attributes[:email][:update_unchanged] = true | ||
assert_nil user.encrypted_email_iv | ||
user.email = '[email protected]' | ||
refute_nil(old_value = user.encrypted_email_iv) | ||
|
@@ -488,21 +488,30 @@ def test_should_generate_iv_if_same_value_when_option_is_true | |
end | ||
|
||
def test_should_not_update_iv_if_same_value_when_option_is_false | ||
user = User.new(email: '[email protected]') | ||
User.encrypted_attributes[:email][:update_unchanged] = false | ||
old_encrypted_email_iv = user.encrypted_email_iv | ||
refute_nil old_encrypted_email_iv | ||
user.email = '[email protected]' | ||
assert_equal old_encrypted_email_iv, user.encrypted_email_iv | ||
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]') | ||
User.encrypted_attributes[:email][:update_unchanged] = true | ||
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' | ||
|
||
another_user = User.new | ||
|
||
assert_equal :encrypting, user.encrypted_attributes[:ssn][:operation] | ||
assert_nil another_user.encrypted_attributes[:ssn][:operation] | ||
end | ||
end |