test/cipher_test.rb in symmetric-encryption-4.0.0 vs test/cipher_test.rb in symmetric-encryption-4.0.1

- old
+ new

@@ -1,11 +1,11 @@ require_relative 'test_helper' # Tests for SymmetricEncryption::Cipher class CipherTest < Minitest::Test ['aes-128-cbc'].each do |cipher_name| - #['aes-128-cbc', 'aes-128-gcm'].each do |cipher_name| + # ['aes-128-cbc', 'aes-128-gcm'].each do |cipher_name| describe "Cipher: #{cipher_name}" do describe 'standalone' do it 'allows setting the cipher_name' do cipher = SymmetricEncryption::Cipher.new( cipher_name: cipher_name, @@ -39,11 +39,11 @@ end end end [false, true].each do |always_add_header| - [:none, :base64, :base64strict, :base16].each do |encoding| + %i[none base64 base64strict base16].each do |encoding| describe "encoding: #{encoding} with#{'out' unless always_add_header} header" do before do @social_security_number = '987654321' @encrypted_values = { 'aes-128-cbc' => { @@ -60,11 +60,11 @@ no_header: 'c9378b8ec1d36bcca4a0ef792b42909a' }, none: { header: "@EnC\x00\x00\xC97\x8B\x8E\xC1\xD3k\xCC\xA4\xA0\xEFy+B\x90\x9A", no_header: "\xC97\x8B\x8E\xC1\xD3k\xCC\xA4\xA0\xEFy+B\x90\x9A" - }, + } }, # 'aes-128-gcm' => { # base64: { # header: "QEVuQwAAOcqz9UDbd1Sn\n", # no_header: "Ocqz9UDbd1Sn\n" @@ -171,12 +171,19 @@ @social_security_number = '987654321' end it 'build and parse header' do key = SymmetricEncryption::Key.new(cipher_name: 'aes-128-cbc') - assert binary_header = SymmetricEncryption::Cipher.build_header(SymmetricEncryption.cipher.version, true, key.iv, key.key, key.cipher_name) - header = SymmetricEncryption::Header.new + # Test Deprecated method + binary_header = SymmetricEncryption::Cipher.build_header( + SymmetricEncryption.cipher.version, + true, + key.iv, + key.key, + key.cipher_name + ) + header = SymmetricEncryption::Header.new header.parse(binary_header) assert_equal true, header.compressed? assert random_cipher = SymmetricEncryption::Cipher.new(iv: key.iv, key: key.key, cipher_name: key.cipher_name) assert_equal random_cipher.cipher_name, header.cipher_name, 'Ciphers differ' assert_equal random_cipher.send(:key), header.key, 'Keys differ' @@ -202,9 +209,8 @@ assert encrypted = @cipher.encrypt(@social_security_number, random_iv: true, compress: true) assert_equal @social_security_number, @cipher.decrypt(encrypted) end end end - end end end