attr_encrypted 1.4.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +6 -0
- data/.travis.yml +24 -0
- data/CHANGELOG.md +71 -0
- data/Gemfile +3 -0
- data/README.md +420 -0
- data/Rakefile +3 -15
- data/attr_encrypted.gemspec +60 -0
- data/certs/saghaulor.pem +21 -0
- data/lib/attr_encrypted.rb +197 -114
- data/lib/attr_encrypted/adapters/active_record.rb +8 -8
- data/lib/attr_encrypted/adapters/data_mapper.rb +1 -0
- data/lib/attr_encrypted/adapters/sequel.rb +1 -0
- data/lib/attr_encrypted/version.rb +2 -2
- data/test/active_record_test.rb +40 -18
- data/test/attr_encrypted_test.rb +101 -39
- data/test/compatibility_test.rb +19 -36
- data/test/data_mapper_test.rb +1 -1
- data/test/legacy_active_record_test.rb +11 -7
- data/test/legacy_attr_encrypted_test.rb +17 -16
- data/test/legacy_compatibility_test.rb +21 -30
- data/test/legacy_data_mapper_test.rb +6 -3
- data/test/legacy_sequel_test.rb +8 -4
- data/test/run.sh +12 -52
- data/test/sequel_test.rb +1 -1
- data/test/test_helper.rb +27 -17
- metadata +62 -28
- metadata.gz.sig +2 -0
- data/README.rdoc +0 -344
data/test/compatibility_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
require_relative 'test_helper'
|
3
3
|
|
4
4
|
# Test to ensure that existing representations in database do not break on
|
5
5
|
# migrating to new versions of this gem. This ensures that future versions of
|
@@ -13,11 +13,13 @@ class CompatibilityTest < Minitest::Test
|
|
13
13
|
PET_BIRTHDATE_KEY = 'my-really-really-secret-pet-birthdate-key'
|
14
14
|
|
15
15
|
self.attr_encrypted_options[:mode] = :per_attribute_iv_and_salt
|
16
|
+
self.attr_encrypted_options[:algorithm] = 'aes-256-cbc'
|
17
|
+
self.attr_encrypted_options[:insecure_mode] = true
|
16
18
|
|
17
19
|
attr_encrypted :nickname,
|
18
|
-
:key => proc { Encryptor.encrypt(:value => PET_NICKNAME_SALT, :key => PET_NICKNAME_KEY) }
|
20
|
+
:key => proc { Encryptor.encrypt(:value => PET_NICKNAME_SALT, :key => PET_NICKNAME_KEY, insecure_mode: true, algorithm: 'aes-256-cbc') }
|
19
21
|
attr_encrypted :birthdate,
|
20
|
-
:key => proc { Encryptor.encrypt(:value => PET_BIRTHDATE_SALT, :key => PET_BIRTHDATE_KEY) }
|
22
|
+
:key => proc { Encryptor.encrypt(:value => PET_BIRTHDATE_SALT, :key => PET_BIRTHDATE_KEY, insecure_mode: true, algorithm: 'aes-256-cbc') }
|
21
23
|
end
|
22
24
|
|
23
25
|
class MarshallingPet < ActiveRecord::Base
|
@@ -27,12 +29,14 @@ class CompatibilityTest < Minitest::Test
|
|
27
29
|
PET_BIRTHDATE_KEY = 'my-really-really-secret-pet-birthdate-key'
|
28
30
|
|
29
31
|
self.attr_encrypted_options[:mode] = :per_attribute_iv_and_salt
|
32
|
+
self.attr_encrypted_options[:algorithm] = 'aes-256-cbc'
|
33
|
+
self.attr_encrypted_options[:insecure_mode] = true
|
30
34
|
|
31
35
|
attr_encrypted :nickname,
|
32
|
-
:key => proc { Encryptor.encrypt(:value => PET_NICKNAME_SALT, :key => PET_NICKNAME_KEY) },
|
36
|
+
:key => proc { Encryptor.encrypt(:value => PET_NICKNAME_SALT, :key => PET_NICKNAME_KEY, insecure_mode: true, algorithm: 'aes-256-cbc') },
|
33
37
|
:marshal => true
|
34
38
|
attr_encrypted :birthdate,
|
35
|
-
:key => proc { Encryptor.encrypt(:value => PET_BIRTHDATE_SALT, :key => PET_BIRTHDATE_KEY) },
|
39
|
+
:key => proc { Encryptor.encrypt(:value => PET_BIRTHDATE_SALT, :key => PET_BIRTHDATE_KEY, insecure_mode: true, algorithm: 'aes-256-cbc') },
|
36
40
|
:marshal => true
|
37
41
|
end
|
38
42
|
|
@@ -58,40 +62,20 @@ class CompatibilityTest < Minitest::Test
|
|
58
62
|
end
|
59
63
|
|
60
64
|
def test_marshalling_backwards_compatibility
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
:encrypted_birthdate => '4nbCEzcj6CjLd3B9liKm9Q==',
|
71
|
-
:encrypted_birthdate_iv => 'Vt10PQZMrbamh/gmjSLdkQ==',
|
72
|
-
:encrypted_birthdate_salt => 'cfb245a3df76404f'
|
73
|
-
)
|
74
|
-
else
|
75
|
-
pet = MarshallingPet.create!(
|
76
|
-
:name => 'Fido',
|
77
|
-
:encrypted_nickname => 'EsQScJYkPw80vVGvKWkE37Px99HHpXPFjoEPTNa4rbs=',
|
78
|
-
:encrypted_nickname_iv => 'fNq1OZcGvty4KfcvGTcFSw==',
|
79
|
-
:encrypted_nickname_salt => '733b459b7d34c217',
|
80
|
-
:encrypted_birthdate => '+VUlKQGfNWkOgCwI4hv+3qlGIwh9h6cJ/ranJlaxvU+xxQdL3H3cOzTcI2rkYkdR',
|
81
|
-
:encrypted_birthdate_iv => 'Ka+zF/SwEYZKwVa24lvFfA==',
|
82
|
-
:encrypted_birthdate_salt => 'd5e892d5bbd81566'
|
83
|
-
)
|
84
|
-
end
|
65
|
+
pet = MarshallingPet.create!(
|
66
|
+
:name => 'Fido',
|
67
|
+
:encrypted_nickname => 'EsQScJYkPw80vVGvKWkE37Px99HHpXPFjoEPTNa4rbs=',
|
68
|
+
:encrypted_nickname_iv => 'fNq1OZcGvty4KfcvGTcFSw==',
|
69
|
+
:encrypted_nickname_salt => '733b459b7d34c217',
|
70
|
+
:encrypted_birthdate => '+VUlKQGfNWkOgCwI4hv+3qlGIwh9h6cJ/ranJlaxvU+xxQdL3H3cOzTcI2rkYkdR',
|
71
|
+
:encrypted_birthdate_iv => 'Ka+zF/SwEYZKwVa24lvFfA==',
|
72
|
+
:encrypted_birthdate_salt => 'd5e892d5bbd81566'
|
73
|
+
)
|
85
74
|
|
86
75
|
assert_equal 'Fido', pet.name
|
87
76
|
assert_equal 'Mummy\'s little helper', pet.nickname
|
88
77
|
|
89
|
-
|
90
|
-
if RUBY_VERSION < '1.9.3'
|
91
|
-
assert_equal '2011-07-09', pet.birthdate
|
92
|
-
else
|
93
|
-
assert_equal Date.new(2011, 7, 9), pet.birthdate
|
94
|
-
end
|
78
|
+
assert_equal Date.new(2011, 7, 9), pet.birthdate
|
95
79
|
end
|
96
80
|
|
97
81
|
private
|
@@ -123,4 +107,3 @@ class CompatibilityTest < Minitest::Test
|
|
123
107
|
end
|
124
108
|
|
125
109
|
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
|
126
|
-
|
data/test/data_mapper_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
require_relative 'test_helper'
|
3
3
|
|
4
4
|
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
|
5
5
|
|
@@ -22,8 +22,12 @@ create_people_table
|
|
22
22
|
ActiveRecord::MissingAttributeError = ActiveModel::MissingAttributeError unless defined?(ActiveRecord::MissingAttributeError)
|
23
23
|
|
24
24
|
class LegacyPerson < ActiveRecord::Base
|
25
|
+
self.attr_encrypted_options[:insecure_mode] = true
|
26
|
+
self.attr_encrypted_options[:algorithm] = 'aes-256-cbc'
|
27
|
+
self.attr_encrypted_options[:mode] = :single_iv_and_salt
|
28
|
+
|
25
29
|
attr_encrypted :email, :key => 'a secret key'
|
26
|
-
attr_encrypted :credentials, :key => Proc.new { |user| Encryptor.encrypt(:value => user.salt, :key => 'some private key') }, :marshal => true
|
30
|
+
attr_encrypted :credentials, :key => Proc.new { |user| Encryptor.encrypt(:value => user.salt, :key => 'some private key', insecure_mode: true, algorithm: 'aes-256-cbc') }, :marshal => true
|
27
31
|
|
28
32
|
ActiveSupport::Deprecation.silenced = true
|
29
33
|
def after_initialize; end
|
@@ -55,7 +59,7 @@ class LegacyActiveRecordTest < Minitest::Test
|
|
55
59
|
def test_should_decrypt_with_correct_encoding
|
56
60
|
if defined?(Encoding)
|
57
61
|
@person = LegacyPerson.create :email => 'test@example.com'
|
58
|
-
assert_equal 'UTF-8', LegacyPerson.
|
62
|
+
assert_equal 'UTF-8', LegacyPerson.first.email.encoding.name
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
@@ -63,14 +67,14 @@ class LegacyActiveRecordTest < Minitest::Test
|
|
63
67
|
@person = LegacyPerson.create :email => 'test@example.com'
|
64
68
|
refute_nil @person.encrypted_email
|
65
69
|
refute_equal @person.email, @person.encrypted_email
|
66
|
-
assert_equal @person.email, LegacyPerson.
|
70
|
+
assert_equal @person.email, LegacyPerson.first.email
|
67
71
|
end
|
68
72
|
|
69
73
|
def test_should_marshal_and_encrypt_credentials
|
70
74
|
@person = LegacyPerson.create
|
71
75
|
refute_nil @person.encrypted_credentials
|
72
76
|
refute_equal @person.credentials, @person.encrypted_credentials
|
73
|
-
assert_equal @person.credentials, LegacyPerson.
|
77
|
+
assert_equal @person.credentials, LegacyPerson.first.credentials
|
74
78
|
end
|
75
79
|
|
76
80
|
def test_should_find_by_email
|
@@ -86,13 +90,13 @@ class LegacyActiveRecordTest < Minitest::Test
|
|
86
90
|
|
87
91
|
def test_should_scope_by_email
|
88
92
|
@person = LegacyPerson.create(:email => 'test@example.com')
|
89
|
-
assert_equal @person, LegacyPerson.scoped_by_email('test@example.com').
|
93
|
+
assert_equal @person, LegacyPerson.scoped_by_email('test@example.com').first rescue NoMethodError
|
90
94
|
end
|
91
95
|
|
92
96
|
def test_should_scope_by_email_and_password
|
93
97
|
LegacyPerson.create(:email => 'test@example.com', :password => 'invalid')
|
94
98
|
@person = LegacyPerson.create(:email => 'test@example.com', :password => 'test')
|
95
|
-
assert_equal @person, LegacyPerson.scoped_by_email_and_password('test@example.com', 'test').
|
99
|
+
assert_equal @person, LegacyPerson.scoped_by_email_and_password('test@example.com', 'test').first rescue NoMethodError
|
96
100
|
end
|
97
101
|
|
98
102
|
def test_should_encode_by_default
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
require_relative 'test_helper'
|
3
3
|
|
4
4
|
class LegacySillyEncryptor
|
5
5
|
def self.silly_encrypt(options)
|
@@ -12,7 +12,11 @@ class LegacySillyEncryptor
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class LegacyUser
|
15
|
+
extend AttrEncrypted
|
15
16
|
self.attr_encrypted_options[:key] = Proc.new { |user| user.class.to_s } # default key
|
17
|
+
self.attr_encrypted_options[:insecure_mode] = true
|
18
|
+
self.attr_encrypted_options[:algorithm] = 'aes-256-cbc'
|
19
|
+
self.attr_encrypted_options[:mode] = :single_iv_and_salt
|
16
20
|
|
17
21
|
attr_encrypted :email, :without_encoding, :key => 'secret key'
|
18
22
|
attr_encrypted :password, :prefix => 'crypted_', :suffix => '_test'
|
@@ -43,6 +47,7 @@ class LegacyAdmin < LegacyUser
|
|
43
47
|
end
|
44
48
|
|
45
49
|
class LegacySomeOtherClass
|
50
|
+
extend AttrEncrypted
|
46
51
|
def self.call(object)
|
47
52
|
object.class
|
48
53
|
end
|
@@ -174,7 +179,7 @@ class LegacyAttrEncryptedTest < Minitest::Test
|
|
174
179
|
assert_nil @user.ssn_encrypted
|
175
180
|
@user.ssn = 'testing'
|
176
181
|
refute_nil @user.ssn_encrypted
|
177
|
-
assert_equal Encryptor.encrypt(:value => 'testing', :key => @user.salt), @user.ssn_encrypted
|
182
|
+
assert_equal Encryptor.encrypt(:value => 'testing', :key => @user.salt, insecure_mode: true, algorithm: 'aes-256-cbc'), @user.ssn_encrypted
|
178
183
|
end
|
179
184
|
|
180
185
|
def test_should_evaluate_a_key_passed_as_a_proc
|
@@ -182,7 +187,7 @@ class LegacyAttrEncryptedTest < Minitest::Test
|
|
182
187
|
assert_nil @user.crypted_password_test
|
183
188
|
@user.password = 'testing'
|
184
189
|
refute_nil @user.crypted_password_test
|
185
|
-
assert_equal Encryptor.encrypt(:value => 'testing', :key => 'LegacyUser'), @user.crypted_password_test
|
190
|
+
assert_equal Encryptor.encrypt(:value => 'testing', :key => 'LegacyUser', insecure_mode: true, algorithm: 'aes-256-cbc'), @user.crypted_password_test
|
186
191
|
end
|
187
192
|
|
188
193
|
def test_should_use_options_found_in_the_attr_encrypted_options_attribute
|
@@ -190,7 +195,7 @@ class LegacyAttrEncryptedTest < Minitest::Test
|
|
190
195
|
assert_nil @user.crypted_password_test
|
191
196
|
@user.password = 'testing'
|
192
197
|
refute_nil @user.crypted_password_test
|
193
|
-
assert_equal Encryptor.encrypt(:value => 'testing', :key => 'LegacyUser'), @user.crypted_password_test
|
198
|
+
assert_equal Encryptor.encrypt(:value => 'testing', :key => 'LegacyUser', insecure_mode: true, algorithm: 'aes-256-cbc'), @user.crypted_password_test
|
194
199
|
end
|
195
200
|
|
196
201
|
def test_should_inherit_encrypted_attributes
|
@@ -208,23 +213,24 @@ class LegacyAttrEncryptedTest < Minitest::Test
|
|
208
213
|
end
|
209
214
|
|
210
215
|
def test_should_evaluate_a_symbol_option
|
211
|
-
assert_equal
|
216
|
+
assert_equal LegacySomeOtherClass, LegacySomeOtherClass.new.send(:evaluate_attr_encrypted_option, :class)
|
212
217
|
end
|
213
218
|
|
214
219
|
def test_should_evaluate_a_proc_option
|
215
|
-
assert_equal
|
220
|
+
assert_equal LegacySomeOtherClass, LegacySomeOtherClass.new.send(:evaluate_attr_encrypted_option, proc { |object| object.class })
|
216
221
|
end
|
217
222
|
|
218
223
|
def test_should_evaluate_a_lambda_option
|
219
|
-
assert_equal
|
224
|
+
assert_equal LegacySomeOtherClass, LegacySomeOtherClass.new.send(:evaluate_attr_encrypted_option, lambda { |object| object.class })
|
220
225
|
end
|
221
226
|
|
222
227
|
def test_should_evaluate_a_method_option
|
223
|
-
assert_equal
|
228
|
+
assert_equal LegacySomeOtherClass, LegacySomeOtherClass.new.send(:evaluate_attr_encrypted_option, LegacySomeOtherClass.method(:call))
|
224
229
|
end
|
225
230
|
|
226
231
|
def test_should_return_a_string_option
|
227
|
-
|
232
|
+
class_string = 'LegacySomeOtherClass'
|
233
|
+
assert_equal class_string, LegacySomeOtherClass.new.send(:evaluate_attr_encrypted_option, class_string)
|
228
234
|
end
|
229
235
|
|
230
236
|
def test_should_encrypt_with_true_if
|
@@ -232,7 +238,7 @@ class LegacyAttrEncryptedTest < Minitest::Test
|
|
232
238
|
assert_nil @user.encrypted_with_true_if
|
233
239
|
@user.with_true_if = 'testing'
|
234
240
|
refute_nil @user.encrypted_with_true_if
|
235
|
-
assert_equal Encryptor.encrypt(:value => 'testing', :key => 'secret key'), @user.encrypted_with_true_if
|
241
|
+
assert_equal Encryptor.encrypt(:value => 'testing', :key => 'secret key', insecure_mode: true, algorithm: 'aes-256-cbc'), @user.encrypted_with_true_if
|
236
242
|
end
|
237
243
|
|
238
244
|
def test_should_not_encrypt_with_false_if
|
@@ -248,7 +254,7 @@ class LegacyAttrEncryptedTest < Minitest::Test
|
|
248
254
|
assert_nil @user.encrypted_with_false_unless
|
249
255
|
@user.with_false_unless = 'testing'
|
250
256
|
refute_nil @user.encrypted_with_false_unless
|
251
|
-
assert_equal Encryptor.encrypt(:value => 'testing', :key => 'secret key'), @user.encrypted_with_false_unless
|
257
|
+
assert_equal Encryptor.encrypt(:value => 'testing', :key => 'secret key', insecure_mode: true, algorithm: 'aes-256-cbc'), @user.encrypted_with_false_unless
|
252
258
|
end
|
253
259
|
|
254
260
|
def test_should_not_encrypt_with_true_unless
|
@@ -266,11 +272,6 @@ class LegacyAttrEncryptedTest < Minitest::Test
|
|
266
272
|
def test_should_always_reset_options
|
267
273
|
@user = LegacyUser.new
|
268
274
|
@user.with_if_changed = "encrypt_stuff"
|
269
|
-
@user.stubs(:instance_variable_get).returns(nil)
|
270
|
-
@user.stubs(:instance_variable_set).raises("BadStuff")
|
271
|
-
assert_raises RuntimeError do
|
272
|
-
@user.with_if_changed
|
273
|
-
end
|
274
275
|
|
275
276
|
@user = LegacyUser.new
|
276
277
|
@user.should_encrypt = false
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
require_relative 'test_helper'
|
3
3
|
|
4
4
|
# Test to ensure that existing representations in database do not break on
|
5
5
|
# migrating to new versions of this gem. This ensures that future versions of
|
@@ -12,10 +12,14 @@ class LegacyCompatibilityTest < Minitest::Test
|
|
12
12
|
PET_BIRTHDATE_SALT = Digest::SHA256.hexdigest('my-really-really-secret-pet-birthdate-salt')
|
13
13
|
PET_BIRTHDATE_KEY = 'my-really-really-secret-pet-birthdate-key'
|
14
14
|
|
15
|
+
self.attr_encrypted_options[:insecure_mode] = true
|
16
|
+
self.attr_encrypted_options[:algorithm] = 'aes-256-cbc'
|
17
|
+
self.attr_encrypted_options[:mode] = :single_iv_and_salt
|
18
|
+
|
15
19
|
attr_encrypted :nickname,
|
16
|
-
:key => proc { Encryptor.encrypt(:value => PET_NICKNAME_SALT, :key => PET_NICKNAME_KEY) }
|
20
|
+
:key => proc { Encryptor.encrypt(:value => PET_NICKNAME_SALT, :key => PET_NICKNAME_KEY, insecure_mode: true, algorithm: 'aes-256-cbc') }
|
17
21
|
attr_encrypted :birthdate,
|
18
|
-
:key => proc { Encryptor.encrypt(:value => PET_BIRTHDATE_SALT, :key => PET_BIRTHDATE_KEY) }
|
22
|
+
:key => proc { Encryptor.encrypt(:value => PET_BIRTHDATE_SALT, :key => PET_BIRTHDATE_KEY, insecure_mode: true, algorithm: 'aes-256-cbc') }
|
19
23
|
end
|
20
24
|
|
21
25
|
class LegacyMarshallingPet < ActiveRecord::Base
|
@@ -24,12 +28,16 @@ class LegacyCompatibilityTest < Minitest::Test
|
|
24
28
|
PET_BIRTHDATE_SALT = Digest::SHA256.hexdigest('my-really-really-secret-pet-birthdate-salt')
|
25
29
|
PET_BIRTHDATE_KEY = 'my-really-really-secret-pet-birthdate-key'
|
26
30
|
|
31
|
+
self.attr_encrypted_options[:insecure_mode] = true
|
32
|
+
self.attr_encrypted_options[:algorithm] = 'aes-256-cbc'
|
33
|
+
self.attr_encrypted_options[:mode] = :single_iv_and_salt
|
34
|
+
|
27
35
|
attr_encrypted :nickname,
|
28
|
-
|
29
|
-
|
36
|
+
:key => proc { Encryptor.encrypt(:value => PET_NICKNAME_SALT, :key => PET_NICKNAME_KEY, insecure_mode: true, algorithm: 'aes-256-cbc') },
|
37
|
+
:marshal => true
|
30
38
|
attr_encrypted :birthdate,
|
31
|
-
|
32
|
-
|
39
|
+
:key => proc { Encryptor.encrypt(:value => PET_BIRTHDATE_SALT, :key => PET_BIRTHDATE_KEY, insecure_mode: true, algorithm: 'aes-256-cbc') },
|
40
|
+
:marshal => true
|
33
41
|
end
|
34
42
|
|
35
43
|
def setup
|
@@ -50,32 +58,16 @@ class LegacyCompatibilityTest < Minitest::Test
|
|
50
58
|
end
|
51
59
|
|
52
60
|
def test_marshalling_backwards_compatibility
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
:name => 'Fido',
|
59
|
-
:encrypted_nickname => 'xhayxWxfkfbNyOS2w1qBMPV49Gfvs6dcZFBopMK2zQA=',
|
60
|
-
:encrypted_birthdate => 'f4ufXun4GXzahH4MQ1eTBQ=='
|
61
|
-
)
|
62
|
-
else
|
63
|
-
pet = LegacyMarshallingPet.create!(
|
64
|
-
:name => 'Fido',
|
65
|
-
:encrypted_nickname => '7RwoT64in4H+fGVBPYtRcN0K4RtriIy1EP4nDojUa8g=',
|
66
|
-
:encrypted_birthdate => 'bSp9sJhXQSp2QlNZHiujtcK4lRVBE8HQhn1y7moQ63bGJR20hvRSZ73ePAmm+wc5'
|
67
|
-
)
|
68
|
-
end
|
61
|
+
pet = LegacyMarshallingPet.create!(
|
62
|
+
:name => 'Fido',
|
63
|
+
:encrypted_nickname => '7RwoT64in4H+fGVBPYtRcN0K4RtriIy1EP4nDojUa8g=',
|
64
|
+
:encrypted_birthdate => 'bSp9sJhXQSp2QlNZHiujtcK4lRVBE8HQhn1y7moQ63bGJR20hvRSZ73ePAmm+wc5'
|
65
|
+
)
|
69
66
|
|
70
67
|
assert_equal 'Fido', pet.name
|
71
68
|
assert_equal 'Mummy\'s little helper', pet.nickname
|
72
69
|
|
73
|
-
|
74
|
-
if RUBY_VERSION < '1.9.3'
|
75
|
-
assert_equal '2011-07-09', pet.birthdate
|
76
|
-
else
|
77
|
-
assert_equal Date.new(2011, 7, 9), pet.birthdate
|
78
|
-
end
|
70
|
+
assert_equal Date.new(2011, 7, 9), pet.birthdate
|
79
71
|
end
|
80
72
|
|
81
73
|
private
|
@@ -101,4 +93,3 @@ class LegacyCompatibilityTest < Minitest::Test
|
|
101
93
|
end
|
102
94
|
|
103
95
|
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
|
104
|
-
|
@@ -1,17 +1,20 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
|
3
3
|
DataMapper.setup(:default, 'sqlite3::memory:')
|
4
4
|
|
5
5
|
class LegacyClient
|
6
6
|
include DataMapper::Resource
|
7
|
+
self.attr_encrypted_options[:insecure_mode] = true
|
8
|
+
self.attr_encrypted_options[:algorithm] = 'aes-256-cbc'
|
9
|
+
self.attr_encrypted_options[:mode] = :single_iv_and_salt
|
7
10
|
|
8
11
|
property :id, Serial
|
9
12
|
property :encrypted_email, String
|
10
13
|
property :encrypted_credentials, Text
|
11
14
|
property :salt, String
|
12
15
|
|
13
|
-
attr_encrypted :email, :key => 'a secret key'
|
14
|
-
attr_encrypted :credentials, :key => Proc.new { |client| Encryptor.encrypt(:value => client.salt, :key => 'some private key') }, :marshal => true
|
16
|
+
attr_encrypted :email, :key => 'a secret key', mode: :single_iv_and_salt
|
17
|
+
attr_encrypted :credentials, :key => Proc.new { |client| Encryptor.encrypt(:value => client.salt, :key => 'some private key', insecure_mode: true, algorithm: 'aes-256-cbc') }, :marshal => true, mode: :single_iv_and_salt
|
15
18
|
|
16
19
|
def initialize(attrs = {})
|
17
20
|
super attrs
|
data/test/legacy_sequel_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
|
3
3
|
DB.create_table :legacy_humans do
|
4
4
|
primary_key :id
|
@@ -8,9 +8,13 @@ DB.create_table :legacy_humans do
|
|
8
8
|
column :salt, :string
|
9
9
|
end
|
10
10
|
|
11
|
-
class LegacyHuman < Sequel::Model(:legacy_humans)
|
12
|
-
|
13
|
-
|
11
|
+
class LegacyHuman < Sequel::Model(:legacy_humans)
|
12
|
+
self.attr_encrypted_options[:insecure_mode] = true
|
13
|
+
self.attr_encrypted_options[:algorithm] = 'aes-256-cbc'
|
14
|
+
self.attr_encrypted_options[:mode] = :single_iv_and_salt
|
15
|
+
|
16
|
+
attr_encrypted :email, :key => 'a secret key', mode: :single_iv_and_salt
|
17
|
+
attr_encrypted :credentials, :key => Proc.new { |human| Encryptor.encrypt(:value => human.salt, :key => 'some private key', insecure_mode: true, algorithm: 'aes-256-cbc') }, :marshal => true, mode: :single_iv_and_salt
|
14
18
|
|
15
19
|
def after_initialize(attrs = {})
|
16
20
|
self.salt ||= Digest::SHA1.hexdigest((Time.now.to_i * rand(5)).to_s)
|
data/test/run.sh
CHANGED
@@ -1,52 +1,12 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
bundle exec rake
|
11
|
-
|
12
|
-
|
13
|
-
bundle exec rake
|
14
|
-
export ACTIVERECORD=3.1.0
|
15
|
-
bundle
|
16
|
-
bundle exec rake
|
17
|
-
export ACTIVERECORD=3.2.0
|
18
|
-
bundle
|
19
|
-
bundle exec rake
|
20
|
-
|
21
|
-
export RBENV_VERSION=1.9.3-p484
|
22
|
-
rbenv version
|
23
|
-
|
24
|
-
export ACTIVERECORD=3.0.0
|
25
|
-
bundle
|
26
|
-
bundle exec rake
|
27
|
-
export ACTIVERECORD=3.1.0
|
28
|
-
bundle
|
29
|
-
bundle exec rake
|
30
|
-
export ACTIVERECORD=3.2.0
|
31
|
-
bundle
|
32
|
-
bundle exec rake
|
33
|
-
export ACTIVERECORD=4.0.0
|
34
|
-
bundle
|
35
|
-
bundle exec rake
|
36
|
-
|
37
|
-
export RBENV_VERSION=2.0.0-p353
|
38
|
-
rbenv version
|
39
|
-
|
40
|
-
export ACTIVERECORD=3.2.0
|
41
|
-
bundle
|
42
|
-
bundle exec rake
|
43
|
-
export ACTIVERECORD=4.0.0
|
44
|
-
bundle
|
45
|
-
bundle exec rake
|
46
|
-
|
47
|
-
export RBENV_VERSION=2.1.0
|
48
|
-
rbenv version
|
49
|
-
|
50
|
-
export ACTIVERECORD=4.0.0
|
51
|
-
bundle
|
52
|
-
bundle exec rake
|
1
|
+
#!/usr/bin/env sh -e
|
2
|
+
|
3
|
+
for RUBY in 1.9.3 2.0.0 2.1 2.2
|
4
|
+
do
|
5
|
+
for RAILS in 2.3.8 3.0.0 3.1.0 3.2.0 4.0.0 4.1.0 4.2.0
|
6
|
+
do
|
7
|
+
if [[ $RUBY -gt 1.9.3 && $RAILS -lt 4.0.0 ]]; then
|
8
|
+
continue
|
9
|
+
fi
|
10
|
+
RBENV_VERSION=$RUBY ACTIVERECORD=$RAILS bundle && bundle exec rake
|
11
|
+
done
|
12
|
+
done
|