Skip to content

Commit

Permalink
Merge pull request #188 from nikz/allow-6-1
Browse files Browse the repository at this point in the history
Allows Rails 6.1
  • Loading branch information
jmazzi authored Apr 9, 2021
2 parents 6994db6 + a7499fb commit 12e2644
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 5 deletions.
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ rvm:
- 2.4.5
- 2.5.3
- 2.6.4
- 2.7.2

gemfile:
- gemfiles/activerecord_4_2.gemfile
- gemfiles/activerecord_5_0.gemfile
- gemfiles/activerecord_5_1.gemfile
- gemfiles/activerecord_5_2.gemfile
- gemfiles/activerecord_6_0.gemfile
- gemfiles/activerecord_6_1.gemfile


matrix:
exclude:
Expand All @@ -22,18 +25,24 @@ matrix:
gemfile: gemfiles/activerecord_5_1.gemfile
- rvm: 2.2.10
gemfile: gemfiles/activerecord_6_0.gemfile
- rvm: 2.2.10
gemfile: gemfiles/activerecord_6_1.gemfile
- rvm: 2.3.8
gemfile: gemfiles/activerecord_5_0.gemfile
- rvm: 2.3.8
gemfile: gemfiles/activerecord_5_1.gemfile
- rvm: 2.3.8
gemfile: gemfiles/activerecord_6_0.gemfile
- rvm: 2.3.8
gemfile: gemfiles/activerecord_6_1.gemfile
- rvm: 2.4.5
gemfile: gemfiles/activerecord_5_0.gemfile
- rvm: 2.4.5
gemfile: gemfiles/activerecord_5_1.gemfile
- rvm: 2.4.5
gemfile: gemfiles/activerecord_6_0.gemfile
- rvm: 2.4.5
gemfile: gemfiles/activerecord_6_1.gemfile
- rvm: 2.5.3
gemfile: gemfiles/activerecord_5_0.gemfile
- rvm: 2.5.3
Expand All @@ -53,7 +62,8 @@ before_script:
- psql crypt_keeper_providers -c 'CREATE EXTENSION IF NOT EXISTS pgcrypto;' -U postgres
- mysql -e 'CREATE DATABASE crypt_keeper_providers'

branches: master
branches:
- master

notifications:
email:
Expand Down
11 changes: 11 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ 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"

gem "sqlite3", "~> 1.3.6"
end

appraise "activerecord_5_1" do
Expand All @@ -23,3 +28,9 @@ appraise "activerecord_6_0" do
gem "activerecord", "~> 6.0.0"
gem "activesupport", "~> 6.0.0"
end

appraise "activerecord_6_1" do
gem "activerecord", "~> 6.1.0"
gem "activesupport", "~> 6.1.0"
gem "pg", "~> 1.1"
end
4 changes: 2 additions & 2 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', '< 6.1'
gem.add_runtime_dependency 'activesupport', '>= 4.2', '< 6.1'
gem.add_runtime_dependency 'activerecord', '>= 4.2', '< 6.2'
gem.add_runtime_dependency 'activesupport', '>= 4.2', '< 6.2'

gem.add_development_dependency 'rspec', '~> 3.5.0'
gem.add_development_dependency 'guard', '~> 2.6.1'
Expand Down
1 change: 1 addition & 0 deletions gemfiles/activerecord_4_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ source "https://rubygems.org"
gem "activerecord", "~> 4.2.0"
gem "activesupport", "~> 4.2.0"
gem "sqlite3", "~> 1.3.0"
gem "bigdecimal", "1.3.5"

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

gem "activerecord", "~> 5.0.0"
gem "activesupport", "~> 5.0.0"
gem "sqlite3", "~> 1.3.6"

gemspec :path => "../"
9 changes: 9 additions & 0 deletions gemfiles/activerecord_6_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", "~> 6.1.0"
gem "activesupport", "~> 6.1.0"
gem "pg", "~> 1.1"

gemspec :path => "../"
4 changes: 4 additions & 0 deletions lib/crypt_keeper/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ module SQL
def escape_and_execute_sql(query, new_transaction: false)
query = ::ActiveRecord::Base.send :sanitize_sql_array, query

# force binary encoding to avoid "invalid byte sequence in UTF-8" errors
# when we send binary AES keys (f.ex) to the database
query = query.b if query.respond_to?(:b)

if CryptKeeper.silence_logs?
::ActiveRecord::Base.logger.silence do
execute_sql(query, new_transaction: new_transaction)
Expand Down
19 changes: 17 additions & 2 deletions spec/crypt_keeper/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
end

it "allows binary as a valid type" do
subject.crypt_keeper :storage, encryptor: :fake_encryptor
allow(subject.columns_hash['storage']).to receive(:type).and_return(:binary)
subject.crypt_keeper :storage_binary, encryptor: :fake_encryptor
expect(subject.new.save).to be_truthy
end

Expand Down Expand Up @@ -55,6 +54,7 @@
end
end


context "Encryption and Decryption" do
let(:plain_text) { 'plain_text' }
let(:cipher_text) { 'tooltxet_nialp' }
Expand Down Expand Up @@ -105,6 +105,21 @@
expect_any_instance_of(CryptKeeper::Provider::Encryptor).to_not receive(:decrypt)
subject.find(record.id).storage
end

context "with a binary database field" do
subject { create_encrypted_model :storage_binary, passphrase: 'tool', encryptor: :encryptor }

it "encrypts the data" do
expect_any_instance_of(CryptKeeper::Provider::Encryptor).to receive(:encrypt).with('testing')
subject.create!(storage_binary: 'testing')
end

it "decrypts the data" do
record = subject.create!(storage_binary: 'testing')
expect_any_instance_of(CryptKeeper::Provider::Encryptor).to receive(:decrypt).at_least(1).times.with('toolgnitset')
subject.find(record.id).storage_binary
end
end
end

context "Search" do
Expand Down
1 change: 1 addition & 0 deletions spec/support/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def define_schema!
create_table :sensitive_data, :force => true do |t|
t.column :name, :string
t.column :storage, :text
t.column :storage_binary, :binary
t.column :secret, :text
end
end
Expand Down

0 comments on commit 12e2644

Please sign in to comment.