test/cipher_test.rb in symmetric-encryption-1.0.0 vs test/cipher_test.rb in symmetric-encryption-1.1.1
- old
+ new
@@ -4,10 +4,13 @@
require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'symmetric_encryption'
+# Load Symmetric Encryption keys
+SymmetricEncryption.load!(File.join(File.dirname(__FILE__), 'config', 'symmetric-encryption.yml'), 'test')
+
# Unit Test for SymmetricEncryption::Cipher
#
class CipherTest < Test::Unit::TestCase
context 'standalone' do
@@ -85,9 +88,26 @@
end
should "decode encrypted data as utf-8" do
assert_equal Encoding.find('utf-8'), @cipher.decrypt(@cipher.encrypt(@social_security_number)).encoding
end
+ end
+ end
+
+ context "magic header" do
+
+ should "create and parse magic header" do
+ random_cipher = SymmetricEncryption::Cipher.random_cipher
+ header = random_cipher.magic_header(compressed=true, include_iv=true, include_key=true, include_cipher=true)
+ cipher, compressed = SymmetricEncryption::Cipher.parse_magic_header!(header)
+ assert_equal true, compressed
+ assert_equal random_cipher.cipher, cipher.cipher, "Ciphers differ"
+ assert_equal random_cipher.send(:key), cipher.send(:key), "Keys differ"
+ assert_equal random_cipher.send(:iv), cipher.send(:iv), "IVs differ"
+
+ string = "Hellow World"
+ # Test Encryption
+ assert_equal random_cipher.encrypt(string, false), cipher.encrypt(string, false), "Encrypted values differ"
end
end
end
end
\ No newline at end of file