symmetric-encryption 3.8.2 → 3.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -9
- data/lib/symmetric_encryption/cipher.rb +2 -2
- data/lib/symmetric_encryption/coerce.rb +18 -1
- data/lib/symmetric_encryption/extensions/active_record/base.rb +1 -1
- data/lib/symmetric_encryption/extensions/mongo_mapper/plugins/encrypted_key.rb +7 -7
- data/lib/symmetric_encryption/extensions/mongoid/encrypted.rb +7 -7
- data/lib/symmetric_encryption/generator.rb +3 -3
- data/lib/symmetric_encryption/version.rb +1 -1
- data/lib/symmetric_encryption/writer.rb +2 -2
- data/test/active_record_test.rb +82 -74
- data/test/cipher_test.rb +26 -26
- data/test/config/mongoid_v5.yml +9 -0
- data/test/mongo_mapper_test.rb +88 -88
- data/test/mongoid_test.rb +98 -90
- data/test/reader_test.rb +17 -18
- data/test/symmetric_encryption_test.rb +62 -62
- data/test/test_db.sqlite3 +0 -0
- data/test/test_helper.rb +8 -2
- data/test/writer_test.rb +4 -4
- metadata +6 -4
data/test/cipher_test.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative 'test_helper'
|
|
5
5
|
class CipherTest < Minitest::Test
|
6
6
|
describe 'standalone' do
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'allow setting the cipher_name' do
|
9
9
|
cipher = SymmetricEncryption::Cipher.new(
|
10
10
|
cipher_name: 'aes-128-cbc',
|
11
11
|
key: '1234567890ABCDEF1234567890ABCDEF',
|
@@ -15,7 +15,7 @@ class CipherTest < Minitest::Test
|
|
15
15
|
assert_equal 'aes-128-cbc', cipher.cipher_name
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'not require an iv' do
|
19
19
|
cipher = SymmetricEncryption::Cipher.new(
|
20
20
|
key: '1234567890ABCDEF1234567890ABCDEF',
|
21
21
|
encoding: :none
|
@@ -29,7 +29,7 @@ class CipherTest < Minitest::Test
|
|
29
29
|
assert_equal result, cipher.encrypt('Hello World')
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it 'throw an exception on bad data' do
|
33
33
|
cipher = SymmetricEncryption::Cipher.new(
|
34
34
|
cipher_name: 'aes-128-cbc',
|
35
35
|
key: '1234567890ABCDEF1234567890ABCDEF',
|
@@ -47,18 +47,18 @@ class CipherTest < Minitest::Test
|
|
47
47
|
SymmetricEncryption::Cipher::ENCODINGS.each do |encoding|
|
48
48
|
describe "encoding: #{encoding} with#{'out' unless always_add_header} header" do
|
49
49
|
before do
|
50
|
-
@social_security_number =
|
50
|
+
@social_security_number = '987654321'
|
51
51
|
@social_security_number_encrypted =
|
52
52
|
case encoding
|
53
53
|
when :base64
|
54
54
|
always_add_header ? "QEVuQwAAyTeLjsHTa8ykoO95K0KQmg==\n" : "yTeLjsHTa8ykoO95K0KQmg==\n"
|
55
55
|
when :base64strict
|
56
|
-
always_add_header ?
|
56
|
+
always_add_header ? 'QEVuQwAAyTeLjsHTa8ykoO95K0KQmg==' : 'yTeLjsHTa8ykoO95K0KQmg=='
|
57
57
|
when :base16
|
58
|
-
always_add_header ?
|
58
|
+
always_add_header ? '40456e430000c9378b8ec1d36bcca4a0ef792b42909a' : 'c9378b8ec1d36bcca4a0ef792b42909a'
|
59
59
|
when :none
|
60
60
|
bin = always_add_header ? "@EnC\x00\x00\xC97\x8B\x8E\xC1\xD3k\xCC\xA4\xA0\xEFy+B\x90\x9A" : "\xC97\x8B\x8E\xC1\xD3k\xCC\xA4\xA0\xEFy+B\x90\x9A"
|
61
|
-
bin.force_encoding(Encoding.find(
|
61
|
+
bin.force_encoding(Encoding.find('binary'))
|
62
62
|
else
|
63
63
|
raise "Add test for encoding: #{encoding}"
|
64
64
|
end
|
@@ -73,11 +73,11 @@ class CipherTest < Minitest::Test
|
|
73
73
|
)
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
76
|
+
it 'encrypt simple string' do
|
77
77
|
assert_equal @social_security_number_encrypted, @cipher.encrypt(@social_security_number)
|
78
78
|
end
|
79
79
|
|
80
|
-
it
|
80
|
+
it 'decrypt string' do
|
81
81
|
assert decrypted = @cipher.decrypt(@social_security_number_encrypted)
|
82
82
|
assert_equal @social_security_number, decrypted
|
83
83
|
assert_equal Encoding.find('utf-8'), decrypted.encoding, decrypted
|
@@ -93,7 +93,7 @@ class CipherTest < Minitest::Test
|
|
93
93
|
assert_equal @non_utf8, decrypted
|
94
94
|
end
|
95
95
|
|
96
|
-
it
|
96
|
+
it 'return nil when encrypting nil' do
|
97
97
|
assert_equal nil, @cipher.encrypt(nil)
|
98
98
|
end
|
99
99
|
|
@@ -101,7 +101,7 @@ class CipherTest < Minitest::Test
|
|
101
101
|
assert_equal '', @cipher.encrypt('')
|
102
102
|
end
|
103
103
|
|
104
|
-
it
|
104
|
+
it 'return nil when decrypting nil' do
|
105
105
|
assert_equal nil, @cipher.decrypt(nil)
|
106
106
|
end
|
107
107
|
|
@@ -119,7 +119,7 @@ class CipherTest < Minitest::Test
|
|
119
119
|
iv: '1234567890ABCDEF',
|
120
120
|
encoding: :none
|
121
121
|
)
|
122
|
-
@social_security_number =
|
122
|
+
@social_security_number = '987654321'
|
123
123
|
|
124
124
|
@social_security_number_encrypted = "A\335*\314\336\250V\340\023%\000S\177\305\372\266"
|
125
125
|
@social_security_number_encrypted.force_encoding('binary') if defined?(Encoding)
|
@@ -133,39 +133,39 @@ class CipherTest < Minitest::Test
|
|
133
133
|
assert_equal 'aes-256-cbc', @cipher.cipher_name
|
134
134
|
end
|
135
135
|
|
136
|
-
describe
|
136
|
+
describe 'with header' do
|
137
137
|
before do
|
138
|
-
@social_security_number =
|
138
|
+
@social_security_number = '987654321'
|
139
139
|
end
|
140
140
|
|
141
|
-
it
|
141
|
+
it 'build and parse header' do
|
142
142
|
assert random_key_pair = SymmetricEncryption::Cipher.random_key_pair('aes-128-cbc')
|
143
|
-
assert binary_header = SymmetricEncryption::Cipher.build_header(SymmetricEncryption.cipher.version,
|
143
|
+
assert binary_header = SymmetricEncryption::Cipher.build_header(SymmetricEncryption.cipher.version, true, random_key_pair[:iv], random_key_pair[:key], random_key_pair[:cipher_name])
|
144
144
|
header = SymmetricEncryption::Cipher.parse_header!(binary_header)
|
145
145
|
assert_equal true, header.compressed
|
146
146
|
assert random_cipher = SymmetricEncryption::Cipher.new(random_key_pair)
|
147
|
-
assert_equal random_cipher.cipher_name, header.cipher_name,
|
148
|
-
assert_equal random_cipher.send(:key), header.key,
|
149
|
-
assert_equal random_cipher.send(:iv), header.iv,
|
147
|
+
assert_equal random_cipher.cipher_name, header.cipher_name, 'Ciphers differ'
|
148
|
+
assert_equal random_cipher.send(:key), header.key, 'Keys differ'
|
149
|
+
assert_equal random_cipher.send(:iv), header.iv, 'IVs differ'
|
150
150
|
|
151
|
-
string =
|
151
|
+
string = 'Hello World'
|
152
152
|
cipher = SymmetricEncryption::Cipher.new(key: header.key, iv: header.iv, cipher_name: header.cipher_name)
|
153
153
|
# Test Encryption
|
154
|
-
assert_equal random_cipher.encrypt(string, false, false), cipher.encrypt(string, false, false),
|
154
|
+
assert_equal random_cipher.encrypt(string, false, false), cipher.encrypt(string, false, false), 'Encrypted values differ'
|
155
155
|
end
|
156
156
|
|
157
|
-
it
|
157
|
+
it 'encrypt and then decrypt without a header' do
|
158
158
|
assert encrypted = @cipher.binary_encrypt(@social_security_number, false, false, false)
|
159
159
|
assert_equal @social_security_number, @cipher.decrypt(encrypted)
|
160
160
|
end
|
161
161
|
|
162
|
-
it
|
163
|
-
assert encrypted = @cipher.encrypt(@social_security_number,
|
162
|
+
it 'encrypt and then decrypt using random iv' do
|
163
|
+
assert encrypted = @cipher.encrypt(@social_security_number, true)
|
164
164
|
assert_equal @social_security_number, @cipher.decrypt(encrypted)
|
165
165
|
end
|
166
166
|
|
167
|
-
it
|
168
|
-
assert encrypted = @cipher.encrypt(@social_security_number,
|
167
|
+
it 'encrypt and then decrypt using random iv with compression' do
|
168
|
+
assert encrypted = @cipher.encrypt(@social_security_number, true, true)
|
169
169
|
assert_equal @social_security_number, @cipher.decrypt(encrypted)
|
170
170
|
end
|
171
171
|
|
data/test/mongo_mapper_test.rb
CHANGED
@@ -46,7 +46,7 @@ begin
|
|
46
46
|
|
47
47
|
validates :username,
|
48
48
|
length: {in: 3..20},
|
49
|
-
format: {with: /\A[\w
|
49
|
+
format: {with: /\A[\w\-]+\z/},
|
50
50
|
allow_blank: true
|
51
51
|
end
|
52
52
|
#@formatter:on
|
@@ -57,27 +57,27 @@ begin
|
|
57
57
|
class MongoMapperTest < Minitest::Test
|
58
58
|
describe 'MongoMapperUser' do
|
59
59
|
before do
|
60
|
-
@bank_account_number =
|
61
|
-
@bank_account_number_encrypted =
|
60
|
+
@bank_account_number = '1234567890'
|
61
|
+
@bank_account_number_encrypted = 'QEVuQwIAL94ArJeFlJrZp6SYsvoOGA=='
|
62
62
|
|
63
|
-
@social_security_number =
|
64
|
-
@social_security_number_encrypted =
|
63
|
+
@social_security_number = '987654321'
|
64
|
+
@social_security_number_encrypted = 'QEVuQwIAS+8X1NRrqdfEIQyFHVPuVA=='
|
65
65
|
|
66
66
|
@integer = 32768
|
67
|
-
@integer_encrypted =
|
67
|
+
@integer_encrypted = 'FA3smFQEKqB/ITv+A0xACg=='
|
68
68
|
|
69
69
|
@float = 0.9867
|
70
|
-
@float_encrypted =
|
70
|
+
@float_encrypted = 'z7Pwt2JDp74d+u0IXFAdrQ=='
|
71
71
|
|
72
72
|
@date = Date.parse('20120320')
|
73
|
-
@date_encrypted =
|
73
|
+
@date_encrypted = 'WTkSPHo5ApSSHBJMxxWt2A=='
|
74
74
|
|
75
|
-
@string =
|
76
|
-
@long_string =
|
75
|
+
@string = 'A string containing some data to be encrypted with a random initialization vector'
|
76
|
+
@long_string = 'A string containing some data to be encrypted with a random initialization vector and compressed since it takes up so much space in plain text form'
|
77
77
|
|
78
78
|
@integer_value = 12
|
79
79
|
@float_value = 88.12345
|
80
|
-
@decimal_value = BigDecimal.new(
|
80
|
+
@decimal_value = BigDecimal.new('22.51')
|
81
81
|
@datetime_value = DateTime.new(2001, 11, 26, 20, 55, 54, "-5")
|
82
82
|
@time_value = Time.new(2013, 01, 01, 22, 30, 00, "-04:00")
|
83
83
|
@date_value = Date.new(1927, 04, 02)
|
@@ -86,7 +86,7 @@ begin
|
|
86
86
|
@user = MongoMapperUser.new(
|
87
87
|
encrypted_bank_account_number: @bank_account_number_encrypted,
|
88
88
|
encrypted_social_security_number: @social_security_number_encrypted,
|
89
|
-
name:
|
89
|
+
name: 'Joe Bloggs',
|
90
90
|
# data type specific fields
|
91
91
|
integer_value: @integer_value,
|
92
92
|
aliased_integer_value: @integer_value,
|
@@ -102,7 +102,7 @@ begin
|
|
102
102
|
)
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
105
|
+
it 'have encrypted methods' do
|
106
106
|
assert_equal true, @user.respond_to?(:encrypted_bank_account_number)
|
107
107
|
assert_equal true, @user.respond_to?(:encrypted_social_security_number)
|
108
108
|
assert_equal true, @user.respond_to?(:encrypted_string)
|
@@ -116,7 +116,7 @@ begin
|
|
116
116
|
assert_equal false, @user.respond_to?(:encrypted_name=)
|
117
117
|
end
|
118
118
|
|
119
|
-
it
|
119
|
+
it 'have unencrypted methods' do
|
120
120
|
assert_equal true, @user.respond_to?(:bank_account_number)
|
121
121
|
assert_equal true, @user.respond_to?(:social_security_number)
|
122
122
|
assert_equal true, @user.respond_to?(:string)
|
@@ -130,22 +130,22 @@ begin
|
|
130
130
|
assert_equal true, @user.respond_to?(:name=)
|
131
131
|
end
|
132
132
|
|
133
|
-
it
|
133
|
+
it 'support aliased fields' do
|
134
134
|
assert_equal true, @user.respond_to?(:aliased_integer_value=)
|
135
135
|
assert_equal true, @user.respond_to?(:aliased_integer_value)
|
136
136
|
end
|
137
137
|
|
138
|
-
it
|
138
|
+
it 'have unencrypted values' do
|
139
139
|
assert_equal @bank_account_number, @user.bank_account_number
|
140
140
|
assert_equal @social_security_number, @user.social_security_number
|
141
141
|
end
|
142
142
|
|
143
|
-
it
|
143
|
+
it 'have encrypted values' do
|
144
144
|
assert_equal @bank_account_number_encrypted, @user.encrypted_bank_account_number
|
145
145
|
assert_equal @social_security_number_encrypted, @user.encrypted_social_security_number
|
146
146
|
end
|
147
147
|
|
148
|
-
it
|
148
|
+
it 'support same iv' do
|
149
149
|
@user.social_security_number = @social_security_number
|
150
150
|
assert first_value = @user.social_security_number
|
151
151
|
# Assign the same value
|
@@ -153,7 +153,7 @@ begin
|
|
153
153
|
assert_equal first_value, @user.social_security_number
|
154
154
|
end
|
155
155
|
|
156
|
-
it
|
156
|
+
it 'support a random iv' do
|
157
157
|
@user.string = @string
|
158
158
|
assert first_value = @user.encrypted_string
|
159
159
|
# Assign the same value
|
@@ -161,26 +161,26 @@ begin
|
|
161
161
|
assert_equal true, first_value != @user.encrypted_string
|
162
162
|
end
|
163
163
|
|
164
|
-
it
|
164
|
+
it 'support a random iv and compress' do
|
165
165
|
@user.string = @long_string
|
166
166
|
@user.long_string = @long_string
|
167
167
|
|
168
168
|
assert_equal true, (@user.encrypted_long_string.length.to_f / @user.encrypted_string.length) < 0.8
|
169
169
|
end
|
170
170
|
|
171
|
-
it
|
171
|
+
it 'encrypt' do
|
172
172
|
user = MongoMapperUser.new
|
173
173
|
user.bank_account_number = @bank_account_number
|
174
174
|
assert_equal @bank_account_number, user.bank_account_number
|
175
175
|
assert_equal @bank_account_number_encrypted, user.encrypted_bank_account_number
|
176
176
|
end
|
177
177
|
|
178
|
-
it
|
178
|
+
it 'all paths it lead to the same result' do
|
179
179
|
assert_equal @bank_account_number_encrypted, (@user.encrypted_social_security_number = @bank_account_number_encrypted)
|
180
180
|
assert_equal @bank_account_number, @user.social_security_number
|
181
181
|
end
|
182
182
|
|
183
|
-
it
|
183
|
+
it 'all paths it lead to the same result 2' do
|
184
184
|
assert_equal @bank_account_number, (@user.social_security_number = @bank_account_number)
|
185
185
|
assert_equal @bank_account_number_encrypted, @user.encrypted_social_security_number
|
186
186
|
end
|
@@ -197,7 +197,7 @@ begin
|
|
197
197
|
assert_equal nil, user.encrypted_social_security_number
|
198
198
|
end
|
199
199
|
|
200
|
-
it
|
200
|
+
it 'allow unencrypted values to be passed to the constructor' do
|
201
201
|
user = MongoMapperUser.new(bank_account_number: @bank_account_number, social_security_number: @social_security_number)
|
202
202
|
assert_equal @bank_account_number, user.bank_account_number
|
203
203
|
assert_equal @social_security_number, user.social_security_number
|
@@ -205,7 +205,7 @@ begin
|
|
205
205
|
assert_equal @social_security_number_encrypted, user.encrypted_social_security_number
|
206
206
|
end
|
207
207
|
|
208
|
-
it
|
208
|
+
it 'allow both encrypted and unencrypted values to be passed to the constructor' do
|
209
209
|
user = MongoMapperUser.new(encrypted_bank_account_number: @bank_account_number_encrypted, social_security_number: @social_security_number)
|
210
210
|
assert_equal @bank_account_number, user.bank_account_number
|
211
211
|
assert_equal @social_security_number, user.social_security_number
|
@@ -234,7 +234,7 @@ begin
|
|
234
234
|
end
|
235
235
|
end
|
236
236
|
|
237
|
-
describe
|
237
|
+
describe 'data types' do
|
238
238
|
before do
|
239
239
|
@user.save!
|
240
240
|
@user_clone = MongoMapperUser.find(@user.id)
|
@@ -244,26 +244,26 @@ begin
|
|
244
244
|
@user.destroy if @user
|
245
245
|
end
|
246
246
|
|
247
|
-
describe
|
248
|
-
it
|
249
|
-
@user_clone.aliased_integer_value =
|
247
|
+
describe 'aliased fields' do
|
248
|
+
it 'return correct data type' do
|
249
|
+
@user_clone.aliased_integer_value = '5'
|
250
250
|
assert_equal 5, @user_clone.aliased_integer_value
|
251
251
|
end
|
252
252
|
end
|
253
253
|
|
254
|
-
describe
|
255
|
-
it
|
254
|
+
describe 'integer values' do
|
255
|
+
it 'return correct data type' do
|
256
256
|
assert_equal @integer_value, @user_clone.integer_value
|
257
257
|
assert @user.clone.integer_value.kind_of?(Integer)
|
258
258
|
end
|
259
259
|
|
260
|
-
it
|
261
|
-
u = MongoMapperUser.new(integer_value:
|
260
|
+
it 'coerce data type before save' do
|
261
|
+
u = MongoMapperUser.new(integer_value: '5')
|
262
262
|
assert_equal 5, u.integer_value
|
263
263
|
assert u.integer_value.kind_of?(Integer)
|
264
264
|
end
|
265
265
|
|
266
|
-
it
|
266
|
+
it 'permit replacing value with nil' do
|
267
267
|
@user_clone.integer_value = nil
|
268
268
|
@user_clone.save!
|
269
269
|
|
@@ -272,7 +272,7 @@ begin
|
|
272
272
|
assert_nil @user.encrypted_integer_value
|
273
273
|
end
|
274
274
|
|
275
|
-
it
|
275
|
+
it 'permit replacing value' do
|
276
276
|
new_integer_value = 98
|
277
277
|
@user_clone.integer_value = new_integer_value
|
278
278
|
@user_clone.save!
|
@@ -282,19 +282,19 @@ begin
|
|
282
282
|
end
|
283
283
|
end
|
284
284
|
|
285
|
-
describe
|
286
|
-
it
|
285
|
+
describe 'float values' do
|
286
|
+
it 'return correct data type' do
|
287
287
|
assert_equal @float_value, @user_clone.float_value
|
288
288
|
assert @user.clone.float_value.kind_of?(Float)
|
289
289
|
end
|
290
290
|
|
291
|
-
it
|
292
|
-
u = MongoMapperUser.new(float_value:
|
291
|
+
it 'coerce data type before save' do
|
292
|
+
u = MongoMapperUser.new(float_value: '5.6')
|
293
293
|
assert_equal 5.6, u.float_value
|
294
294
|
assert u.float_value.kind_of?(Float)
|
295
295
|
end
|
296
296
|
|
297
|
-
it
|
297
|
+
it 'permit replacing value with nil' do
|
298
298
|
@user_clone.float_value = nil
|
299
299
|
@user_clone.save!
|
300
300
|
|
@@ -303,7 +303,7 @@ begin
|
|
303
303
|
assert_nil @user.encrypted_float_value
|
304
304
|
end
|
305
305
|
|
306
|
-
it
|
306
|
+
it 'permit replacing value' do
|
307
307
|
new_float_value = 45.4321
|
308
308
|
@user_clone.float_value = new_float_value
|
309
309
|
@user_clone.save!
|
@@ -313,19 +313,19 @@ begin
|
|
313
313
|
end
|
314
314
|
end
|
315
315
|
|
316
|
-
describe
|
317
|
-
it
|
316
|
+
describe 'decimal values' do
|
317
|
+
it 'return correct data type' do
|
318
318
|
assert_equal @decimal_value, @user_clone.decimal_value
|
319
319
|
assert @user.clone.decimal_value.kind_of?(BigDecimal)
|
320
320
|
end
|
321
321
|
|
322
|
-
it
|
323
|
-
u = MongoMapperUser.new(decimal_value:
|
324
|
-
assert_equal BigDecimal.new(
|
322
|
+
it 'coerce data type before save' do
|
323
|
+
u = MongoMapperUser.new(decimal_value: '99.95')
|
324
|
+
assert_equal BigDecimal.new('99.95'), u.decimal_value
|
325
325
|
assert u.decimal_value.kind_of?(BigDecimal)
|
326
326
|
end
|
327
327
|
|
328
|
-
it
|
328
|
+
it 'permit replacing value with nil' do
|
329
329
|
@user_clone.decimal_value = nil
|
330
330
|
@user_clone.save!
|
331
331
|
|
@@ -334,8 +334,8 @@ begin
|
|
334
334
|
assert_nil @user.encrypted_decimal_value
|
335
335
|
end
|
336
336
|
|
337
|
-
it
|
338
|
-
new_decimal_value = BigDecimal.new(
|
337
|
+
it 'permit replacing value' do
|
338
|
+
new_decimal_value = BigDecimal.new('99.95')
|
339
339
|
@user_clone.decimal_value = new_decimal_value
|
340
340
|
@user_clone.save!
|
341
341
|
|
@@ -344,20 +344,20 @@ begin
|
|
344
344
|
end
|
345
345
|
end
|
346
346
|
|
347
|
-
describe
|
348
|
-
it
|
347
|
+
describe 'datetime values' do
|
348
|
+
it 'return correct data type' do
|
349
349
|
assert_equal @datetime_value, @user_clone.datetime_value
|
350
350
|
assert @user.clone.datetime_value.kind_of?(DateTime)
|
351
351
|
end
|
352
352
|
|
353
|
-
it
|
353
|
+
it 'coerce data type before save' do
|
354
354
|
now = Time.now
|
355
355
|
u = MongoMapperUser.new(datetime_value: now)
|
356
356
|
assert_equal now, u.datetime_value
|
357
357
|
assert u.datetime_value.kind_of?(DateTime)
|
358
358
|
end
|
359
359
|
|
360
|
-
it
|
360
|
+
it 'permit replacing value with nil' do
|
361
361
|
@user_clone.datetime_value = nil
|
362
362
|
@user_clone.save!
|
363
363
|
|
@@ -366,8 +366,8 @@ begin
|
|
366
366
|
assert_nil @user.encrypted_datetime_value
|
367
367
|
end
|
368
368
|
|
369
|
-
it
|
370
|
-
new_datetime_value = DateTime.new(1998, 10, 21, 8, 33, 28,
|
369
|
+
it 'permit replacing value' do
|
370
|
+
new_datetime_value = DateTime.new(1998, 10, 21, 8, 33, 28, '+5')
|
371
371
|
@user_clone.datetime_value = new_datetime_value
|
372
372
|
@user_clone.save!
|
373
373
|
|
@@ -376,20 +376,20 @@ begin
|
|
376
376
|
end
|
377
377
|
end
|
378
378
|
|
379
|
-
describe
|
380
|
-
it
|
379
|
+
describe 'time values' do
|
380
|
+
it 'return correct data type' do
|
381
381
|
assert_equal @time_value, @user_clone.time_value
|
382
382
|
assert @user.clone.time_value.kind_of?(Time)
|
383
383
|
end
|
384
384
|
|
385
|
-
it
|
385
|
+
it 'coerce data type before save' do
|
386
386
|
now = Time.now
|
387
387
|
u = MongoMapperUser.new(time_value: now)
|
388
388
|
assert_equal now, u.time_value
|
389
389
|
assert u.time_value.kind_of?(Time)
|
390
390
|
end
|
391
391
|
|
392
|
-
it
|
392
|
+
it 'permit replacing value with nil' do
|
393
393
|
@user_clone.time_value = nil
|
394
394
|
@user_clone.save!
|
395
395
|
|
@@ -398,8 +398,8 @@ begin
|
|
398
398
|
assert_nil @user.encrypted_time_value
|
399
399
|
end
|
400
400
|
|
401
|
-
it
|
402
|
-
new_time_value = Time.new(1998, 10, 21, 8, 33, 28,
|
401
|
+
it 'permit replacing value' do
|
402
|
+
new_time_value = Time.new(1998, 10, 21, 8, 33, 28, '+04:00')
|
403
403
|
@user_clone.time_value = new_time_value
|
404
404
|
@user_clone.save!
|
405
405
|
|
@@ -408,20 +408,20 @@ begin
|
|
408
408
|
end
|
409
409
|
end
|
410
410
|
|
411
|
-
describe
|
412
|
-
it
|
411
|
+
describe 'date values' do
|
412
|
+
it 'return correct data type' do
|
413
413
|
assert_equal @date_value, @user_clone.date_value
|
414
414
|
assert @user.clone.date_value.kind_of?(Date)
|
415
415
|
end
|
416
416
|
|
417
|
-
it
|
417
|
+
it 'coerce data type before save' do
|
418
418
|
now = Time.now
|
419
419
|
u = MongoMapperUser.new(date_value: now)
|
420
420
|
assert_equal now.to_date, u.date_value
|
421
421
|
assert u.date_value.kind_of?(Date)
|
422
422
|
end
|
423
423
|
|
424
|
-
it
|
424
|
+
it 'permit replacing value with nil' do
|
425
425
|
@user_clone.date_value = nil
|
426
426
|
@user_clone.save!
|
427
427
|
|
@@ -430,7 +430,7 @@ begin
|
|
430
430
|
assert_nil @user.encrypted_date_value
|
431
431
|
end
|
432
432
|
|
433
|
-
it
|
433
|
+
it 'permit replacing value' do
|
434
434
|
new_date_value = Date.new(1998, 10, 21)
|
435
435
|
@user_clone.date_value = new_date_value
|
436
436
|
@user_clone.save!
|
@@ -440,19 +440,19 @@ begin
|
|
440
440
|
end
|
441
441
|
end
|
442
442
|
|
443
|
-
describe
|
444
|
-
it
|
443
|
+
describe 'true values' do
|
444
|
+
it 'return correct data type' do
|
445
445
|
assert_equal true, @user_clone.true_value
|
446
446
|
assert @user.clone.true_value.kind_of?(TrueClass)
|
447
447
|
end
|
448
448
|
|
449
|
-
it
|
450
|
-
u = MongoMapperUser.new(true_value:
|
449
|
+
it 'coerce data type before save' do
|
450
|
+
u = MongoMapperUser.new(true_value: '1')
|
451
451
|
assert_equal true, u.true_value
|
452
452
|
assert u.true_value.kind_of?(TrueClass)
|
453
453
|
end
|
454
454
|
|
455
|
-
it
|
455
|
+
it 'permit replacing value with nil' do
|
456
456
|
@user_clone.true_value = nil
|
457
457
|
@user_clone.save!
|
458
458
|
|
@@ -461,7 +461,7 @@ begin
|
|
461
461
|
assert_nil @user.encrypted_true_value
|
462
462
|
end
|
463
463
|
|
464
|
-
it
|
464
|
+
it 'permit replacing value' do
|
465
465
|
new_value = false
|
466
466
|
@user_clone.true_value = new_value
|
467
467
|
@user_clone.save!
|
@@ -471,19 +471,19 @@ begin
|
|
471
471
|
end
|
472
472
|
end
|
473
473
|
|
474
|
-
describe
|
475
|
-
it
|
474
|
+
describe 'false values' do
|
475
|
+
it 'return correct data type' do
|
476
476
|
assert_equal false, @user_clone.false_value
|
477
477
|
assert @user.clone.false_value.kind_of?(FalseClass)
|
478
478
|
end
|
479
479
|
|
480
|
-
it
|
481
|
-
u = MongoMapperUser.new(false_value:
|
480
|
+
it 'coerce data type before save' do
|
481
|
+
u = MongoMapperUser.new(false_value: '0')
|
482
482
|
assert_equal false, u.false_value
|
483
483
|
assert u.false_value.kind_of?(FalseClass)
|
484
484
|
end
|
485
485
|
|
486
|
-
it
|
486
|
+
it 'permit replacing value with nil' do
|
487
487
|
@user_clone.false_value = nil
|
488
488
|
@user_clone.save!
|
489
489
|
|
@@ -492,7 +492,7 @@ begin
|
|
492
492
|
assert_nil @user.encrypted_false_value
|
493
493
|
end
|
494
494
|
|
495
|
-
it
|
495
|
+
it 'permit replacing value' do
|
496
496
|
new_value = true
|
497
497
|
@user_clone.false_value = new_value
|
498
498
|
@user_clone.save!
|
@@ -502,7 +502,7 @@ begin
|
|
502
502
|
end
|
503
503
|
end
|
504
504
|
|
505
|
-
describe
|
505
|
+
describe 'JSON Serialization' do
|
506
506
|
before do
|
507
507
|
# JSON Does not support symbols, so they will come back as strings
|
508
508
|
# Convert symbols to string in the test
|
@@ -512,18 +512,18 @@ begin
|
|
512
512
|
end
|
513
513
|
end
|
514
514
|
|
515
|
-
it
|
515
|
+
it 'return correct data type' do
|
516
516
|
assert_equal @h, @user_clone.data_json
|
517
517
|
assert @user.clone.data_json.kind_of?(Hash)
|
518
518
|
end
|
519
519
|
|
520
|
-
it
|
520
|
+
it 'not coerce data type (leaves as hash) before save' do
|
521
521
|
u = MongoMapperUser.new(data_json: @h)
|
522
522
|
assert_equal @h, u.data_json
|
523
523
|
assert u.data_json.kind_of?(Hash)
|
524
524
|
end
|
525
525
|
|
526
|
-
it
|
526
|
+
it 'permit replacing value with nil' do
|
527
527
|
@user_clone.data_json = nil
|
528
528
|
@user_clone.save!
|
529
529
|
|
@@ -532,7 +532,7 @@ begin
|
|
532
532
|
assert_nil @user.encrypted_data_json
|
533
533
|
end
|
534
534
|
|
535
|
-
it
|
535
|
+
it 'permit replacing value' do
|
536
536
|
new_value = @h.clone
|
537
537
|
new_value['c'] = 'C'
|
538
538
|
@user_clone.data_json = new_value
|
@@ -543,19 +543,19 @@ begin
|
|
543
543
|
end
|
544
544
|
end
|
545
545
|
|
546
|
-
describe
|
547
|
-
it
|
546
|
+
describe 'YAML Serialization' do
|
547
|
+
it 'return correct data type' do
|
548
548
|
assert_equal @h, @user_clone.data_yaml
|
549
549
|
assert @user.clone.data_yaml.kind_of?(Hash)
|
550
550
|
end
|
551
551
|
|
552
|
-
it
|
552
|
+
it 'not coerce data type (leaves as hash) before save' do
|
553
553
|
u = MongoMapperUser.new(data_yaml: @h)
|
554
554
|
assert_equal @h, u.data_yaml
|
555
555
|
assert u.data_yaml.kind_of?(Hash)
|
556
556
|
end
|
557
557
|
|
558
|
-
it
|
558
|
+
it 'permit replacing value with nil' do
|
559
559
|
@user_clone.data_yaml = nil
|
560
560
|
@user_clone.save!
|
561
561
|
|
@@ -564,7 +564,7 @@ begin
|
|
564
564
|
assert_nil @user.encrypted_data_yaml
|
565
565
|
end
|
566
566
|
|
567
|
-
it
|
567
|
+
it 'permit replacing value' do
|
568
568
|
new_value = @h.clone
|
569
569
|
new_value[:c] = 'C'
|
570
570
|
@user_clone.data_yaml = new_value
|