From 2d40b4e2dd06b503cf3b2440821cfd20238ab2eb Mon Sep 17 00:00:00 2001 From: Ahmet Abdi Date: Thu, 16 May 2019 12:25:21 +0100 Subject: [PATCH] Fixes bug with memory decryption not handing blank values --- lib/vault/rails.rb | 2 +- spec/integration/rails_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/vault/rails.rb b/lib/vault/rails.rb index 455a4710..e56af840 100644 --- a/lib/vault/rails.rb +++ b/lib/vault/rails.rb @@ -220,7 +220,7 @@ def memory_batch_encrypt(path, key, plaintexts, _client) def memory_decrypt(path, key, ciphertext, _client, convergent) log_warning(DEV_WARNING) if self.in_memory_warnings_enabled? - return nil if ciphertext.nil? + return ciphertext if ciphertext.blank? cipher = OpenSSL::Cipher::AES.new(128, :CBC) cipher.decrypt diff --git a/spec/integration/rails_spec.rb b/spec/integration/rails_spec.rb index 4131f25d..9ad8c8a0 100644 --- a/spec/integration/rails_spec.rb +++ b/spec/integration/rails_spec.rb @@ -518,6 +518,20 @@ expect(first_person.email_encrypted).not_to eq(second_person.email_encrypted) end end + + context '.vault_load_all' do + it 'works with records with nil and blank values' do + first_person = LazyPerson.create!(passport_number: nil) + second_person = LazyPerson.create!(passport_number: '') + + first_person.reload + second_person.reload + + LazyPerson.vault_load_all(:passport_number, [first_person, second_person]) + expect(first_person.passport_number).to eq(nil) + expect(second_person.passport_number).to eq('') + end + end end context 'uniqueness validation' do