Skip to content

Commit 30a0e7c

Browse files
TC-SJ-YoonmvastolajoshbranhamJosh Branhamvimalvnair
authored
TP #119254: Merge upstream v4.2.0 into fork (#5)
* Add (failable) tests to Travis for RoR 6/6.1/7 * Restrict set_attribute_was patch to Rails versions >= 5.2, < 6 Signed-off-by: Josh Branham <josh.php@gmail.com> * Don't use Gem requirement comparison with frozen Gem::Version * Disallow failures for RoR 6.0+ tests on travis As those should be passing or otherwise dealt with by the time this is merged * Use #write_cast_value to register the original value before change for Rails >= 5.2 Use #write_cast_value instead of #set_attribute_was patch * Prefix 'attr_encrypted' to encrypted_attributes method to avoid clash with Rails 7 Prefix 'attr_encrypted' to encrypt and decrypt methods to avoid clash with Rails 7 Adopted from PR: attr-encrypted#425 * Hardcoding sqlite3 gem version to 1.5.4 since newer sqlite3 versions removed native gem support for Ruby 2.6 * Release 4.0.0 * Drop gem signing (attr-encrypted#436) * Drop support for DataMapper (attr-encrypted#439) This project has been dead since 2018 * Update README.md (attr-encrypted#441) * Start testing ruby 3 (attr-encrypted#440) * Start testing ruby 3 * Exclude older AR and newer Ruby combos * Add Ruby 3.0.6 as well * Exclude 3.0.6 and AR 5.x * Use ActiveRecord.deprecator when available (attr-encrypted#437) Rails 7.1 will deprecate using the singleton ActiveSupport::Deprecation instance. This directly uses the one from ActiveRecord. Co-authored-by: Josh Branham <josh.php@gmail.com> * Use Github Actions for CI (attr-encrypted#442) * Use Github Actions for CI * Add back old Rails versions * Only test Rails 5 on Ruby 2.7 --------- Co-authored-by: Josh Branham <josh.php@gmail.com> * Fix minitest guard for rails 4 breaking specs (attr-encrypted#448) Co-authored-by: Josh Branham <joshbranham@sophie-mba.local> * Add Josh and Mike to authors (attr-encrypted#447) * Add Josh and Mike to authors Signed-off-by: Josh Branham <josh.php@gmail.com> * Update attr_encrypted.gemspec Signed-off-by: Josh Branham <josh.php@gmail.com> --------- Signed-off-by: Josh Branham <josh.php@gmail.com> * Add GitHub Actions badge to README (attr-encrypted#449) * Update README.md Signed-off-by: Josh Branham <josh.php@gmail.com> * Update README.md Signed-off-by: Josh Branham <josh.php@gmail.com> --------- Signed-off-by: Josh Branham <josh.php@gmail.com> * Deprecate testing with travis (attr-encrypted#450) * Add rails7.1 and Ruby3.3 to CI matrix (attr-encrypted#453) * Release v4.1.0 (attr-encrypted#455) * Fix SystemStackError when extending the reload method with Module#prepend (attr-encrypted#457) For example, when using the master branch of activerecord-multi-tenant, if activerecord-multi-tenant and attr_encrypted are listed in the Gemfile in that order, calling the reload method raises a SystemStackError. This happens because activerecord-multi-tenant extends Active Record’s reload method using prepend, while attr_encrypted extends it using an alias method. Here’s an example of how extending the same method with both prepend and alias methods in that order can result in a SystemStackError ``` class Hello def hello 'hello' end end Hello.prepend(Module.new do def hello super end end) Hello.class_eval do alias orig_hello hello def hello "#{orig_hello} world" end end Hello.new.hello #=> SystemStackError ``` However, reversing the order works: ``` class Hello def hello 'hello' end end Hello.class_eval do alias orig_hello hello def hello "#{orig_hello} world" end end Hello.prepend(Module.new do def hello super end end) Hello.new.hello #=> "hello world" ``` This issue can be resolved by standardizing the method extension to use prepend to avoid conflicts. * Release 4.1.1 (attr-encrypted#458) * Add Rails7.2, 8.0 and Ruby 3.4 to CI matrix Also updated actions/checkout to the latest v4. * Fix CI failures for Rails 6.0 to 7.0. The CI failures for Rails 6.0 to 7.0 are caused by changes introduced in concurrent-ruby v1.3.5. ref: [Rails 7.0.8 fails to create an app with most recent concurrent-ruby version · Issue #54260 · rails/rails](rails/rails#54260) Update concurrent-ruby to a version below 1.3.5 to fix the tests. * Set the sqlite3 version to 2.1.0 or higher for Rails 8.0. To run CI with Rails 8.0, sqlite3 version 2.1.0 or higher is required. * Remove the unused dm-sqlite-adapter dm-sqlite-adapter is a SQLite adapter for DataMapper. https://github.com/datamapper/dm-sqlite-adapter Since support for DataMapper was dropped in version 4.1.0, this gem is no longer needed as a dependency. * Set required_ruby_version >= 2.7.0 (attr-encrypted#464) * Release 4.2.0 * Release 4.2.0 (attr-encrypted#465) * Prevent attr_encrypted from making queries on load (attr-encrypted#468) `#attribute_instance_methods_as_symbols` can trigger a query when the schema cache is not loaded. We only need the results of this method if `attribute_instance_methods_as_symbols_available?` is true so we move this inside the check. Signed-off-by: Bojan Marjanovic <marjanovic93@gmail.com> * Reduce gem size by excluding test files (attr-encrypted#470) Co-authored-by: Yuri Zubov <yuri.zubov@cleverlabs.io> --------- Signed-off-by: Josh Branham <josh.php@gmail.com> Signed-off-by: Bojan Marjanovic <marjanovic93@gmail.com> Co-authored-by: Mike Vastola <mike@vasto.la> Co-authored-by: Josh Branham <josh.php@gmail.com> Co-authored-by: Josh Branham <jbranham@salsify.com> Co-authored-by: Vimal V Nair <vimalvnair999@gmail.com> Co-authored-by: Matt Larraz <mlarraz@users.noreply.github.com> Co-authored-by: Étienne Barrié <etienne.barrie@gmail.com> Co-authored-by: Josh Branham <joshbranham@sophie-mba.local> Co-authored-by: Shinichi Maeshima <netwillnet@gmail.com> Co-authored-by: Josh Branham <jbranham@redhat.com> Co-authored-by: Bojan Marjanovic <marjanovic93@gmail.com> Co-authored-by: Yuri Zubov <yury.zubau@gmail.com> Co-authored-by: Yuri Zubov <yuri.zubov@cleverlabs.io> Co-authored-by: Claude <noreply@anthropic.com>
1 parent e4b3995 commit 30a0e7c

15 files changed

Lines changed: 178 additions & 246 deletions

.github/workflows/CI.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
name: Ruby ${{ matrix.ruby }} / ActiveRecord ${{ matrix.active_record }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
include:
17+
- { active_record: '5.1', ruby: '2.7' }
18+
- { active_record: '5.2', ruby: '2.7' }
19+
- { active_record: '6.0', ruby: '2.7' }
20+
- { active_record: '6.0', ruby: '3.0' }
21+
- { active_record: '6.0', ruby: '3.1' }
22+
- { active_record: '6.0', ruby: '3.2' }
23+
- { active_record: '6.1', ruby: '2.7' }
24+
- { active_record: '6.1', ruby: '3.0' }
25+
- { active_record: '6.1', ruby: '3.1' }
26+
- { active_record: '6.1', ruby: '3.2' }
27+
- { active_record: '7.0', ruby: '2.7' }
28+
- { active_record: '7.0', ruby: '3.0' }
29+
- { active_record: '7.0', ruby: '3.1' }
30+
- { active_record: '7.0', ruby: '3.2' }
31+
- { active_record: '7.1', ruby: '2.7' }
32+
- { active_record: '7.1', ruby: '3.0' }
33+
- { active_record: '7.1', ruby: '3.1' }
34+
- { active_record: '7.1', ruby: '3.2' }
35+
- { active_record: '7.1', ruby: '3.3' }
36+
- { active_record: '7.2', ruby: '3.1' }
37+
- { active_record: '7.2', ruby: '3.2' }
38+
- { active_record: '7.2', ruby: '3.3' }
39+
- { active_record: '7.2', ruby: '3.4' }
40+
- { active_record: '8.0', ruby: '3.2' }
41+
- { active_record: '8.0', ruby: '3.3' }
42+
- { active_record: '8.0', ruby: '3.4' }
43+
env:
44+
ACTIVERECORD: ${{ matrix.active_record }}
45+
steps:
46+
- uses: actions/checkout@v4
47+
- name: Set up Ruby
48+
uses: ruby/setup-ruby@v1
49+
with:
50+
ruby-version: ${{ matrix.ruby }}
51+
bundler-cache: true
52+
- run: |
53+
bundle exec rake test

.travis.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1-
# attr_encrypted #
1+
# attr_encrypted
2+
3+
## Unreleased
4+
5+
* Reduce gem size by excluding test files
6+
7+
## 4.2.0
8+
9+
* Changed: Set minimum Ruby version as 2.7.
10+
* Added: Rails 7.2 and 8.0 support.
11+
* Fixed: Further removal of `datamapper` support.
12+
13+
## 4.1.1
14+
15+
* Fixed: Fix SystemStackError when extending the reload method with Module#prepend.
16+
17+
## 4.1.0
18+
19+
* Changed: Dropped support for `datamapper` which has not had a release since October 2011. This is in an attempt to make
20+
maintenance and testing easier moving forward.
21+
22+
## 4.0.0
23+
24+
* Added: Support for Ruby >= 3.0.
25+
* Added: Rails 7 support.
26+
* Changed: Using `#encrypted_attributes` is no longer supported. Instead, use `#attr_encrypted_encrypted_attributes` to avoid
27+
collision with Active Record 7 native encryption.
28+
29+
## 3.1.0
230

3-
## 3.1.0 ##
431
* Added: Abitilty to encrypt empty values. (@tamird)
532
* Added: MIT license
633
* Added: MRI 2.5.x support (@saghaulor)
@@ -11,23 +38,28 @@
1138
* Fixed: Only check empty on strings, allows for encrypting non-string type objects
1239
* Fixed: Fixed how accessors for db columns are defined in the ActiveRecord adapter, preventing premature definition. (@nagachika)
1340

14-
## 3.0.3 ##
41+
## 3.0.3
42+
1543
* Fixed: attr_was would decrypt the attribute upon every call. This is inefficient and introduces problems when the options change between decrypting an old value and encrypting a new value; for example, when rotating the encryption key. As such, the new approach caches the decrypted value of the old encrypted value such that the old options are no longer needed. (@johnny-lai) (@saghaulor)
1644

17-
## 3.0.2 ##
45+
## 3.0.2
46+
1847
* Changed: Removed alias_method_chain for compatibility with Rails v5.x (@grosser)
1948
* Changed: Updated Travis build matrix to include Rails 5. (@saghaulor) (@connorshea)
2049
* Changed: Removed `.silence_stream` from tests as it has been removed from Rails 5. (@sblackstone)
2150

22-
## 3.0.1 ##
51+
## 3.0.1
52+
2353
* Fixed: attr_was method no longer calls undefined methods. (@saghaulor)
2454

25-
## 3.0.0 ##
55+
## 3.0.0
56+
2657
* Changed: Updated gemspec to use Encryptor v3.0.0. (@saghaulor)
2758
* Changed: Updated README with instructions related to moving from v2.0.0 to v3.0.0. (@saghaulor)
2859
* Fixed: ActiveModel::Dirty methods in the ActiveRecord adapter. (@saghaulor)
2960

30-
## 2.0.0 ##
61+
## 2.0.0
62+
3163
* Added: Now using Encryptor v2.0.0 (@saghaulor)
3264
* Added: Options are copied to the instance. (@saghaulor)
3365
* Added: Operation option is set during encryption/decryption to allow options to be evaluated in the context of the current operation. (@saghaulor)
@@ -48,51 +80,62 @@
4880
* Removed: Support for Rails < 3.x (@saghaulor)
4981
* Removed: Unnecessary use of `alias_method` from ActiveRecord adapter. (@saghaulor)
5082

51-
## 1.4.0 ##
83+
## 1.4.0
84+
5285
* Added: ActiveModel::Dirty#attribute_was (@saghaulor)
5386
* Added: ActiveModel::Dirty#attribute_changed? (@mwean)
5487

55-
## 1.3.5 ##
88+
## 1.3.5
89+
5690
* Changed: Fixed gemspec to explicitly depend on Encryptor v1.3.0 (@saghaulor)
5791
* Fixed: Evaluate `:mode` option as a symbol or proc. (@cheynewallace)
5892

59-
## 1.3.4 ##
93+
## 1.3.4
94+
6095
* Added: ActiveRecord::Base.reload support. (@rcook)
6196
* Fixed: ActiveRecord adapter no longer forces attribute hashes to be string-keyed. (@tamird)
6297
* Fixed: Mass assignment protection in ActiveRecord 4. (@tamird)
6398
* Changed: Now using rubygems over https. (@tamird)
6499
* Changed: Let ActiveRecord define attribute methods. (@saghaulor)
65100

66-
## 1.3.3 ##
101+
## 1.3.3
102+
67103
* Added: Alias attr_encryptor and attr_encrpted. (@Billy Monk)
68104

69-
## 1.3.2 ##
105+
## 1.3.2
106+
70107
* Fixed: Bug regarding strong parameters. (@S. Brent Faulkner)
71108
* Fixed: Bug regarding loading per instance IV and salt. (@S. Brent Faulkner)
72109
* Fixed: Bug regarding assigning nil. (@S. Brent Faulkner)
73110
* Added: Support for protected attributes. (@S. Brent Faulkner)
74111
* Added: Support for ActiveRecord 4. (@S. Brent Faulkner)
75112

76-
## 1.3.1 ##
113+
## 1.3.1
114+
77115
* Added: Support for Rails 2.3.x and 3.1.x. (@S. Brent Faulkner)
78116

79-
## 1.3.0 ##
117+
## 1.3.0
118+
80119
* Fixed: Serialization bug. (@Billy Monk)
81120
* Added: Support for :per_attribute_iv_and_salt mode. (@rcook)
82121
* Fixed: Added dependencies to gemspec. (@jmazzi)
83122

84-
## 1.2.1 ##
123+
## 1.2.1
124+
85125
* Added: Force encoding when not marshaling. (@mosaicxm)
86126
* Fixed: Issue specifying multiple attributes on the same line. (@austintaylor)
87127
* Added: Typecasting to String before encryption (@shuber)
88128
* Added: `"#{attribute}?"` method. (@shuber)
89129

90-
## 1.2.0 ##
130+
## 1.2.0
131+
91132
* Changed: General code refactoring (@shuber)
92133

93-
## 1.1.2 ##
134+
## 1.1.2
135+
94136
* No significant changes
95137

96-
## 1.1.1 ##
138+
## 1.1.1
139+
97140
* Changled: Updated README. (@shuber)
98141
* Added: `before_type_cast` alias to ActiveRecord adapter. (@shuber)

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
source 'https://rubygems.org'
22

33
gemspec
4+
5+
gem "concurrent-ruby", "< 1.3.5"

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
## Maintainer(s) wanted!!!
2-
3-
**If you have an interest in maintaining this project... please see https://github.com/attr-encrypted/attr_encrypted/issues/379**
4-
51
# attr_encrypted
62

7-
[![Build Status](https://secure.travis-ci.org/attr-encrypted/attr_encrypted.svg)](https://travis-ci.org/attr-encrypted/attr_encrypted) [![Test Coverage](https://codeclimate.com/github/attr-encrypted/attr_encrypted/badges/coverage.svg)](https://codeclimate.com/github/attr-encrypted/attr_encrypted/coverage) [![Code Climate](https://codeclimate.com/github/attr-encrypted/attr_encrypted/badges/gpa.svg)](https://codeclimate.com/github/attr-encrypted/attr_encrypted) [![Gem Version](https://badge.fury.io/rb/attr_encrypted.svg)](https://badge.fury.io/rb/attr_encrypted) [![security](https://hakiri.io/github/attr-encrypted/attr_encrypted/master.svg)](https://hakiri.io/github/attr-encrypted/attr_encrypted/master)
3+
![workflow](https://github.com/attr-encrypted/attr_encrypted/actions/workflows/CI.yml/badge.svg) [![Gem Version](https://badge.fury.io/rb/attr_encrypted.svg)](https://badge.fury.io/rb/attr_encrypted)
84

95
Generates attr_accessors that transparently encrypt and decrypt attributes.
106

11-
It works with ANY class, however, you get a few extra features when you're using it with `ActiveRecord`, `DataMapper`, or `Sequel`.
12-
7+
It works with ANY class, however, you get a few extra features when you're using it with `ActiveRecord` or `Sequel`.
138

149
## Installation
1510

1611
Add attr_encrypted to your gemfile:
1712

1813
```ruby
19-
gem "attr_encrypted", "~> 3.1.0"
14+
gem "attr_encrypted"
2015
```
2116

2217
Then install the gem:
@@ -27,7 +22,7 @@ Then install the gem:
2722

2823
## Usage
2924

30-
If you're using an ORM like `ActiveRecord`, `DataMapper`, or `Sequel`, using attr_encrypted is easy:
25+
If you're using an ORM like `ActiveRecord` or `Sequel`, using attr_encrypted is easy:
3126

3227
```ruby
3328
class User
@@ -368,7 +363,7 @@ NOTE: This only works if all records are encrypted with the same encryption key
368363
__NOTE: This feature is deprecated and will be removed in the next major release.__
369364

370365

371-
### DataMapper and Sequel
366+
### Sequel
372367

373368
#### Default options
374369

attr_encrypted.gemspec

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,47 @@ Gem::Specification.new do |s|
1414
s.summary = 'Encrypt and decrypt attributes'
1515
s.description = 'Generates attr_accessors that encrypt and decrypt attributes transparently'
1616

17-
s.authors = ['Sean Huber', 'S. Brent Faulkner', 'William Monk', 'Stephen Aghaulor']
18-
s.email = ['seah@shuber.io', 'sbfaulkner@gmail.com', 'billy.monk@gmail.com', 'saghaulor@gmail.com']
17+
s.authors = ['Sean Huber', 'S. Brent Faulkner', 'William Monk', 'Stephen Aghaulor', 'Josh Branham', 'Mike Vastola']
18+
s.email = ['seah@shuber.io', 'sbfaulkner@gmail.com', 'billy.monk@gmail.com', 'saghaulor@gmail.com', 'josh.php@gmail.com', 'Mike@Vasto.la']
1919
s.homepage = 'http://github.com/attr-encrypted/attr_encrypted'
2020
s.license = 'MIT'
2121

2222
s.require_paths = ['lib']
2323

24-
s.files = `git ls-files`.split("\n")
25-
s.test_files = `git ls-files -- test/*`.split("\n")
24+
s.files = Dir.glob('lib/**/*') + [
25+
'CHANGELOG.md',
26+
'MIT-LICENSE',
27+
'README.md'
28+
]
2629

2730
s.required_ruby_version = '>= 3.3.0'
2831

2932
s.add_dependency('encryptor', ['~> 3.0.0'])
3033
# support for testing with specific active record version
3134
activerecord_version = if ENV.key?('ACTIVERECORD')
32-
"~> #{ENV['ACTIVERECORD']}"
35+
"~> #{ENV['ACTIVERECORD']}.0"
3336
else
34-
'>= 2.0.0'
37+
'>= 6.0.0'
3538
end
3639
s.add_development_dependency('activerecord', activerecord_version)
3740
s.add_development_dependency('actionpack', activerecord_version)
38-
# DataMapper removed - incompatible with Ruby 3.x (uses removed Fixnum constant)
3941
s.add_development_dependency('rake')
4042
s.add_development_dependency('minitest')
4143
s.add_development_dependency('sequel')
4244
if defined?(RUBY_ENGINE) && RUBY_ENGINE.to_sym == :jruby
4345
s.add_development_dependency('activerecord-jdbcsqlite3-adapter')
4446
s.add_development_dependency('jdbc-sqlite3', '< 3.8.7') # 3.8.7 is nice and broke
4547
else
46-
s.add_development_dependency('sqlite3')
48+
if ENV['ACTIVERECORD'] && Gem::Version.new(ENV['ACTIVERECORD']) >= Gem::Version.new('8.0')
49+
s.add_development_dependency('sqlite3', '> 2.1.0')
50+
else
51+
s.add_development_dependency('sqlite3', '= 1.5.4')
52+
end
4753
end
4854
s.add_development_dependency('pry')
4955
s.add_development_dependency('simplecov')
5056

51-
s.cert_chain = ['certs/saghaulor.pem']
52-
s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
53-
54-
s.post_install_message = "\n\n\nWARNING: Several insecure default options and features were deprecated in attr_encrypted v2.0.0.\n
55-
Additionally, there was a bug in Encryptor v2.0.0 that insecurely encrypted data when using an AES-*-GCM algorithm.\n
56-
This bug was fixed but introduced breaking changes between v2.x and v3.x.\n
57-
Please see the README for more information regarding upgrading to attr_encrypted v3.0.0.\n\n\n"
57+
s.post_install_message = "\n\n\nWARNING: Using `#encrypted_attributes` is no longer supported. Instead, use `#attr_encrypted_encrypted_attributes` to avoid
58+
collision with Active Record 7 native encryption.\n\n\n"
5859

5960
end

certs/saghaulor.pem

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/attr_encrypted.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def self.extended(base) # :nodoc:
5454
# string instead of just 'true'. See
5555
# http://www.ruby-doc.org/core/classes/Array.html#M002245
5656
# for more encoding directives.
57-
# Defaults to false unless you're using it with ActiveRecord, DataMapper, or Sequel.
57+
# Defaults to false unless you're using it with ActiveRecord or Sequel.
5858
#
5959
# encode_iv: Defaults to true.
6060

@@ -144,9 +144,8 @@ def attr_encrypted(*attributes)
144144
attributes.each do |attribute|
145145
encrypted_attribute_name = (options[:attribute] ? options[:attribute] : [options[:prefix], attribute, options[:suffix]].join).to_sym
146146

147-
instance_methods_as_symbols = attribute_instance_methods_as_symbols
148-
149147
if attribute_instance_methods_as_symbols_available?
148+
instance_methods_as_symbols = attribute_instance_methods_as_symbols
150149
attr_reader encrypted_attribute_name unless instance_methods_as_symbols.include?(encrypted_attribute_name)
151150
attr_writer encrypted_attribute_name unless instance_methods_as_symbols.include?(:"#{encrypted_attribute_name}=")
152151

0 commit comments

Comments
 (0)