Skip to content

Commit

Permalink
Added warning for encrypting store attributes - closes #185
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jan 11, 2024
1 parent dcdd5b3 commit 5317d89
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.3 (unreleased)

- Added warning for encrypting store attributes

## 1.3.2 (2024-01-10)

- Fixed issue with serialized attributes
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class User < ApplicationRecord
end
```

For [Active Record Store](https://api.rubyonrails.org/classes/ActiveRecord/Store.html), encrypt the column rather than individual accessors.

For [StoreModel](https://github.com/DmitryTsepelev/store_model), use:

```ruby
Expand Down
5 changes: 5 additions & 0 deletions lib/lockbox/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ def reload
@lockbox_attributes[original_name] = options

if activerecord
# warn on store attributes
if stored_attributes.any? { |k, v| v.include?(name) }
warn "[lockbox] WARNING: encrypting store accessors is not supported. Encrypt the column instead."
end

# warn on default attributes
if attributes_to_define_after_schema_loads.key?(name.to_s)
opt = attributes_to_define_after_schema_loads[name.to_s][1]
Expand Down
1 change: 1 addition & 0 deletions test/internal/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
t.text :info2_ciphertext
t.text :credentials
t.text :credentials2_ciphertext
t.text :credentials3
t.text :configuration
t.text :configuration2_ciphertext
t.text :coordinates
Expand Down
6 changes: 6 additions & 0 deletions test/model_types_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,12 @@ def test_store
assert_attribute :username, "hello", check_nil: false
end

def test_store_attributes
assert_output(nil, /WARNING: encrypting store accessors is not supported/) do
User.has_encrypted :username3
end
end

def test_custom
assert_attribute :configuration, "USA", format: "USA!!"
end
Expand Down
1 change: 1 addition & 0 deletions test/support/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def deserialize(value)
store :credentials, accessors: [:username], coder: JSON
store :credentials2, accessors: [:username2], coder: JSON
has_encrypted :credentials2
store :credentials3, accessors: [:username3], coder: JSON

attribute :configuration, Configuration.new
has_encrypted :configuration2, type: Configuration.new
Expand Down

0 comments on commit 5317d89

Please sign in to comment.