Skip to content

Commit

Permalink
Merge pull request #78 from FundingCircle/bug_with_vault_load_all_and…
Browse files Browse the repository at this point in the history
…_in_memory

Fixes bug with memory decryption not handing blank values
  • Loading branch information
ahmetabdi authored May 16, 2019
2 parents 0ffd1ae + 2d40b4e commit 659ec59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/vault/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions spec/integration/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 659ec59

Please sign in to comment.