symmetric-encryption 3.7.2 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/reader_test.rb CHANGED
@@ -4,17 +4,17 @@ require 'stringio'
4
4
  # Unit Test for SymmetricEncrypted::ReaderStream
5
5
  #
6
6
  class ReaderTest < Minitest::Test
7
- context SymmetricEncryption::Reader do
8
- setup do
9
- @data = [
7
+ describe SymmetricEncryption::Reader do
8
+ before do
9
+ @data = [
10
10
  "Hello World\n",
11
11
  "Keep this secret\n",
12
12
  "And keep going even further and further..."
13
13
  ]
14
- @data_str = @data.inject('') {|sum,str| sum << str}
15
- @data_len = @data_str.length
14
+ @data_str = @data.inject('') { |sum, str| sum << str }
15
+ @data_len = @data_str.length
16
16
  # Use Cipher 0 since it does not always include a header
17
- @cipher = SymmetricEncryption.cipher(0)
17
+ @cipher = SymmetricEncryption.cipher(0)
18
18
  @data_encrypted_without_header = @cipher.binary_encrypt(@data_str)
19
19
 
20
20
  @data_encrypted_with_header = SymmetricEncryption::Cipher.build_header(
@@ -33,20 +33,20 @@ class ReaderTest < Minitest::Test
33
33
  end
34
34
 
35
35
  [true, false].each do |header|
36
- context header do
37
- setup do
36
+ describe header do
37
+ before do
38
38
  @data_encrypted = header ? @data_encrypted_with_header : @data_encrypted_without_header
39
39
  end
40
40
 
41
- should "#read()" do
42
- stream = StringIO.new(@data_encrypted)
41
+ it "#read()" do
42
+ stream = StringIO.new(@data_encrypted)
43
43
  # Version 0 supplied if the file/stream does not have a header
44
- decrypted = SymmetricEncryption::Reader.open(stream, version: 0) {|file| file.read}
44
+ decrypted = SymmetricEncryption::Reader.open(stream, version: 0) { |file| file.read }
45
45
  assert_equal @data_str, decrypted
46
46
  end
47
47
 
48
- should "#read(size) followed by #read()" do
49
- stream = StringIO.new(@data_encrypted)
48
+ it "#read(size) followed by #read()" do
49
+ stream = StringIO.new(@data_encrypted)
50
50
  # Version 0 supplied if the file/stream does not have a header
51
51
  decrypted = SymmetricEncryption::Reader.open(stream, version: 0) do |file|
52
52
  file.read(10)
@@ -55,9 +55,9 @@ class ReaderTest < Minitest::Test
55
55
  assert_equal @data_str[10..-1], decrypted
56
56
  end
57
57
 
58
- should "#each_line" do
59
- stream = StringIO.new(@data_encrypted)
60
- i = 0
58
+ it "#each_line" do
59
+ stream = StringIO.new(@data_encrypted)
60
+ i = 0
61
61
  # Version 0 supplied if the file/stream does not have a header
62
62
  decrypted = SymmetricEncryption::Reader.open(stream, version: 0) do |file|
63
63
  file.each_line do |line|
@@ -67,13 +67,13 @@ class ReaderTest < Minitest::Test
67
67
  end
68
68
  end
69
69
 
70
- should "#read(size)" do
71
- stream = StringIO.new(@data_encrypted)
72
- i = 0
70
+ it "#read(size)" do
71
+ stream = StringIO.new(@data_encrypted)
72
+ i = 0
73
73
  # Version 0 supplied if the file/stream does not have a header
74
74
  decrypted = SymmetricEncryption::Reader.open(stream, version: 0) do |file|
75
75
  index = 0
76
- [0,10,5,5000].each do |size|
76
+ [0, 10, 5, 5000].each do |size|
77
77
  buf = file.read(size)
78
78
  if size == 0
79
79
  assert_equal '', buf
@@ -106,30 +106,30 @@ class ReaderTest < Minitest::Test
106
106
 
107
107
  [:data, :empty, :blank].each do |usecase|
108
108
 
109
- context "read from #{usecase} file with options: #{options.inspect}" do
110
- setup do
109
+ describe "read from #{usecase} file with options: #{options.inspect}" do
110
+ before do
111
111
  case usecase
112
112
  when :data
113
113
  # Create encrypted file
114
- @eof = false
114
+ @eof = false
115
115
  @filename = '_test'
116
- @header = (options[:header] != false)
116
+ @header = (options[:header] != false)
117
117
  SymmetricEncryption::Writer.open(@filename, options) do |file|
118
- @data.inject(0) {|sum,str| sum + file.write(str)}
118
+ @data.inject(0) { |sum, str| sum + file.write(str) }
119
119
  end
120
120
  when :empty
121
121
  @data_str = ''
122
- @eof = true
122
+ @eof = true
123
123
  @filename = '_test_empty'
124
- @header = (options[:header] != false)
124
+ @header = (options[:header] != false)
125
125
  SymmetricEncryption::Writer.open(@filename, options) do |file|
126
126
  # Leave data portion empty
127
127
  end
128
128
  when :blank
129
129
  @data_str = ''
130
- @eof = true
130
+ @eof = true
131
131
  @filename = File.join(File.dirname(__FILE__), 'config/empty.csv')
132
- @header = false
132
+ @header = false
133
133
  assert_equal 0, File.size(@filename)
134
134
  else
135
135
  raise "Unhandled usecase: #{usecase}"
@@ -137,35 +137,35 @@ class ReaderTest < Minitest::Test
137
137
  @data_size = @data_str.length
138
138
  end
139
139
 
140
- teardown do
140
+ after do
141
141
  File.delete(@filename) if File.exist?(@filename) && !@filename.end_with?('empty.csv')
142
142
  end
143
143
 
144
- should ".empty?" do
144
+ it ".empty?" do
145
145
  assert_equal (@data_size==0), SymmetricEncryption::Reader.empty?(@filename)
146
146
  assert_raises Errno::ENOENT do
147
147
  SymmetricEncryption::Reader.empty?('missing_file')
148
148
  end
149
149
  end
150
150
 
151
- should ".header_present?" do
151
+ it ".header_present?" do
152
152
  assert_equal @header, SymmetricEncryption::Reader.header_present?(@filename)
153
153
  assert_raises Errno::ENOENT do
154
154
  SymmetricEncryption::Reader.header_present?('missing_file')
155
155
  end
156
156
  end
157
157
 
158
- should ".open return Zlib::GzipReader when compressed" do
158
+ it ".open return Zlib::GzipReader when compressed" do
159
159
  file = SymmetricEncryption::Reader.open(@filename)
160
160
  #assert_equal (@header && (options[:compress]||false)), file.is_a?(Zlib::GzipReader)
161
161
  file.close
162
162
  end
163
163
 
164
- should "#read()" do
165
- data = nil
166
- eof = nil
164
+ it "#read()" do
165
+ data = nil
166
+ eof = nil
167
167
  result = SymmetricEncryption::Reader.open(@filename) do |file|
168
- eof = file.eof?
168
+ eof = file.eof?
169
169
  data = file.read
170
170
  end
171
171
  assert_equal @eof, eof
@@ -173,9 +173,9 @@ class ReaderTest < Minitest::Test
173
173
  assert_equal @data_str, result
174
174
  end
175
175
 
176
- should "#read(size)" do
176
+ it "#read(size)" do
177
177
  file = SymmetricEncryption::Reader.open(@filename)
178
- eof = file.eof?
178
+ eof = file.eof?
179
179
  data = file.read(4096)
180
180
  file.close
181
181
 
@@ -183,7 +183,7 @@ class ReaderTest < Minitest::Test
183
183
  assert_equal (@data_size > 0 ? @data_str : nil), data
184
184
  end
185
185
 
186
- should "#each_line" do
186
+ it "#each_line" do
187
187
  decrypted = SymmetricEncryption::Reader.open(@filename) do |file|
188
188
  i = 0
189
189
  file.each_line do |line|
@@ -193,7 +193,7 @@ class ReaderTest < Minitest::Test
193
193
  end
194
194
  end
195
195
 
196
- should "#rewind" do
196
+ it "#rewind" do
197
197
  decrypted = SymmetricEncryption::Reader.open(@filename) do |file|
198
198
  file.read
199
199
  file.rewind
@@ -202,10 +202,10 @@ class ReaderTest < Minitest::Test
202
202
  assert_equal @data_str, decrypted
203
203
  end
204
204
 
205
- should "#gets(nil,size)" do
205
+ it "#gets(nil,size)" do
206
206
  file = SymmetricEncryption::Reader.open(@filename)
207
- eof = file.eof?
208
- data = file.gets(nil,4096)
207
+ eof = file.eof?
208
+ data = file.gets(nil, 4096)
209
209
  file.close
210
210
 
211
211
  assert_equal @eof, eof
@@ -222,7 +222,7 @@ class ReaderTest < Minitest::Test
222
222
  end
223
223
  end
224
224
 
225
- should "#gets(delim)" do
225
+ it "#gets(delim)" do
226
226
  decrypted = SymmetricEncryption::Reader.open(@filename) do |file|
227
227
  i = 0
228
228
  while line = file.gets("\n")
@@ -233,10 +233,10 @@ class ReaderTest < Minitest::Test
233
233
  end
234
234
  end
235
235
 
236
- should "#gets(delim,size)" do
236
+ it "#gets(delim,size)" do
237
237
  decrypted = SymmetricEncryption::Reader.open(@filename) do |file|
238
238
  i = 0
239
- while line = file.gets("\n",128)
239
+ while line = file.gets("\n", 128)
240
240
  i += 1
241
241
  end
242
242
  assert_equal (@data_size > 0 ? 3 : 0), i
@@ -247,25 +247,25 @@ class ReaderTest < Minitest::Test
247
247
  end
248
248
  end
249
249
 
250
- context "reading from files with previous keys" do
251
- setup do
250
+ describe "reading from files with previous keys" do
251
+ before do
252
252
  @filename = '_test'
253
253
  # Create encrypted file with old encryption key
254
254
  SymmetricEncryption::Writer.open(@filename, version: 0) do |file|
255
- @data.inject(0) {|sum,str| sum + file.write(str)}
255
+ @data.inject(0) { |sum, str| sum + file.write(str) }
256
256
  end
257
257
  end
258
258
 
259
- teardown do
259
+ after do
260
260
  File.delete(@filename) if File.exist?(@filename)
261
261
  end
262
262
 
263
- should "decrypt from file in a single read" do
264
- decrypted = SymmetricEncryption::Reader.open(@filename) {|file| file.read}
263
+ it "decrypt from file in a single read" do
264
+ decrypted = SymmetricEncryption::Reader.open(@filename) { |file| file.read }
265
265
  assert_equal @data_str, decrypted
266
266
  end
267
267
 
268
- should "decrypt from file a line at a time" do
268
+ it "decrypt from file a line at a time" do
269
269
  decrypted = SymmetricEncryption::Reader.open(@filename) do |file|
270
270
  i = 0
271
271
  file.each_line do |line|
@@ -275,7 +275,7 @@ class ReaderTest < Minitest::Test
275
275
  end
276
276
  end
277
277
 
278
- should "support rewind" do
278
+ it "support rewind" do
279
279
  decrypted = SymmetricEncryption::Reader.open(@filename) do |file|
280
280
  file.read
281
281
  file.rewind
@@ -285,16 +285,16 @@ class ReaderTest < Minitest::Test
285
285
  end
286
286
  end
287
287
 
288
- context "reading from files with previous keys without a header" do
289
- setup do
288
+ describe "reading from files with previous keys without a header" do
289
+ before do
290
290
  @filename = '_test'
291
291
  # Create encrypted file with old encryption key
292
292
  SymmetricEncryption::Writer.open(@filename, version: 0, header: false, random_key: false) do |file|
293
- @data.inject(0) {|sum,str| sum + file.write(str)}
293
+ @data.inject(0) { |sum, str| sum + file.write(str) }
294
294
  end
295
295
  end
296
296
 
297
- teardown do
297
+ after do
298
298
  begin
299
299
  File.delete(@filename) if File.exist?(@filename)
300
300
  rescue Errno::EACCES
@@ -302,15 +302,15 @@ class ReaderTest < Minitest::Test
302
302
  end
303
303
  end
304
304
 
305
- should "decrypt from file in a single read" do
306
- decrypted = SymmetricEncryption::Reader.open(@filename, version: 0) {|file| file.read}
305
+ it "decrypt from file in a single read" do
306
+ decrypted = SymmetricEncryption::Reader.open(@filename, version: 0) { |file| file.read }
307
307
  assert_equal @data_str, decrypted
308
308
  end
309
309
 
310
- should "decrypt from file in a single read with different version" do
310
+ it "decrypt from file in a single read with different version" do
311
311
  # Should fail since file was encrypted using version 0 key
312
312
  assert_raises OpenSSL::Cipher::CipherError do
313
- SymmetricEncryption::Reader.open(@filename, version: 2) {|file| file.read}
313
+ SymmetricEncryption::Reader.open(@filename, version: 2) { |file| file.read }
314
314
  end
315
315
  end
316
316
  end
@@ -3,15 +3,16 @@ require_relative 'test_helper'
3
3
  # Unit Test for SymmetricEncryption
4
4
  #
5
5
  class SymmetricEncryptionTest < Minitest::Test
6
- context 'SymmetricEncryption' do
6
+ describe 'SymmetricEncryption' do
7
7
 
8
- context 'configuration' do
9
- setup do
10
- @ciphers = SymmetricEncryption.send(:read_config, File.join(File.dirname(__FILE__), 'config', 'symmetric-encryption.yml'), 'test')
8
+ describe 'configuration' do
9
+ before do
10
+ config = SymmetricEncryption::Config.read_config(File.join(File.dirname(__FILE__), 'config', 'symmetric-encryption.yml'), 'test')
11
+ @ciphers = SymmetricEncryption::Config.extract_ciphers(config)
11
12
  @cipher_v2, @cipher_v1, @cipher_v0 = @ciphers
12
13
  end
13
14
 
14
- should "match config file for first cipher" do
15
+ it 'matches config file for first cipher' do
15
16
  cipher = SymmetricEncryption.cipher
16
17
  assert @cipher_v2.send(:key)
17
18
  assert @cipher_v2.send(:iv)
@@ -21,7 +22,7 @@ class SymmetricEncryptionTest < Minitest::Test
21
22
  assert_equal false, SymmetricEncryption.secondary_ciphers.include?(cipher)
22
23
  end
23
24
 
24
- should "match config file for v1 cipher" do
25
+ it 'match config file for v1 cipher' do
25
26
  cipher = SymmetricEncryption.cipher(2)
26
27
  assert @cipher_v2.cipher_name
27
28
  assert @cipher_v2.version
@@ -30,7 +31,7 @@ class SymmetricEncryptionTest < Minitest::Test
30
31
  assert_equal false, SymmetricEncryption.secondary_ciphers.include?(cipher)
31
32
  end
32
33
 
33
- should "match config file for v0 cipher" do
34
+ it 'match config file for v0 cipher' do
34
35
  cipher = SymmetricEncryption.cipher(0)
35
36
  assert @cipher_v0.cipher_name
36
37
  assert @cipher_v0.version
@@ -41,43 +42,43 @@ class SymmetricEncryptionTest < Minitest::Test
41
42
  end
42
43
 
43
44
  SymmetricEncryption::Cipher::ENCODINGS.each do |encoding|
44
- context "encoding: #{encoding}" do
45
- setup do
46
- @social_security_number = "987654321"
47
- @social_security_number_encrypted =
45
+ describe "encoding: #{encoding}" do
46
+ before do
47
+ @social_security_number = '987654321'
48
+ @social_security_number_encrypted =
48
49
  case encoding
49
- when :base64
50
- "QEVuQwIAS+8X1NRrqdfEIQyFHVPuVA==\n"
51
- when :base64strict
52
- "QEVuQwIAS+8X1NRrqdfEIQyFHVPuVA=="
53
- when :base16
54
- "40456e4302004bef17d4d46ba9d7c4210c851d53ee54"
55
- when :none
56
- "@EnC\x02\x00K\xEF\x17\xD4\xD4k\xA9\xD7\xC4!\f\x85\x1DS\xEET".force_encoding(Encoding.find("binary"))
57
- else
58
- raise "Add test for encoding: #{encoding}"
59
- end
50
+ when :base64
51
+ "QEVuQwIAS+8X1NRrqdfEIQyFHVPuVA==\n"
52
+ when :base64strict
53
+ 'QEVuQwIAS+8X1NRrqdfEIQyFHVPuVA=='
54
+ when :base16
55
+ '40456e4302004bef17d4d46ba9d7c4210c851d53ee54'
56
+ when :none
57
+ "@EnC\x02\x00K\xEF\x17\xD4\xD4k\xA9\xD7\xC4!\f\x85\x1DS\xEET".force_encoding(Encoding.find("binary"))
58
+ else
59
+ raise "Add test for encoding: #{encoding}"
60
+ end
60
61
  @social_security_number_encrypted_with_secondary_1 = "D1UCu38pqJ3jc0GvwJHiow==\n"
61
- @non_utf8 = "\xc2".force_encoding('binary')
62
- @encoding = SymmetricEncryption.cipher.encoding
63
- SymmetricEncryption.cipher.encoding = encoding
62
+ @non_utf8 = "\xc2".force_encoding('binary')
63
+ @encoding = SymmetricEncryption.cipher.encoding
64
+ SymmetricEncryption.cipher.encoding = encoding
64
65
  end
65
66
 
66
- teardown do
67
+ after do
67
68
  SymmetricEncryption.cipher.encoding = @encoding
68
69
  end
69
70
 
70
- should "encrypt simple string" do
71
+ it "encrypt simple string" do
71
72
  assert_equal @social_security_number_encrypted, SymmetricEncryption.encrypt(@social_security_number)
72
73
  end
73
74
 
74
- should "decrypt string" do
75
+ it "decrypt string" do
75
76
  assert decrypted = SymmetricEncryption.decrypt(@social_security_number_encrypted)
76
77
  assert_equal @social_security_number, decrypted
77
78
  assert_equal Encoding.find('utf-8'), decrypted.encoding, decrypted
78
79
  end
79
80
 
80
- should 'return BINARY encoding for non-UTF-8 encrypted data' do
81
+ it 'return BINARY encoding for non-UTF-8 encrypted data' do
81
82
  assert_equal Encoding.find('binary'), @non_utf8.encoding
82
83
  assert_equal true, @non_utf8.valid_encoding?
83
84
  assert encrypted = SymmetricEncryption.encrypt(@non_utf8)
@@ -87,34 +88,34 @@ class SymmetricEncryptionTest < Minitest::Test
87
88
  assert_equal @non_utf8, decrypted
88
89
  end
89
90
 
90
- should "return nil when encrypting nil" do
91
+ it "return nil when encrypting nil" do
91
92
  assert_equal nil, SymmetricEncryption.encrypt(nil)
92
93
  end
93
94
 
94
- should "return '' when encrypting ''" do
95
+ it "return '' when encrypting ''" do
95
96
  assert_equal '', SymmetricEncryption.encrypt('')
96
97
  end
97
98
 
98
- should "return nil when decrypting nil" do
99
+ it "return nil when decrypting nil" do
99
100
  assert_equal nil, SymmetricEncryption.decrypt(nil)
100
101
  end
101
102
 
102
- should "return '' when decrypting ''" do
103
+ it "return '' when decrypting ''" do
103
104
  assert_equal '', SymmetricEncryption.decrypt('')
104
105
  end
105
106
 
106
- should "determine if string is encrypted" do
107
+ it "determine if string is encrypted" do
107
108
  assert_equal true, SymmetricEncryption.encrypted?(@social_security_number_encrypted)
108
109
  assert_equal false, SymmetricEncryption.encrypted?(@social_security_number)
109
110
  end
110
111
  end
111
112
  end
112
113
 
113
- context "using select_cipher" do
114
- setup do
114
+ describe "using select_cipher" do
115
+ before do
115
116
  @social_security_number = "987654321"
116
117
  # Encrypt data without a header and encode with base64 which has a trailing '\n'
117
- @encrypted_0_ssn = SymmetricEncryption.cipher(0).encode(SymmetricEncryption.cipher(0).binary_encrypt(@social_security_number,false,false,false))
118
+ @encrypted_0_ssn = SymmetricEncryption.cipher(0).encode(SymmetricEncryption.cipher(0).binary_encrypt(@social_security_number, false, false, false))
118
119
 
119
120
  SymmetricEncryption.select_cipher do |encoded_str, decoded_str|
120
121
  # Use cipher version 0 if the encoded string ends with "\n" otherwise
@@ -123,43 +124,43 @@ class SymmetricEncryptionTest < Minitest::Test
123
124
  end
124
125
  end
125
126
 
126
- teardown do
127
+ after do
127
128
  # Clear out select_cipher
128
129
  SymmetricEncryption.select_cipher
129
130
  end
130
131
 
131
- should "decrypt string without a header using an old cipher" do
132
+ it "decrypt string without a header using an old cipher" do
132
133
  assert_equal @social_security_number, SymmetricEncryption.decrypt(@encrypted_0_ssn)
133
134
  end
134
135
  end
135
136
 
136
- context "without select_cipher" do
137
- setup do
137
+ describe "without select_cipher" do
138
+ before do
138
139
  @social_security_number = "987654321"
139
140
  # Encrypt data without a header and encode with base64 which has a trailing '\n'
140
- assert @encrypted_0_ssn = SymmetricEncryption.cipher(0).encode(SymmetricEncryption.cipher(0).binary_encrypt(@social_security_number,false,false,false))
141
+ assert @encrypted_0_ssn = SymmetricEncryption.cipher(0).encode(SymmetricEncryption.cipher(0).binary_encrypt(@social_security_number, false, false, false))
141
142
  end
142
143
 
143
- should "decrypt string without a header using an old cipher" do
144
+ it "decrypt string without a header using an old cipher" do
144
145
  assert_raises OpenSSL::Cipher::CipherError do
145
146
  SymmetricEncryption.decrypt(@encrypted_0_ssn)
146
147
  end
147
148
  end
148
149
  end
149
150
 
150
- context "random iv" do
151
- setup do
151
+ describe "random iv" do
152
+ before do
152
153
  @social_security_number = "987654321"
153
154
  end
154
155
 
155
- should "encrypt and then decrypt using random iv" do
156
+ it "encrypt and then decrypt using random iv" do
156
157
  # Encrypt with random iv
157
158
  assert encrypted = SymmetricEncryption.encrypt(@social_security_number, random_iv=true)
158
159
  assert_equal true, SymmetricEncryption.encrypted?(encrypted)
159
160
  assert_equal @social_security_number, SymmetricEncryption.decrypt(encrypted)
160
161
  end
161
162
 
162
- should "encrypt and then decrypt using random iv with compression" do
163
+ it "encrypt and then decrypt using random iv with compression" do
163
164
  # Encrypt with random iv and compress
164
165
  assert encrypted = SymmetricEncryption.encrypt(@social_security_number, random_iv=true, compress=true)
165
166
  assert_equal true, SymmetricEncryption.encrypted?(encrypted)
@@ -167,122 +168,122 @@ class SymmetricEncryptionTest < Minitest::Test
167
168
  end
168
169
  end
169
170
 
170
- context "data types" do
171
- context "string" do
172
- setup do
171
+ describe "data types" do
172
+ describe "string" do
173
+ before do
173
174
  @social_security_number = "987654321"
174
175
  end
175
176
 
176
- should "encrypt and decrypt value to and from a string" do
177
+ it "encrypt and decrypt value to and from a string" do
177
178
  assert encrypted = SymmetricEncryption.encrypt(@social_security_number, random_iv=false, compress=false, type=:string)
178
179
  assert_equal true, SymmetricEncryption.encrypted?(encrypted)
179
180
  assert_equal @social_security_number, SymmetricEncryption.decrypt(encrypted, version=nil, type=:string)
180
181
  end
181
182
  end
182
183
 
183
- context "integer" do
184
- setup do
184
+ describe "integer" do
185
+ before do
185
186
  @age = 21
186
187
  end
187
188
 
188
- should "encrypt and decrypt value to and from an integer" do
189
+ it "encrypt and decrypt value to and from an integer" do
189
190
  assert encrypted = SymmetricEncryption.encrypt(@age, random_iv=false, compress=false, type=:integer)
190
191
  assert_equal true, SymmetricEncryption.encrypted?(encrypted)
191
192
  assert_equal @age, SymmetricEncryption.decrypt(encrypted, version=nil, type=:integer)
192
193
  end
193
194
  end
194
195
 
195
- context "float" do
196
- setup do
196
+ describe "float" do
197
+ before do
197
198
  @miles = 2.5
198
199
  end
199
200
 
200
- should "encrypt and decrypt value to and from a float" do
201
+ it "encrypt and decrypt value to and from a float" do
201
202
  assert encrypted = SymmetricEncryption.encrypt(@miles, random_iv=false, compress=false, type=:float)
202
203
  assert_equal true, SymmetricEncryption.encrypted?(encrypted)
203
204
  assert_equal @miles, SymmetricEncryption.decrypt(encrypted, version=nil, type=:float)
204
205
  end
205
206
  end
206
207
 
207
- context "decimal" do
208
- setup do
208
+ describe "decimal" do
209
+ before do
209
210
  @account_balance = BigDecimal.new("12.58")
210
211
  end
211
212
 
212
- should "encrypt and decrypt value to and from a BigDecimal" do
213
+ it "encrypt and decrypt value to and from a BigDecimal" do
213
214
  assert encrypted = SymmetricEncryption.encrypt(@account_balance, random_iv=false, compress=false, type=:decimal)
214
215
  assert_equal true, SymmetricEncryption.encrypted?(encrypted)
215
216
  assert_equal @account_balance, SymmetricEncryption.decrypt(encrypted, version=nil, type=:decimal)
216
217
  end
217
218
  end
218
219
 
219
- context "datetime" do
220
- setup do
220
+ describe "datetime" do
221
+ before do
221
222
  @checked_in_at = DateTime.new(2001, 11, 26, 20, 55, 54, "-5")
222
223
  end
223
224
 
224
- should "encrypt and decrypt value to and from a DateTime" do
225
+ it "encrypt and decrypt value to and from a DateTime" do
225
226
  assert encrypted = SymmetricEncryption.encrypt(@checked_in_at, random_iv=false, compress=false, type=:datetime)
226
227
  assert_equal true, SymmetricEncryption.encrypted?(encrypted)
227
228
  assert_equal @checked_in_at, SymmetricEncryption.decrypt(encrypted, version=nil, type=:datetime)
228
229
  end
229
230
  end
230
231
 
231
- context "time" do
232
- setup do
232
+ describe "time" do
233
+ before do
233
234
  @closing_time = Time.new(2013, 01, 01, 22, 30, 00, "-04:00")
234
235
  end
235
236
 
236
- should "encrypt and decrypt value to and from a Time" do
237
+ it "encrypt and decrypt value to and from a Time" do
237
238
  assert encrypted = SymmetricEncryption.encrypt(@closing_time, random_iv=false, compress=false, type=:time)
238
239
  assert_equal true, SymmetricEncryption.encrypted?(encrypted)
239
240
  assert_equal @closing_time, SymmetricEncryption.decrypt(encrypted, version=nil, type=:time)
240
241
  end
241
242
  end
242
243
 
243
- context "date" do
244
- setup do
244
+ describe "date" do
245
+ before do
245
246
  @birthdate = Date.new(1927, 04, 01)
246
247
  end
247
248
 
248
- should "encrypt and decrypt value to and from a Date" do
249
+ it "encrypt and decrypt value to and from a Date" do
249
250
  assert encrypted = SymmetricEncryption.encrypt(@birthdate, random_iv=false, compress=false, type=:date)
250
251
  assert_equal true, SymmetricEncryption.encrypted?(encrypted)
251
252
  assert_equal @birthdate, SymmetricEncryption.decrypt(encrypted, version=nil, type=:date)
252
253
  end
253
254
  end
254
255
 
255
- context "boolean" do
256
- context "when true" do
257
- setup do
256
+ describe "boolean" do
257
+ describe "when true" do
258
+ before do
258
259
  @is_working = true
259
260
  end
260
261
 
261
- should "encrypt and decrypt a true value to and from a boolean" do
262
+ it "encrypt and decrypt a true value to and from a boolean" do
262
263
  assert encrypted = SymmetricEncryption.encrypt(@is_working, random_iv=false, compress=false, type=:boolean)
263
264
  assert_equal true, SymmetricEncryption.encrypted?(encrypted)
264
265
  assert_equal @is_working, SymmetricEncryption.decrypt(encrypted, version=nil, type=:boolean)
265
266
  end
266
267
  end
267
268
 
268
- context "when false" do
269
- setup do
269
+ describe "when false" do
270
+ before do
270
271
  @is_broken = false
271
272
  end
272
273
 
273
- should "encrypt and decrypt a false value to and from a boolean" do
274
+ it "encrypt and decrypt a false value to and from a boolean" do
274
275
  assert encrypted = SymmetricEncryption.encrypt(@is_broken, random_iv=false, compress=false, type=:boolean)
275
276
  assert_equal true, SymmetricEncryption.encrypted?(encrypted)
276
277
  assert_equal @is_broken, SymmetricEncryption.decrypt(encrypted, version=nil, type=:boolean)
277
278
  end
278
279
  end
279
280
 
280
- context "when yaml" do
281
- setup do
282
- @test = { :a => :b }
281
+ describe "when yaml" do
282
+ before do
283
+ @test = {:a => :b}
283
284
  end
284
285
 
285
- should "encrypt and decrypt a false value to and from a boolean" do
286
+ it "encrypt and decrypt a false value to and from a boolean" do
286
287
  assert encrypted = SymmetricEncryption.encrypt(@test, random_iv=false, compress=false, type=:yaml)
287
288
  assert_equal true, SymmetricEncryption.encrypted?(encrypted)
288
289
  assert_equal @test, SymmetricEncryption.decrypt(encrypted, version=nil, type=:yaml)