test/field_encrypted_test.rb in symmetric-encryption-2.0.2 vs test/field_encrypted_test.rb in symmetric-encryption-2.2.0
- old
+ new
@@ -8,11 +8,10 @@
require 'shoulda'
# Since we want both the Mongoid extensions loaded we need to require it first
require 'active_record'
require 'mongoid'
require 'symmetric-encryption'
-require 'symmetric_encryption/extensions/mongoid/fields'
Mongoid.logger = Logger.new($stdout)
filename = defined?(Mongoid::VERSION) ? "test/config/mongoid_v3.yml" : "test/config/mongoid_v2.yml"
Mongoid.load!(filename)
@@ -20,16 +19,12 @@
include Mongoid::Document
field :name, :type => String
field :encrypted_bank_account_number, :type => String, :encrypted => true
field :encrypted_social_security_number, :type => String, :encrypted => true
- field :encrypted_string, :type => String, :encrypted => true, :random_iv => true
- field :encrypted_long_string, :type => String, :encrypted => true, :random_iv => true, :compress => true
-# field :encrypted_integer, :type => Integer, :encrypted => true
-# field :encrypted_float, :type => Float, :encrypted => true
-# field :encrypted_date, :type => Date, :encrypted => true
- # etc...
+ field :encrypted_string, :type => String, :encrypted => {:random_iv => true}
+ field :encrypted_long_string, :type => String, :encrypted => {:random_iv => true, :compress => true}
# validates :encrypted_bank_account_number, :symmetric_encrypted => true
# validates :encrypted_social_security_number, :symmetric_encrypted => true
end
@@ -62,25 +57,42 @@
# #TODO Intercept passing in attributes to create etc.
@user = MongoidUser.new(
:encrypted_bank_account_number => @bank_account_number_encrypted,
:encrypted_social_security_number => @social_security_number_encrypted,
- :encrypted_integer => @integer_encrypted,
- :encrypted_float => @float_encrypted,
- :encrypted_date => @date_encrypted,
:name => "Joe Bloggs"
)
end
should "have encrypted methods" do
assert_equal true, @user.respond_to?(:encrypted_bank_account_number)
- assert_equal true, @user.respond_to?(:bank_account_number)
assert_equal true, @user.respond_to?(:encrypted_social_security_number)
- assert_equal true, @user.respond_to?(:social_security_number)
+ assert_equal true, @user.respond_to?(:encrypted_string)
+ assert_equal true, @user.respond_to?(:encrypted_long_string)
assert_equal false, @user.respond_to?(:encrypted_name)
+
+ assert_equal true, @user.respond_to?(:encrypted_bank_account_number=)
+ assert_equal true, @user.respond_to?(:encrypted_social_security_number=)
+ assert_equal true, @user.respond_to?(:encrypted_string=)
+ assert_equal true, @user.respond_to?(:encrypted_long_string=)
+ assert_equal false, @user.respond_to?(:encrypted_name=)
end
+ should "have unencrypted methods" do
+ assert_equal true, @user.respond_to?(:bank_account_number)
+ assert_equal true, @user.respond_to?(:social_security_number)
+ assert_equal true, @user.respond_to?(:string)
+ assert_equal true, @user.respond_to?(:long_string)
+ assert_equal true, @user.respond_to?(:name)
+
+ assert_equal true, @user.respond_to?(:bank_account_number=)
+ assert_equal true, @user.respond_to?(:social_security_number=)
+ assert_equal true, @user.respond_to?(:string=)
+ assert_equal true, @user.respond_to?(:long_string=)
+ assert_equal true, @user.respond_to?(:name=)
+ end
+
should "have unencrypted values" do
assert_equal @bank_account_number, @user.bank_account_number
assert_equal @social_security_number, @user.social_security_number
end
@@ -154,13 +166,8 @@
assert_equal @bank_account_number, user.bank_account_number
assert_equal @social_security_number, user.social_security_number
assert_equal @bank_account_number_encrypted, user.encrypted_bank_account_number
assert_equal @social_security_number_encrypted, user.encrypted_social_security_number
end
-
-# should "support different data types" do
-# assert_equal @integer, @user.integer
-# assert_equal @integer_encrypted, @user.encrypted_integer
-# end
end
end
\ No newline at end of file