Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade for Rails 8.0 #208

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby-version: [ '2.7', '3.0', '3.1']
rails: ['5_0', '5_1', '5_2', '6_0', '6_1', '7_0']
ruby-version: [ '2.7', '3.0', '3.1', '3.2', '3.3']
rails: ['5_0', '5_1', '5_2', '6_0', '6_1', '7_0', '7_1', '7_2', '8_0']
exclude:
# exclude unsupported ruby versions: https://github.com/rails/rails/issues/40938
- ruby-version: '3.0'
Expand All @@ -25,6 +25,28 @@ jobs:
rails: '5_1'
- ruby-version: '3.1'
rails: '5_2'
- ruby-version: '3.2'
rails: '5_0'
- ruby-version: '3.2'
rails: '5_1'
- ruby-version: '3.2'
rails: '5_2'
- ruby-version: '3.3'
rails: '5_0'
- ruby-version: '3.3'
rails: '5_1'
- ruby-version: '3.3'
rails: '5_2'
- ruby-version: '2.7'
rails: '7_2'
- ruby-version: '3.0'
rails: '7_2'
- ruby-version: '2.7'
rails: '8_0'
- ruby-version: '3.0'
rails: '8_0'
- ruby-version: '3.1'
rails: '8_0'

env:
TESTING_RAILS_VERSION: ${{ matrix.rails }}
Expand All @@ -41,7 +63,7 @@ jobs:
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--health-retries 5
ports:
- 5432:5432
mysql:
Expand All @@ -53,11 +75,11 @@ jobs:
MYSQL_ROOT_PASSWORD: rootpassword
ports:
- 33306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup System
run: sudo apt-get install libsqlite3-dev

Expand All @@ -66,14 +88,14 @@ jobs:
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Copy database config
run: |
cp spec/github_actions.database.yml spec/database.yml

- name: Enable pgcrypto extension
run: |
PGPASSWORD=crypt_keeper psql crypt_keeper_providers -h localhost -p 5432 -U crypt_keeper -tc "CREATE EXTENSION IF NOT EXISTS pgcrypto;"

- name: Run tests
run: bundle exec rake
27 changes: 18 additions & 9 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
appraise "activerecord_4_2" do
gem "activerecord", "~> 4.2.0"
gem "activesupport", "~> 4.2.0"
gem "sqlite3", "~> 1.3.0"

# otherwise you get "undefined method `new' for BigDecimal:Class" in Ruby 2.7
gem "bigdecimal", "1.3.5"
end

appraise "activerecord_5_0" do
gem "activerecord", "~> 5.0.0"
gem "activesupport", "~> 5.0.0"
Expand Down Expand Up @@ -40,3 +31,21 @@ appraise "activerecord_7_0" do
gem "activesupport", "~> 7.0.0"
gem "pg", "~> 1.1"
end

appraise "activerecord_7_1" do
gem "activerecord", "~> 7.1.0"
gem "activesupport", "~> 7.1.0"
gem "pg", "~> 1.1"
end

appraise "activerecord_7_2" do
gem "activerecord", "~> 7.2.0"
gem "activesupport", "~> 7.2.0"
gem "pg", "~> 1.1"
end

appraise "activerecord_8_0" do
gem "activerecord", "~> 8.0.0.rc1"
gem "activesupport", "~> 8.0.0.rc1"
gem "pg", "~> 1.1"
end
10 changes: 5 additions & 5 deletions crypt_keeper.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Gem::Specification.new do |gem|

gem.post_install_message = "WARNING: CryptKeeper 2.0 contains breaking changes and may require you to reencrypt your data! Please view the README at https://github.com/jmazzi/crypt_keeper for more information."

gem.add_runtime_dependency 'activerecord', '>= 4.2', '~> 7.0.0'
gem.add_runtime_dependency 'activesupport', '>= 4.2', '~> 7.0.0'
gem.add_runtime_dependency 'activerecord', '>= 5.0', '< 8.1'
gem.add_runtime_dependency 'activesupport', '>= 5.0', '< 8.1'

gem.add_development_dependency 'rspec', '~> 3.5.0'
gem.add_development_dependency 'guard', '~> 2.6.1'
Expand All @@ -35,8 +35,8 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'activerecord-jdbcpostgresql-adapter'
gem.add_development_dependency 'activerecord-jdbcmysql-adapter'
else
gem.add_development_dependency 'sqlite3', '>= 1.3.3', '< 1.5'
gem.add_development_dependency 'pg', '~> 0.18.0'
gem.add_development_dependency 'mysql2', '>= 0.3.13', '< 0.6.0'
gem.add_development_dependency 'sqlite3', '>= 1.3'
gem.add_development_dependency 'pg', '>= 0.18.0'
gem.add_development_dependency 'mysql2', '>= 0.3.13'
end
end
1 change: 1 addition & 0 deletions gemfiles/activerecord_5_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ source "https://rubygems.org"

gem "activerecord", "~> 5.1.0"
gem "activesupport", "~> 5.1.0"
gem "sqlite3", "< 2"

gemspec :path => "../"
1 change: 1 addition & 0 deletions gemfiles/activerecord_5_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ source "https://rubygems.org"

gem "activerecord", "~> 5.2.0"
gem "activesupport", "~> 5.2.0"
gem "sqlite3", "< 2"

gemspec :path => "../"
1 change: 1 addition & 0 deletions gemfiles/activerecord_6_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ source "https://rubygems.org"

gem "activerecord", "~> 6.0.0"
gem "activesupport", "~> 6.0.0"
gem "sqlite3", "< 2"

gemspec :path => "../"
1 change: 1 addition & 0 deletions gemfiles/activerecord_6_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ source "https://rubygems.org"
gem "activerecord", "~> 6.1.0"
gem "activesupport", "~> 6.1.0"
gem "pg", "~> 1.1"
gem "sqlite3", "< 2"

gemspec :path => "../"
1 change: 1 addition & 0 deletions gemfiles/activerecord_7_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ source "https://rubygems.org"
gem "activerecord", "~> 7.0.0"
gem "activesupport", "~> 7.0.0"
gem "pg", "~> 1.1"
gem "sqlite3", "< 2"

gemspec :path => "../"
9 changes: 9 additions & 0 deletions gemfiles/activerecord_7_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 7.1.0"
gem "activesupport", "~> 7.1.0"
gem "pg", "~> 1.1"

gemspec :path => "../"
9 changes: 9 additions & 0 deletions gemfiles/activerecord_7_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 7.2.0"
gem "activesupport", "~> 7.2.0"
gem "pg", "~> 1.1"

gemspec :path => "../"
10 changes: 10 additions & 0 deletions gemfiles/activerecord_8_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 8.0.0.rc1"
gem "activesupport", "~> 8.0.0.rc1"
gem "pg", "~> 1.1"
gem "sqlite3", ">= 2.1.0"

gemspec :path => "../"
5 changes: 5 additions & 0 deletions lib/crypt_keeper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class << self

attr_accessor :silence_logs
alias_method :silence_logs?, :silence_logs

def active_record_7_1?
ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 \
|| ActiveRecord::VERSION::MAJOR >= 8
end
end
end

Expand Down
8 changes: 6 additions & 2 deletions lib/crypt_keeper/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ def crypt_keeper(*args)
end

crypt_keeper_fields.each do |field|
serialize field, encryptor
if CryptKeeper.active_record_7_1?
serialize field, coder: encryptor
else
serialize field, encryptor
end
end
end

Expand Down Expand Up @@ -120,7 +124,7 @@ def decrypt_table!
def encryptor_klass
@encryptor_klass ||= "CryptKeeper::Provider::#{crypt_keeper_encryptor.to_s.camelize}".constantize
rescue NameError
# couldn’t constantize...
# couldn’t constantize...
nil
end

Expand Down
2 changes: 1 addition & 1 deletion lib/crypt_keeper/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CryptKeeper
VERSION = "2.3.0"
VERSION = "2.4.0"
end
11 changes: 9 additions & 2 deletions spec/crypt_keeper/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
end
end


context "Encryption and Decryption" do
let(:plain_text) { 'plain_text' }
let(:cipher_text) { 'tooltxet_nialp' }
Expand Down Expand Up @@ -153,6 +153,13 @@

context "Initial Table Encryption" do
subject { create_encrypted_model :storage, key: 'tool', salt: 'salt', encryptor: :active_support }
let(:error_class) do
if CryptKeeper.active_record_7_1?
ActiveSupport::MessageEncryptor::InvalidMessage
else
ActiveSupport::MessageVerifier::InvalidSignature
end
end

before do
subject.delete_all
Expand All @@ -161,7 +168,7 @@
end

it "encrypts the table" do
expect { subject.first(5).map(&:storage) }.to raise_error(ActiveSupport::MessageVerifier::InvalidSignature)
expect { subject.first(5).map(&:storage) }.to raise_error(error_class)
subject.encrypt_table!
expect { subject.first(5).map(&:storage) }.not_to raise_error
end
Expand Down
6 changes: 3 additions & 3 deletions spec/crypt_keeper/provider/postgres_pgp_public_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
describe CryptKeeper::Provider::PostgresPgpPublicKey do
use_postgres

let(:cipher_text) { '\xc1c04c036c401ad086beb9e3010800987d6c4ccd974322190caa75a3a01aba37bc1970182c4c1d3faec98edf186780520f0586101f286e0626096a1eca91a229ed4d4058a6913a8d13cdf49f29ea44e2b96d10347f9b1b860bb3c959f000a3b1b415a95d2cd07af8c74aa6df8cd10ab06b6a6f7db69cdf3185466d68c5b66b95b813acdfb3ddfb021cac92e0967d67e90df73332f27970c1d2b9a56ac74f602d4107b163ed73ef89fca560d9a0a0d2bc7a74005f29fa27babfbaf950ac07b1c809049db4ab126be4824cf76416c278571f7064f638edf830a1ae5ee1ab544d35fce0f974f21b9dcbbea3986077d27b0de34144dc23f369f471090b57e067a056901e680493ddf2a6b29e4af3462387d235010259556079d07daa249b6703e2bc79345da556cfb46f228cad40a8a5b569ac46f08865f9176acf89129a3e0ceb2a7b1991012f65' }
let(:cipher_text) { '\xc1c24e03374ac5d225ffff71100bfe27156ec4de2509f29639db2820a08c79b54a5c35def273f57453c46bf2aa1e211437416afe62f97f350943519d7aa85498d98763118f5ddefa33632c8178eb1f4700dba97dadca79d9e369dc4d4b894f6fd8553185fd1ba8f4e997cbcdce71de376501eb162164668b1368743bd10f06d4ef3406faca262120f55baad2a156afe3953361cb25422a51d5fa82b55714d876ea11abe2e403b1634f7484c6db89d36d18161390b4e5531199b7cd3bd5b54a5702858d4e8cc9a9b67cedb7cb1ac00b1e9291b641e7e666a13a8a01e230506e553c0fab5a21c59f92548c16ba35b0eee42d3640ecbf55d7271ced731c5a3188b1608943b18f739614362bb52ceae7b8900abbae545bae26b8cdd8204da479b0b0fe9cb77c542c8ab20b2a149f0935929e885d1725e4e2d9406ea2bff5772e24c1d0f51b4ffd95d65995c8a0507f30f66e0e934310f603260d554d953bf5990a165c559e8ce6d0347a6ca136c6d666ea25ff751fff8952ef45aefd3aab1362799b8f67b9f05db612f6237153707757d30c009459859cb2a5133ab6062a10b22dca5c9476c7dbbd7c40a06259984a365cbca5b237b0cd2d9eac60c2dbb1ae41a362f2f6585d457a16ec221d3bf93e4fb2d2ed20ab8fe4954111292ebe1cd3a67bc180b4ea965832f1ddcf3c446bd6e686c564cbe9b467471c6d06074a5b97b1ec205ac1097a68db74b1ccb6f08405f91bf81b7449fd6cf1408f3a6b69ae0f9588e404c4389a941a1905322256afd207cdbf62df0f7824a8dbc84f9807c6ed618c2025ff1497d263a969d394d7426fc7ab85989b24a5e67b52f4e155499afef35ac43aa266d0c2afc69c20f04c0a0ee1bb949d210489d289b818be3fb1087d830c45a37ebfebb6dafb2702bd3f77006721d4bbb8366767cacd1471737be22123679cbe04f4a734b9865afbd76249da53f19219d90692f6cca1cac69fcd25a372fad325fc87f7ab1f3edcac65bc9a4cf3ba7da9cfbbabd67beba5319b984d7e855038edf9b3e5aaae5dfa8def1cfb9dd4ca0c1a9d5709f282cd4d9301adee0eada250c26668b126405b095c0e8dba69ca314f54d23501321b5c6c8bc0b25d693d6dc643b52c71f0c263e021b9a7c1a11b646175f95df6cbea5aba6210dadf9f35ef8afcf23c5a62db59ab' }

let(:integer_cipher_text) { '\xc1c04c036c401ad086beb9e30107ff59e674ba05958eb053c2427b44355e0f333f1726e18a0b851130130510c648f580b13b3f6a223eb26e397008596867c5a511a4f5bfbf2ecc852d8929814480d63166e525fa2b259b6a8d4474b5b1373b4e1a4fe70a491d25442e1c0046fd3d69466ad30153c8d8d920e9b4260d4e4e421ef3ead162b3aba5d85408c4ef9f9d342b5655c7568d1bdc61c27ddb419133bf091f22f42e7bc91ec6d279b7b25b87ea65119568b85ae81079dd0a6a7258b58fb219c6cc4580f33cb46de97770a1eb0880bdf87426fd0529576a1e791e521d9b3c426e393e63d83321f319b00f9dc4027ea5a81dd57c0f5ba868fb86d73179c34f2287c437266e8becc072b45a929562d2320194be54464e03854635d0f7d7fb10813adbc6efe51efa9095a9bacc2a03fb5c41d1c1896384e4f36b100c0f00e81d4cff7d' }
let(:integer_cipher_text) { '\xc1c24e03374ac5d225ffff71100c008d6566bcb0e23faab9665214c2611e9e04d37cf2dc775e834bb8ec0e5b4192927c165f3fc42e667e6b2c681ffe6b87226ff02d15907f82e72019f146347e0f00e395a2ae7c2399d2f8511b290ece078ddd4de03976aac074367b588ee79536490a30e0f24d61c9a25a543834cbcbe46e27448c5afa6e11f61368ea45758993da7e2dae9ee9b8ef365f30c18c9ef8b3dfd9b307dfc65204e0c3954e00a934536712e2374a98f87e4c2b7ec069274548f2e76ae95390b0cf996b2269e9a2d4d2fd437d117ad01628eaa86a686c00fdee98efa321e47063a90a60dee36362a96136482102d8012bc6d5d966e80d39d8548233f865429ad08590d1493f3ce8bf2a7b17a53d591975e2cb3d6b81dfb25f4ea621e1b1727c8b95cd637f539390523d2b6c3a2aba1aa94057706631d5e83124b7307f53ecd01668f83d568d094e461a8cc439859ecf9964d41c2ecf36c0b46b56cdd962c387a6ba5c2eeaa4093a2550099ab1783d9a36758be2ec8effd7498bf8c8ce1bc076d7a3535b52766709dfb9900bfe3073409e705506e006f9df051d7ce83af6a47b4b6a30e9e313db8e992a3f9600160ae8f82163567e7dee06f491c66de1837ef6493f1e791186a4c9704d9eb48c48351fc1bf62e7be0a9d940013142031ae15b3ead2c96748be35ee51157ea4748ca1e4d420974e72a8cd9c5c39606557569d3a4efc4c8ff6df8cfd243be43fc0cc1ea305fc54e2e94d7ae7487c175b0e0e784ce1816872ed57f765fe4f186b0181342d9d3c207bc69cb75ab5a063d60bb67f095a593e690b54cd37f8c1448f9af9d8be384fdb7fd281c13cb235446bc17f8a1a7a1b287fe193820d457c64e329c06d143991f0a858aaa2dd7a280ba29a86ec73b1e76f290be54abfeff60bfa5e1afa7ebb9f30bf9c1bb57bc87420c460e3cd616b47ee567e2e8a1962edc26584780626fe891b79a52ced914aff5261e7da4b6a1d4fddb3ec90e18f4ff543e237cbeb7a31f2ffd147f3e135c410463ff5a92950481889680c6f860b3548d3d7326cd9f5956d4bbfdd56e1d53f51a5abeb3ae7222a48920ca16708739e809a96f9d232014ad7f53dbe68cb1bc826d8a21e2761353199fc82d854070ca10ff11bb236221422ba17f1b8c77af3801310bacb7d23bd34' }

let(:integer_plain_text) { 1 }
let(:plain_text) { 'test' }
Expand All @@ -15,7 +15,7 @@
end

let(:private_key) do
IO.read(File.join(SPEC_ROOT, 'fixtures', 'private.asc'))
IO.read(File.join(SPEC_ROOT, 'fixtures', 'private.asc')) # Expiration date 2074-04-06
end

subject { described_class.new key: ENCRYPTION_PASSWORD, public_key: public_key, private_key: private_key }
Expand Down
Loading