diff --git a/CHANGELOG.md b/CHANGELOG.md index 25d58d31..e0d7ab2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 2a90f935..88926b6b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/lockbox/model.rb b/lib/lockbox/model.rb index c8ee64fd..0933b746 100644 --- a/lib/lockbox/model.rb +++ b/lib/lockbox/model.rb @@ -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] diff --git a/test/internal/db/schema.rb b/test/internal/db/schema.rb index ac31f873..a7342fec 100644 --- a/test/internal/db/schema.rb +++ b/test/internal/db/schema.rb @@ -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 diff --git a/test/model_types_test.rb b/test/model_types_test.rb index 138dd8fc..4189d5ca 100644 --- a/test/model_types_test.rb +++ b/test/model_types_test.rb @@ -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 diff --git a/test/support/active_record.rb b/test/support/active_record.rb index f050c085..e3233a17 100644 --- a/test/support/active_record.rb +++ b/test/support/active_record.rb @@ -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