-
Notifications
You must be signed in to change notification settings - Fork 74
Prevent re-encryption of unchanged values. #13
Conversation
… trait. Added new testDontEncryptUnchangedAttributes test in DirtyTest.
Thanks for the pull request @MarkTierney1975! Which version of Laravel framework did you pull the |
Ah, it may have been 5.5. |
I've used the new 6.6 function, there's only minor style differences from what I can see. I'm not sure how to fix the codeclimate and CI issues that are being highlighted, they seem to be with the original Laravel code style :) |
…hasCast() methods to HasEncryptedAttributes trait.
Apologies for all the commits! The codeclimate issues are in the original Laravel function and I don't really want to mess with that. Anything else I need to do? |
Hey @MarkTierney1975 -- I haven't had time to reproduce the bug you're trying to fix here. Do you have a small snippet you can post? In theory the unit tests for getDirty should be catching an issue like this. |
This was the test I added to tests/Traits/DirtyTest.php public function testDontEncryptUnchangedAttributes()
{
$string = 'Hello world!';
$model = DatabaseModel::create(['should_be_encrypted' => $string]);
$this->assertTrue($model->exists);
$model->should_be_encrypted = $string;
$changedAttributes = $model->getDirty();
$this->assertTrue(empty($changedAttributes));
} |
This is my first pull request, not sure if I've done the right thing, apologies if I've messed up :)
In the app I'm building I noticed that all my encrypted attributes were being re-encrypted on save even when they hadn't changed. This pull request adds to the existing originalIsEquivalent from the \Illuminate\Database\Eloquent\Concerns\HasAttributes trait. Compares the decrypted values and adds them to the dirty array only if they are different.
Commit:
Added amended originalIsEquivalent function in HasEncryptedAttributes trait.
Added new testDontEncryptUnchangedAttributes test in DirtyTest.