test/active_crypto_test.rb in ezcrypto-0.3 vs test/active_crypto_test.rb in ezcrypto-0.5

- old
+ new

@@ -1,10 +1,11 @@ $:.unshift(File.dirname(__FILE__) + "/../lib/") require File.join(File.dirname(__FILE__), 'test_helper') require 'test/unit' require 'active_crypto' + class User < ActiveRecord::Base has_many :secrets has_many :groups keyholder end @@ -39,10 +40,14 @@ Cap.create_for_asset(self,email) end end +class AssetRaw<ActiveRecord::Base + set_table_name "assets" +end + class Cap < ActiveRecord::Base belongs_to :asset encrypt :shared_key def self.find_by_key(cap_key) @@ -91,19 +96,19 @@ encrypt :title,:body, :key=>:group end class ActiveCryptoTest < Test::Unit::TestCase - + def setup end - - def test_key_holder + + def test_key_holder_in_record user=User.new user.name="bob" user.save - assert user.kind_of?(ActiveRecord::Crypto::KeyHolder) + assert user.kind_of?(ActiveCrypto::KeyHolder) assert user.kind_of?(ActiveRecord::Base) assert user.kind_of?(User) assert_nil user.session_key user.enter_password "shhcccc" assert_not_nil user.session_key @@ -114,20 +119,20 @@ user=User.new user.save assert_nil user.session_key user.enter_password "shhcccc" assert_not_nil user.session_key - assert user.kind_of?(ActiveRecord::Crypto::KeyHolder) + assert user.kind_of?(ActiveCrypto::KeyHolder) assert user.kind_of?(ActiveRecord::Base) assert user.kind_of?(User) jill=user.secrets.create assert_not_nil jill - assert jill.kind_of?(ActiveRecord::Crypto::AssociationKeyHolder) - assert jill.kind_of?(ActiveRecord::Crypto::KeyHolder) - assert jill.kind_of?(ActiveRecord::Crypto::Encrypted) + assert jill.kind_of?(ActiveCrypto::AssociationKeyHolder) + assert jill.kind_of?(ActiveCrypto::KeyHolder) + assert jill.kind_of?(ActiveCrypto::Encrypted) assert jill.kind_of?(ActiveRecord::Base) assert jill.kind_of?(Secret) assert jill.respond_to?(:session_key) @@ -179,19 +184,28 @@ key=Asset.create("title","pelle@neubia.com") assert_not_nil key cap=Cap.find_by_key key assert_not_nil cap assert_not_nil cap.asset + assert_equal "title",cap.asset.title + assert_equal "title",cap.asset["title"] assert_equal "pelle@neubia.com",cap.email + assert_equal "pelle@neubia.com",cap["email"] + # Non decrypting version + raw=AssetRaw.find cap.asset.id + assert_not_equal "title",raw.title + assert_not_equal "title",raw["title"] + bob_key=cap.asset.share("bob@bob.com") bob_cap=Cap.find_by_key bob_key assert_not_equal key,bob_key assert_not_nil bob_cap assert_not_nil bob_cap.asset assert_equal "title",bob_cap.asset.title assert_equal "bob@bob.com",bob_cap.email end end +