Skip to content

Commit 12e2644

Browse files
authored
Merge pull request jmazzi#188 from nikz/allow-6-1
Allows Rails 6.1
2 parents 6994db6 + a7499fb commit 12e2644

File tree

9 files changed

+57
-5
lines changed

9 files changed

+57
-5
lines changed

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ rvm:
66
- 2.4.5
77
- 2.5.3
88
- 2.6.4
9+
- 2.7.2
910

1011
gemfile:
1112
- gemfiles/activerecord_4_2.gemfile
1213
- gemfiles/activerecord_5_0.gemfile
1314
- gemfiles/activerecord_5_1.gemfile
1415
- gemfiles/activerecord_5_2.gemfile
1516
- gemfiles/activerecord_6_0.gemfile
17+
- gemfiles/activerecord_6_1.gemfile
18+
1619

1720
matrix:
1821
exclude:
@@ -22,18 +25,24 @@ matrix:
2225
gemfile: gemfiles/activerecord_5_1.gemfile
2326
- rvm: 2.2.10
2427
gemfile: gemfiles/activerecord_6_0.gemfile
28+
- rvm: 2.2.10
29+
gemfile: gemfiles/activerecord_6_1.gemfile
2530
- rvm: 2.3.8
2631
gemfile: gemfiles/activerecord_5_0.gemfile
2732
- rvm: 2.3.8
2833
gemfile: gemfiles/activerecord_5_1.gemfile
2934
- rvm: 2.3.8
3035
gemfile: gemfiles/activerecord_6_0.gemfile
36+
- rvm: 2.3.8
37+
gemfile: gemfiles/activerecord_6_1.gemfile
3138
- rvm: 2.4.5
3239
gemfile: gemfiles/activerecord_5_0.gemfile
3340
- rvm: 2.4.5
3441
gemfile: gemfiles/activerecord_5_1.gemfile
3542
- rvm: 2.4.5
3643
gemfile: gemfiles/activerecord_6_0.gemfile
44+
- rvm: 2.4.5
45+
gemfile: gemfiles/activerecord_6_1.gemfile
3746
- rvm: 2.5.3
3847
gemfile: gemfiles/activerecord_5_0.gemfile
3948
- rvm: 2.5.3
@@ -53,7 +62,8 @@ before_script:
5362
- psql crypt_keeper_providers -c 'CREATE EXTENSION IF NOT EXISTS pgcrypto;' -U postgres
5463
- mysql -e 'CREATE DATABASE crypt_keeper_providers'
5564

56-
branches: master
65+
branches:
66+
- master
5767

5868
notifications:
5969
email:

Appraisals

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ appraise "activerecord_4_2" do
22
gem "activerecord", "~> 4.2.0"
33
gem "activesupport", "~> 4.2.0"
44
gem "sqlite3", "~> 1.3.0"
5+
6+
# otherwise you get "undefined method `new' for BigDecimal:Class" in Ruby 2.7
7+
gem "bigdecimal", "1.3.5"
58
end
69

710
appraise "activerecord_5_0" do
811
gem "activerecord", "~> 5.0.0"
912
gem "activesupport", "~> 5.0.0"
13+
14+
gem "sqlite3", "~> 1.3.6"
1015
end
1116

1217
appraise "activerecord_5_1" do
@@ -23,3 +28,9 @@ appraise "activerecord_6_0" do
2328
gem "activerecord", "~> 6.0.0"
2429
gem "activesupport", "~> 6.0.0"
2530
end
31+
32+
appraise "activerecord_6_1" do
33+
gem "activerecord", "~> 6.1.0"
34+
gem "activesupport", "~> 6.1.0"
35+
gem "pg", "~> 1.1"
36+
end

crypt_keeper.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Gem::Specification.new do |gem|
1818

1919
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."
2020

21-
gem.add_runtime_dependency 'activerecord', '>= 4.2', '< 6.1'
22-
gem.add_runtime_dependency 'activesupport', '>= 4.2', '< 6.1'
21+
gem.add_runtime_dependency 'activerecord', '>= 4.2', '< 6.2'
22+
gem.add_runtime_dependency 'activesupport', '>= 4.2', '< 6.2'
2323

2424
gem.add_development_dependency 'rspec', '~> 3.5.0'
2525
gem.add_development_dependency 'guard', '~> 2.6.1'

gemfiles/activerecord_4_2.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ source "https://rubygems.org"
55
gem "activerecord", "~> 4.2.0"
66
gem "activesupport", "~> 4.2.0"
77
gem "sqlite3", "~> 1.3.0"
8+
gem "bigdecimal", "1.3.5"
89

910
gemspec :path => "../"

gemfiles/activerecord_5_0.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ source "https://rubygems.org"
44

55
gem "activerecord", "~> 5.0.0"
66
gem "activesupport", "~> 5.0.0"
7+
gem "sqlite3", "~> 1.3.6"
78

89
gemspec :path => "../"

gemfiles/activerecord_6_1.gemfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "activerecord", "~> 6.1.0"
6+
gem "activesupport", "~> 6.1.0"
7+
gem "pg", "~> 1.1"
8+
9+
gemspec :path => "../"

lib/crypt_keeper/helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ module SQL
1212
def escape_and_execute_sql(query, new_transaction: false)
1313
query = ::ActiveRecord::Base.send :sanitize_sql_array, query
1414

15+
# force binary encoding to avoid "invalid byte sequence in UTF-8" errors
16+
# when we send binary AES keys (f.ex) to the database
17+
query = query.b if query.respond_to?(:b)
18+
1519
if CryptKeeper.silence_logs?
1620
::ActiveRecord::Base.logger.silence do
1721
execute_sql(query, new_transaction: new_transaction)

spec/crypt_keeper/model_spec.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
end
2626

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

@@ -55,6 +54,7 @@
5554
end
5655
end
5756

57+
5858
context "Encryption and Decryption" do
5959
let(:plain_text) { 'plain_text' }
6060
let(:cipher_text) { 'tooltxet_nialp' }
@@ -105,6 +105,21 @@
105105
expect_any_instance_of(CryptKeeper::Provider::Encryptor).to_not receive(:decrypt)
106106
subject.find(record.id).storage
107107
end
108+
109+
context "with a binary database field" do
110+
subject { create_encrypted_model :storage_binary, passphrase: 'tool', encryptor: :encryptor }
111+
112+
it "encrypts the data" do
113+
expect_any_instance_of(CryptKeeper::Provider::Encryptor).to receive(:encrypt).with('testing')
114+
subject.create!(storage_binary: 'testing')
115+
end
116+
117+
it "decrypts the data" do
118+
record = subject.create!(storage_binary: 'testing')
119+
expect_any_instance_of(CryptKeeper::Provider::Encryptor).to receive(:decrypt).at_least(1).times.with('toolgnitset')
120+
subject.find(record.id).storage_binary
121+
end
122+
end
108123
end
109124

110125
context "Search" do

spec/support/active_record.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def define_schema!
1818
create_table :sensitive_data, :force => true do |t|
1919
t.column :name, :string
2020
t.column :storage, :text
21+
t.column :storage_binary, :binary
2122
t.column :secret, :text
2223
end
2324
end

0 commit comments

Comments
 (0)