test/symmetric_encryption_test.rb in symmetric-encryption-3.8.3 vs test/symmetric_encryption_test.rb in symmetric-encryption-3.9.0

- old
+ new

@@ -39,11 +39,11 @@ assert_equal @cipher_v0.version, cipher.version assert_equal true, SymmetricEncryption.secondary_ciphers.include?(cipher) end end - SymmetricEncryption::Cipher::ENCODINGS.each do |encoding| + [:none, :base64, :base64strict, :base16].each do |encoding| describe "encoding: #{encoding}" do before do @social_security_number = '987654321' @social_security_number_encrypted = case encoding @@ -87,19 +87,19 @@ assert_equal Encoding.find('binary'), decrypted.encoding, decrypted assert_equal @non_utf8, decrypted end it 'return nil when encrypting nil' do - assert_equal nil, SymmetricEncryption.encrypt(nil) + assert_nil SymmetricEncryption.encrypt(nil) end it "return '' when encrypting ''" do assert_equal '', SymmetricEncryption.encrypt('') end it 'return nil when decrypting nil' do - assert_equal nil, SymmetricEncryption.decrypt(nil) + assert_nil SymmetricEncryption.decrypt(nil) end it "return '' when decrypting ''" do assert_equal '', SymmetricEncryption.decrypt('') end @@ -291,8 +291,28 @@ end end end + describe '.generate_symmetric_key_files' do + let(:params) { {private_rsa_key: 'rsa_key', key: 'key', iv: 'iv'} } + let(:file_path) { File.join(File.dirname(__FILE__), 'config', 'symmetric-encryption.yml') } + let(:cipher_config) { {encrypted_key: 'encrypted_key', encrypted_iv: 'encrypted_iv'} } + + let(:config) do + { + private_rsa_key: 'rsa_key', + ciphers: [{version: 1, always_add_header: true, key: 'key', iv: 'iv'}] + } + end + + it 'removes unused config keys before generate the random keys' do + SymmetricEncryption::Config.stub(:read_config, config) do + SymmetricEncryption::Cipher.stub(:generate_random_keys, cipher_config) do + SymmetricEncryption.generate_symmetric_key_files(file_path, 'test') + end + end + end + end end end