symmetric-encryption 3.8.2 → 3.8.3

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.
@@ -5,7 +5,15 @@ begin
5
5
  ENV['RACK_ENV'] = 'test'
6
6
 
7
7
  Mongoid.logger = SemanticLogger[Mongoid]
8
- filename = defined?(Mongoid::VERSION) ? "test/config/mongoid_v3.yml" : "test/config/mongoid_v2.yml"
8
+ filename =
9
+ case Mongoid::VERSION.to_i
10
+ when 3, 4
11
+ 'test/config/mongoid_v3.yml'
12
+ when 1, 2
13
+ 'test/config/mongoid_v2.yml'
14
+ else
15
+ 'test/config/mongoid_v5.yml'
16
+ end
9
17
  Mongoid.load!(filename)
10
18
 
11
19
  #@formatter:off
@@ -45,7 +53,7 @@ begin
45
53
 
46
54
  validates :username,
47
55
  length: {in: 3..20},
48
- format: {with: /\A[\w\d\-[[:alnum:]]]+\z/},
56
+ format: {with: /\A[\w\-]+\z/},
49
57
  allow_blank: true
50
58
  end
51
59
  #@formatter:on
@@ -56,27 +64,27 @@ begin
56
64
  class MongoidTest < Minitest::Test
57
65
  describe 'Mongoid' do
58
66
  before do
59
- @bank_account_number = "1234567890"
60
- @bank_account_number_encrypted = "QEVuQwIAL94ArJeFlJrZp6SYsvoOGA=="
67
+ @bank_account_number = '1234567890'
68
+ @bank_account_number_encrypted = 'QEVuQwIAL94ArJeFlJrZp6SYsvoOGA=='
61
69
 
62
- @social_security_number = "987654321"
63
- @social_security_number_encrypted = "QEVuQwIAS+8X1NRrqdfEIQyFHVPuVA=="
70
+ @social_security_number = '987654321'
71
+ @social_security_number_encrypted = 'QEVuQwIAS+8X1NRrqdfEIQyFHVPuVA=='
64
72
 
65
73
  @integer = 32768
66
- @integer_encrypted = "FA3smFQEKqB/ITv+A0xACg=="
74
+ @integer_encrypted = 'FA3smFQEKqB/ITv+A0xACg=='
67
75
 
68
76
  @float = 0.9867
69
- @float_encrypted = "z7Pwt2JDp74d+u0IXFAdrQ=="
77
+ @float_encrypted = 'z7Pwt2JDp74d+u0IXFAdrQ=='
70
78
 
71
79
  @date = Date.parse('20120320')
72
- @date_encrypted = "WTkSPHo5ApSSHBJMxxWt2A=="
80
+ @date_encrypted = 'WTkSPHo5ApSSHBJMxxWt2A=='
73
81
 
74
- @string = "A string containing some data to be encrypted with a random initialization vector"
75
- @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"
82
+ @string = 'A string containing some data to be encrypted with a random initialization vector'
83
+ @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'
76
84
 
77
85
  @integer_value = 12
78
86
  @float_value = 88.12345
79
- @decimal_value = BigDecimal.new("22.51")
87
+ @decimal_value = BigDecimal.new('22.51')
80
88
  @datetime_value = DateTime.new(2001, 11, 26, 20, 55, 54, "-5")
81
89
  @time_value = Time.new(2013, 01, 01, 22, 30, 00, "-04:00")
82
90
  @date_value = Date.new(1927, 04, 02)
@@ -85,7 +93,7 @@ begin
85
93
  @user = MongoidUser.new(
86
94
  encrypted_bank_account_number: @bank_account_number_encrypted,
87
95
  encrypted_social_security_number: @social_security_number_encrypted,
88
- name: "Joe Bloggs",
96
+ name: 'Joe Bloggs',
89
97
  # data type specific fields
90
98
  integer_value: @integer_value,
91
99
  aliased_integer_value: @integer_value,
@@ -101,7 +109,7 @@ begin
101
109
  )
102
110
  end
103
111
 
104
- it "have encrypted methods" do
112
+ it 'have encrypted methods' do
105
113
  assert_equal true, @user.respond_to?(:encrypted_bank_account_number)
106
114
  assert_equal true, @user.respond_to?(:encrypted_social_security_number)
107
115
  assert_equal true, @user.respond_to?(:encrypted_string)
@@ -115,7 +123,7 @@ begin
115
123
  assert_equal false, @user.respond_to?(:encrypted_name=)
116
124
  end
117
125
 
118
- it "have unencrypted methods" do
126
+ it 'have unencrypted methods' do
119
127
  assert_equal true, @user.respond_to?(:bank_account_number)
120
128
  assert_equal true, @user.respond_to?(:social_security_number)
121
129
  assert_equal true, @user.respond_to?(:string)
@@ -129,22 +137,22 @@ begin
129
137
  assert_equal true, @user.respond_to?(:name=)
130
138
  end
131
139
 
132
- it "support aliased fields" do
140
+ it 'support aliased fields' do
133
141
  assert_equal true, @user.respond_to?(:aliased_integer_value=)
134
142
  assert_equal true, @user.respond_to?(:aliased_integer_value)
135
143
  end
136
144
 
137
- it "have unencrypted values" do
145
+ it 'have unencrypted values' do
138
146
  assert_equal @bank_account_number, @user.bank_account_number
139
147
  assert_equal @social_security_number, @user.social_security_number
140
148
  end
141
149
 
142
- it "have encrypted values" do
150
+ it 'have encrypted values' do
143
151
  assert_equal @bank_account_number_encrypted, @user.encrypted_bank_account_number
144
152
  assert_equal @social_security_number_encrypted, @user.encrypted_social_security_number
145
153
  end
146
154
 
147
- it "support same iv" do
155
+ it 'support same iv' do
148
156
  @user.social_security_number = @social_security_number
149
157
  assert first_value = @user.social_security_number
150
158
  # Assign the same value
@@ -152,7 +160,7 @@ begin
152
160
  assert_equal first_value, @user.social_security_number
153
161
  end
154
162
 
155
- it "support a random iv" do
163
+ it 'support a random iv' do
156
164
  @user.string = @string
157
165
  assert first_value = @user.encrypted_string
158
166
  # Assign the same value
@@ -160,26 +168,26 @@ begin
160
168
  assert_equal true, first_value != @user.encrypted_string
161
169
  end
162
170
 
163
- it "support a random iv and compress" do
171
+ it 'support a random iv and compress' do
164
172
  @user.string = @long_string
165
173
  @user.long_string = @long_string
166
174
 
167
175
  assert_equal true, (@user.encrypted_long_string.length.to_f / @user.encrypted_string.length) < 0.8
168
176
  end
169
177
 
170
- it "encrypt" do
178
+ it 'encrypt' do
171
179
  user = MongoidUser.new
172
180
  user.bank_account_number = @bank_account_number
173
181
  assert_equal @bank_account_number, user.bank_account_number
174
182
  assert_equal @bank_account_number_encrypted, user.encrypted_bank_account_number
175
183
  end
176
184
 
177
- it "all paths it lead to the same result" do
185
+ it 'all paths it lead to the same result' do
178
186
  assert_equal @bank_account_number_encrypted, (@user.encrypted_social_security_number = @bank_account_number_encrypted)
179
187
  assert_equal @bank_account_number, @user.social_security_number
180
188
  end
181
189
 
182
- it "all paths it lead to the same result 2" do
190
+ it 'all paths it lead to the same result 2' do
183
191
  assert_equal @bank_account_number, (@user.social_security_number = @bank_account_number)
184
192
  assert_equal @bank_account_number_encrypted, @user.encrypted_social_security_number
185
193
  end
@@ -196,7 +204,7 @@ begin
196
204
  assert_equal nil, user.encrypted_social_security_number
197
205
  end
198
206
 
199
- it "allow unencrypted values to be passed to the constructor" do
207
+ it 'allow unencrypted values to be passed to the constructor' do
200
208
  user = MongoidUser.new(bank_account_number: @bank_account_number, social_security_number: @social_security_number)
201
209
  assert_equal @bank_account_number, user.bank_account_number
202
210
  assert_equal @social_security_number, user.social_security_number
@@ -204,7 +212,7 @@ begin
204
212
  assert_equal @social_security_number_encrypted, user.encrypted_social_security_number
205
213
  end
206
214
 
207
- it "allow both encrypted and unencrypted values to be passed to the constructor" do
215
+ it 'allow both encrypted and unencrypted values to be passed to the constructor' do
208
216
  user = MongoidUser.new(encrypted_bank_account_number: @bank_account_number_encrypted, social_security_number: @social_security_number)
209
217
  assert_equal @bank_account_number, user.bank_account_number
210
218
  assert_equal @social_security_number, user.social_security_number
@@ -233,7 +241,7 @@ begin
233
241
  end
234
242
  end
235
243
 
236
- describe "data types" do
244
+ describe 'data types' do
237
245
  before do
238
246
  @user.save!
239
247
  @user_clone = MongoidUser.find(@user.id)
@@ -243,26 +251,26 @@ begin
243
251
  @user.destroy if @user
244
252
  end
245
253
 
246
- describe "aliased fields" do
247
- it "return correct data type" do
248
- @user_clone.aliased_integer_value = "5"
254
+ describe 'aliased fields' do
255
+ it 'return correct data type' do
256
+ @user_clone.aliased_integer_value = '5'
249
257
  assert_equal 5, @user_clone.aliased_integer_value
250
258
  end
251
259
  end
252
260
 
253
- describe "integer values" do
254
- it "return correct data type" do
261
+ describe 'integer values' do
262
+ it 'return correct data type' do
255
263
  assert_equal @integer_value, @user_clone.integer_value
256
264
  assert @user.clone.integer_value.kind_of?(Integer)
257
265
  end
258
266
 
259
- it "coerce data type before save" do
260
- u = MongoidUser.new(integer_value: "5")
267
+ it 'coerce data type before save' do
268
+ u = MongoidUser.new(integer_value: '5')
261
269
  assert_equal 5, u.integer_value
262
270
  assert u.integer_value.kind_of?(Integer)
263
271
  end
264
272
 
265
- it "permit replacing value with nil" do
273
+ it 'permit replacing value with nil' do
266
274
  @user_clone.integer_value = nil
267
275
  @user_clone.save!
268
276
 
@@ -271,7 +279,7 @@ begin
271
279
  assert_nil @user.encrypted_integer_value
272
280
  end
273
281
 
274
- it "permit replacing value" do
282
+ it 'permit replacing value' do
275
283
  new_integer_value = 98
276
284
  @user_clone.integer_value = new_integer_value
277
285
  @user_clone.save!
@@ -281,19 +289,19 @@ begin
281
289
  end
282
290
  end
283
291
 
284
- describe "float values" do
285
- it "return correct data type" do
292
+ describe 'float values' do
293
+ it 'return correct data type' do
286
294
  assert_equal @float_value, @user_clone.float_value
287
295
  assert @user.clone.float_value.kind_of?(Float)
288
296
  end
289
297
 
290
- it "coerce data type before save" do
291
- u = MongoidUser.new(float_value: "5.6")
298
+ it 'coerce data type before save' do
299
+ u = MongoidUser.new(float_value: '5.6')
292
300
  assert_equal 5.6, u.float_value
293
301
  assert u.float_value.kind_of?(Float)
294
302
  end
295
303
 
296
- it "permit replacing value with nil" do
304
+ it 'permit replacing value with nil' do
297
305
  @user_clone.float_value = nil
298
306
  @user_clone.save!
299
307
 
@@ -302,7 +310,7 @@ begin
302
310
  assert_nil @user.encrypted_float_value
303
311
  end
304
312
 
305
- it "permit replacing value" do
313
+ it 'permit replacing value' do
306
314
  new_float_value = 45.4321
307
315
  @user_clone.float_value = new_float_value
308
316
  @user_clone.save!
@@ -312,19 +320,19 @@ begin
312
320
  end
313
321
  end
314
322
 
315
- describe "decimal values" do
316
- it "return correct data type" do
323
+ describe 'decimal values' do
324
+ it 'return correct data type' do
317
325
  assert_equal @decimal_value, @user_clone.decimal_value
318
326
  assert @user.clone.decimal_value.kind_of?(BigDecimal)
319
327
  end
320
328
 
321
- it "coerce data type before save" do
322
- u = MongoidUser.new(decimal_value: "99.95")
323
- assert_equal BigDecimal.new("99.95"), u.decimal_value
329
+ it 'coerce data type before save' do
330
+ u = MongoidUser.new(decimal_value: '99.95')
331
+ assert_equal BigDecimal.new('99.95'), u.decimal_value
324
332
  assert u.decimal_value.kind_of?(BigDecimal)
325
333
  end
326
334
 
327
- it "permit replacing value with nil" do
335
+ it 'permit replacing value with nil' do
328
336
  @user_clone.decimal_value = nil
329
337
  @user_clone.save!
330
338
 
@@ -333,8 +341,8 @@ begin
333
341
  assert_nil @user.encrypted_decimal_value
334
342
  end
335
343
 
336
- it "permit replacing value" do
337
- new_decimal_value = BigDecimal.new("99.95")
344
+ it 'permit replacing value' do
345
+ new_decimal_value = BigDecimal.new('99.95')
338
346
  @user_clone.decimal_value = new_decimal_value
339
347
  @user_clone.save!
340
348
 
@@ -343,20 +351,20 @@ begin
343
351
  end
344
352
  end
345
353
 
346
- describe "datetime values" do
347
- it "return correct data type" do
354
+ describe 'datetime values' do
355
+ it 'return correct data type' do
348
356
  assert_equal @datetime_value, @user_clone.datetime_value
349
357
  assert @user.clone.datetime_value.kind_of?(DateTime)
350
358
  end
351
359
 
352
- it "coerce data type before save" do
360
+ it 'coerce data type before save' do
353
361
  now = Time.now
354
362
  u = MongoidUser.new(datetime_value: now)
355
363
  assert_equal now, u.datetime_value
356
364
  assert u.datetime_value.kind_of?(DateTime)
357
365
  end
358
366
 
359
- it "permit replacing value with nil" do
367
+ it 'permit replacing value with nil' do
360
368
  @user_clone.datetime_value = nil
361
369
  @user_clone.save!
362
370
 
@@ -365,8 +373,8 @@ begin
365
373
  assert_nil @user.encrypted_datetime_value
366
374
  end
367
375
 
368
- it "permit replacing value" do
369
- new_datetime_value = DateTime.new(1998, 10, 21, 8, 33, 28, "+5")
376
+ it 'permit replacing value' do
377
+ new_datetime_value = DateTime.new(1998, 10, 21, 8, 33, 28, '+5')
370
378
  @user_clone.datetime_value = new_datetime_value
371
379
  @user_clone.save!
372
380
 
@@ -375,20 +383,20 @@ begin
375
383
  end
376
384
  end
377
385
 
378
- describe "time values" do
379
- it "return correct data type" do
386
+ describe 'time values' do
387
+ it 'return correct data type' do
380
388
  assert_equal @time_value, @user_clone.time_value
381
389
  assert @user.clone.time_value.kind_of?(Time)
382
390
  end
383
391
 
384
- it "coerce data type before save" do
392
+ it 'coerce data type before save' do
385
393
  now = Time.now
386
394
  u = MongoidUser.new(time_value: now)
387
395
  assert_equal now, u.time_value
388
396
  assert u.time_value.kind_of?(Time)
389
397
  end
390
398
 
391
- it "permit replacing value with nil" do
399
+ it 'permit replacing value with nil' do
392
400
  @user_clone.time_value = nil
393
401
  @user_clone.save!
394
402
 
@@ -397,8 +405,8 @@ begin
397
405
  assert_nil @user.encrypted_time_value
398
406
  end
399
407
 
400
- it "permit replacing value" do
401
- new_time_value = Time.new(1998, 10, 21, 8, 33, 28, "+04:00")
408
+ it 'permit replacing value' do
409
+ new_time_value = Time.new(1998, 10, 21, 8, 33, 28, '+04:00')
402
410
  @user_clone.time_value = new_time_value
403
411
  @user_clone.save!
404
412
 
@@ -407,20 +415,20 @@ begin
407
415
  end
408
416
  end
409
417
 
410
- describe "date values" do
411
- it "return correct data type" do
418
+ describe 'date values' do
419
+ it 'return correct data type' do
412
420
  assert_equal @date_value, @user_clone.date_value
413
421
  assert @user.clone.date_value.kind_of?(Date)
414
422
  end
415
423
 
416
- it "coerce data type before save" do
424
+ it 'coerce data type before save' do
417
425
  now = Time.now
418
426
  u = MongoidUser.new(date_value: now)
419
427
  assert_equal now.to_date, u.date_value
420
428
  assert u.date_value.kind_of?(Date)
421
429
  end
422
430
 
423
- it "permit replacing value with nil" do
431
+ it 'permit replacing value with nil' do
424
432
  @user_clone.date_value = nil
425
433
  @user_clone.save!
426
434
 
@@ -429,7 +437,7 @@ begin
429
437
  assert_nil @user.encrypted_date_value
430
438
  end
431
439
 
432
- it "permit replacing value" do
440
+ it 'permit replacing value' do
433
441
  new_date_value = Date.new(1998, 10, 21)
434
442
  @user_clone.date_value = new_date_value
435
443
  @user_clone.save!
@@ -439,19 +447,19 @@ begin
439
447
  end
440
448
  end
441
449
 
442
- describe "true values" do
443
- it "return correct data type" do
450
+ describe 'true values' do
451
+ it 'return correct data type' do
444
452
  assert_equal true, @user_clone.true_value
445
453
  assert @user.clone.true_value.kind_of?(TrueClass)
446
454
  end
447
455
 
448
- it "coerce data type before save" do
449
- u = MongoidUser.new(true_value: "1")
456
+ it 'coerce data type before save' do
457
+ u = MongoidUser.new(true_value: '1')
450
458
  assert_equal true, u.true_value
451
459
  assert u.true_value.kind_of?(TrueClass)
452
460
  end
453
461
 
454
- it "permit replacing value with nil" do
462
+ it 'permit replacing value with nil' do
455
463
  @user_clone.true_value = nil
456
464
  @user_clone.save!
457
465
 
@@ -460,7 +468,7 @@ begin
460
468
  assert_nil @user.encrypted_true_value
461
469
  end
462
470
 
463
- it "permit replacing value" do
471
+ it 'permit replacing value' do
464
472
  new_value = false
465
473
  @user_clone.true_value = new_value
466
474
  @user_clone.save!
@@ -470,19 +478,19 @@ begin
470
478
  end
471
479
  end
472
480
 
473
- describe "false values" do
474
- it "return correct data type" do
481
+ describe 'false values' do
482
+ it 'return correct data type' do
475
483
  assert_equal false, @user_clone.false_value
476
484
  assert @user.clone.false_value.kind_of?(FalseClass)
477
485
  end
478
486
 
479
- it "coerce data type before save" do
480
- u = MongoidUser.new(false_value: "0")
487
+ it 'coerce data type before save' do
488
+ u = MongoidUser.new(false_value: '0')
481
489
  assert_equal false, u.false_value
482
490
  assert u.false_value.kind_of?(FalseClass)
483
491
  end
484
492
 
485
- it "permit replacing value with nil" do
493
+ it 'permit replacing value with nil' do
486
494
  @user_clone.false_value = nil
487
495
  @user_clone.save!
488
496
 
@@ -491,7 +499,7 @@ begin
491
499
  assert_nil @user.encrypted_false_value
492
500
  end
493
501
 
494
- it "permit replacing value" do
502
+ it 'permit replacing value' do
495
503
  new_value = true
496
504
  @user_clone.false_value = new_value
497
505
  @user_clone.save!
@@ -501,7 +509,7 @@ begin
501
509
  end
502
510
  end
503
511
 
504
- describe "JSON Serialization" do
512
+ describe 'JSON Serialization' do
505
513
  before do
506
514
  # JSON Does not support symbols, so they will come back as strings
507
515
  # Convert symbols to string in the test
@@ -511,18 +519,18 @@ begin
511
519
  end
512
520
  end
513
521
 
514
- it "return correct data type" do
522
+ it 'return correct data type' do
515
523
  assert_equal @h, @user_clone.data_json
516
524
  assert @user.clone.data_json.kind_of?(Hash)
517
525
  end
518
526
 
519
- it "not coerce data type (leaves as hash) before save" do
527
+ it 'not coerce data type (leaves as hash) before save' do
520
528
  u = MongoidUser.new(data_json: @h)
521
529
  assert_equal @h, u.data_json
522
530
  assert u.data_json.kind_of?(Hash)
523
531
  end
524
532
 
525
- it "permit replacing value with nil" do
533
+ it 'permit replacing value with nil' do
526
534
  @user_clone.data_json = nil
527
535
  @user_clone.save!
528
536
 
@@ -531,7 +539,7 @@ begin
531
539
  assert_nil @user.encrypted_data_json
532
540
  end
533
541
 
534
- it "permit replacing value" do
542
+ it 'permit replacing value' do
535
543
  new_value = @h.clone
536
544
  new_value['c'] = 'C'
537
545
  @user_clone.data_json = new_value
@@ -542,19 +550,19 @@ begin
542
550
  end
543
551
  end
544
552
 
545
- describe "YAML Serialization" do
546
- it "return correct data type" do
553
+ describe 'YAML Serialization' do
554
+ it 'return correct data type' do
547
555
  assert_equal @h, @user_clone.data_yaml
548
556
  assert @user.clone.data_yaml.kind_of?(Hash)
549
557
  end
550
558
 
551
- it "not coerce data type (leaves as hash) before save" do
559
+ it 'not coerce data type (leaves as hash) before save' do
552
560
  u = MongoidUser.new(data_yaml: @h)
553
561
  assert_equal @h, u.data_yaml
554
562
  assert u.data_yaml.kind_of?(Hash)
555
563
  end
556
564
 
557
- it "permit replacing value with nil" do
565
+ it 'permit replacing value with nil' do
558
566
  @user_clone.data_yaml = nil
559
567
  @user_clone.save!
560
568
 
@@ -563,7 +571,7 @@ begin
563
571
  assert_nil @user.encrypted_data_yaml
564
572
  end
565
573
 
566
- it "permit replacing value" do
574
+ it 'permit replacing value' do
567
575
  new_value = @h.clone
568
576
  new_value[:c] = 'C'
569
577
  @user_clone.data_yaml = new_value
@@ -588,7 +596,7 @@ begin
588
596
  it 'does not allow duplicate values' do
589
597
  duplicate = MongoidUniqueUser.new(email: @email)
590
598
  assert_equal false, duplicate.valid?
591
- assert_equal 'has already been taken', duplicate.errors.messages[:encrypted_email].first
599
+ assert_equal 'is already taken', duplicate.errors.messages[:encrypted_email].first
592
600
  end
593
601
  end
594
602