symmetric-encryption 3.6.0 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/mongoid_test.rb CHANGED
@@ -1,5 +1,9 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
- if defined?(Mongoid)
1
+ begin
2
+ require 'mongoid'
3
+ require_relative 'test_helper'
4
+ require_relative '../lib/symmetric_encryption/extensions/mongoid/encrypted'
5
+ ENV['RACK_ENV'] = 'test'
6
+
3
7
  Mongoid.logger = SemanticLogger[Mongoid]
4
8
  filename = defined?(Mongoid::VERSION) ? "test/config/mongoid_v3.yml" : "test/config/mongoid_v2.yml"
5
9
  Mongoid.load!(filename)
@@ -14,7 +18,7 @@ if defined?(Mongoid)
14
18
  field :encrypted_long_string, type: String, encrypted: {random_iv: true, compress: true}
15
19
 
16
20
  field :encrypted_integer_value, type: String, encrypted: {type: :integer}
17
- field :aiv, type: String, encrypted: {type: :integer, encrypt_as: :aliased_integer_value}
21
+ field :aiv, type: String, encrypted: {type: :integer, decrypt_as: :aliased_integer_value}
18
22
  field :encrypted_float_value, type: String, encrypted: {type: :float}
19
23
  field :encrypted_decimal_value, type: String, encrypted: {type: :decimal}
20
24
  field :encrypted_datetime_value, type: String, encrypted: {type: :datetime}
@@ -32,7 +36,7 @@ if defined?(Mongoid)
32
36
  #
33
37
  # Unit Tests for field encrypted and validation aspects of SymmetricEncryption
34
38
  #
35
- class MongoidTest < Test::Unit::TestCase
39
+ class MongoidTest < Minitest::Test
36
40
  context 'Mongoid' do
37
41
  setup do
38
42
  @bank_account_number = "1234567890"
@@ -532,4 +536,7 @@ if defined?(Mongoid)
532
536
 
533
537
  end
534
538
  end
539
+
540
+ rescue LoadError
541
+ puts "Not running Mongoid tests because mongoid gem is not installed!!!"
535
542
  end
data/test/reader_test.rb CHANGED
@@ -1,9 +1,9 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require_relative 'test_helper'
2
2
  require 'stringio'
3
3
 
4
4
  # Unit Test for SymmetricEncrypted::ReaderStream
5
5
  #
6
- class ReaderTest < Test::Unit::TestCase
6
+ class ReaderTest < Minitest::Test
7
7
  context SymmetricEncryption::Reader do
8
8
  setup do
9
9
  @data = [
@@ -143,14 +143,14 @@ class ReaderTest < Test::Unit::TestCase
143
143
 
144
144
  should ".empty?" do
145
145
  assert_equal (@data_size==0), SymmetricEncryption::Reader.empty?(@filename)
146
- assert_raise Errno::ENOENT do
146
+ assert_raises Errno::ENOENT do
147
147
  SymmetricEncryption::Reader.empty?('missing_file')
148
148
  end
149
149
  end
150
150
 
151
151
  should ".header_present?" do
152
152
  assert_equal @header, SymmetricEncryption::Reader.header_present?(@filename)
153
- assert_raise Errno::ENOENT do
153
+ assert_raises Errno::ENOENT do
154
154
  SymmetricEncryption::Reader.header_present?('missing_file')
155
155
  end
156
156
  end
@@ -174,8 +174,6 @@ class ReaderTest < Test::Unit::TestCase
174
174
  end
175
175
 
176
176
  should "#read(size)" do
177
- data = nil
178
- eof = nil
179
177
  file = SymmetricEncryption::Reader.open(@filename)
180
178
  eof = file.eof?
181
179
  data = file.read(4096)
@@ -205,15 +203,23 @@ class ReaderTest < Test::Unit::TestCase
205
203
  end
206
204
 
207
205
  should "#gets(nil,size)" do
208
- data = nil
209
- eof = nil
210
206
  file = SymmetricEncryption::Reader.open(@filename)
211
207
  eof = file.eof?
212
208
  data = file.gets(nil,4096)
213
209
  file.close
214
210
 
215
211
  assert_equal @eof, eof
216
- assert_equal (@data_size > 0 ? @data_str : nil), data
212
+ if @data_size > 0
213
+ assert_equal @data_str, data
214
+ else
215
+ # On JRuby Zlib::GzipReader.new(file) returns '' instead of nil
216
+ # on an empty file
217
+ if defined?(JRuby) && options[:compress] && (usecase == :empty)
218
+ assert_equal '', data
219
+ else
220
+ assert_equal nil, data
221
+ end
222
+ end
217
223
  end
218
224
 
219
225
  should "#gets(delim)" do
@@ -303,7 +309,7 @@ class ReaderTest < Test::Unit::TestCase
303
309
 
304
310
  should "decrypt from file in a single read with different version" do
305
311
  # Should fail since file was encrypted using version 0 key
306
- assert_raise OpenSSL::Cipher::CipherError do
312
+ assert_raises OpenSSL::Cipher::CipherError do
307
313
  SymmetricEncryption::Reader.open(@filename, version: 2) {|file| file.read}
308
314
  end
309
315
  end
@@ -1,8 +1,8 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require_relative 'test_helper'
2
2
 
3
3
  # Unit Test for SymmetricEncryption
4
4
  #
5
- class SymmetricEncryptionTest < Test::Unit::TestCase
5
+ class SymmetricEncryptionTest < Minitest::Test
6
6
  context 'SymmetricEncryption' do
7
7
 
8
8
  context 'configuration' do
@@ -276,6 +276,19 @@ class SymmetricEncryptionTest < Test::Unit::TestCase
276
276
  assert_equal @is_broken, SymmetricEncryption.decrypt(encrypted, version=nil, type=:boolean)
277
277
  end
278
278
  end
279
+
280
+ context "when yaml" do
281
+ setup do
282
+ @test = { :a => :b }
283
+ end
284
+
285
+ should "encrypt and decrypt a false value to and from a boolean" do
286
+ assert encrypted = SymmetricEncryption.encrypt(@test, random_iv=false, compress=false, type=:yaml)
287
+ assert_equal true, SymmetricEncryption.encrypted?(encrypted)
288
+ assert_equal @test, SymmetricEncryption.decrypt(encrypted, version=nil, type=:yaml)
289
+ end
290
+ end
291
+
279
292
  end
280
293
  end
281
294
 
data/test/test_db.sqlite3 CHANGED
Binary file
data/test/test_helper.rb CHANGED
@@ -1,17 +1,19 @@
1
1
  # Allow examples to be run in-place without requiring a gem install
2
2
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
3
 
4
- require 'rubygems'
4
+ require 'yaml'
5
+ require 'minitest/autorun'
6
+ require 'minitest/reporters'
7
+ require 'minitest/stub_any_instance'
8
+ require 'shoulda/context'
5
9
  require 'semantic_logger'
6
- require 'erb'
7
- require 'test/unit'
8
10
  # Since we want both the AR and Mongoid extensions loaded we need to require them first
9
11
  require 'active_record'
10
12
  require 'symmetric-encryption'
11
- # Should redefines Proc#bind so must include after Rails
12
- require 'shoulda'
13
13
 
14
- SemanticLogger.add_appender('test.log') if SemanticLogger.appenders.size == 0
14
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
15
+
16
+ SemanticLogger.add_appender('test.log', &SemanticLogger::Appender::Base.colorized_formatter)
15
17
  SemanticLogger.default_level = :trace
16
18
 
17
19
  # Load Symmetric Encryption keys
data/test/writer_test.rb CHANGED
@@ -1,9 +1,9 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require_relative 'test_helper'
2
2
  require 'stringio'
3
3
 
4
4
  # Unit Test for Symmetric::EncryptedStream
5
5
  #
6
- class WriterTest < Test::Unit::TestCase
6
+ class WriterTest < Minitest::Test
7
7
  context SymmetricEncryption::Writer do
8
8
  setup do
9
9
  @data = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symmetric-encryption
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-04 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coercible
@@ -37,6 +37,7 @@ files:
37
37
  - README.md
38
38
  - Rakefile
39
39
  - examples/symmetric-encryption.yml
40
+ - lib/_test_empty
40
41
  - lib/rails/generators/symmetric_encryption/config/config_generator.rb
41
42
  - lib/rails/generators/symmetric_encryption/config/templates/symmetric-encryption.yml
42
43
  - lib/rails/generators/symmetric_encryption/heroku_config/heroku_config_generator.rb
@@ -45,6 +46,7 @@ files:
45
46
  - lib/symmetric-encryption.rb
46
47
  - lib/symmetric_encryption.rb
47
48
  - lib/symmetric_encryption/cipher.rb
49
+ - lib/symmetric_encryption/exception.rb
48
50
  - lib/symmetric_encryption/extensions/active_record/base.rb
49
51
  - lib/symmetric_encryption/extensions/mongo_mapper/plugins/encrypted_key.rb
50
52
  - lib/symmetric_encryption/extensions/mongoid/encrypted.rb
@@ -87,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
89
  requirements:
88
90
  - - ">="
89
91
  - !ruby/object:Gem::Version
90
- version: '0'
92
+ version: 2.0.0
91
93
  required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  requirements:
93
95
  - - ">="
@@ -95,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
97
  version: '0'
96
98
  requirements: []
97
99
  rubyforge_project:
98
- rubygems_version: 2.2.2
100
+ rubygems_version: 2.4.6
99
101
  signing_key:
100
102
  specification_version: 4
101
103
  summary: Symmetric Encryption for Ruby, and Ruby on Rails