mlambie (owner)

Revisions

gist: 220522 Download_button fork
public
Description:
Updating an encrypted attribute to an empty string doesn't actually update the attribute
Public Clone URL: git://gist.github.com/220522.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
>> c = Factory(:credit_card)
=> #<CreditCard id: 2, first_name: "Royce", last_name: "Ritchie", number: "4ioaILZVhGjVtdV7yJXBUFl8o6c2LeqPQAkRPSnUHl4=\n", month: 10, year: 2010, scheme: "visa", start_month: nil, start_year: nil, issue_number: nil, created_at: "2009-10-28 14:31:10", updated_at: "2009-10-28 14:31:10", friendly_name: nil, token: "f55440238e4dda3298ee9c625c00494ba6608000">
>> c.number.decrypt(PASSWORD)
=> "4242424242424242"
>> c.number = '4242424242424241'
=> "4242424242424241"
>> c.save
=> false
>> c.number.decrypt(PASSWORD)
=> "4242424242424241"
>> c.errors.full_messages
=> ["Number is not a valid credit card number"]
>> c.number = '4242424242424242'
=> "4242424242424242"
>> c.save
=> true
>> c.number = ''
=> ""
>> c.save
=> true
>> c.number.decrypt(PASSWORD)
=> "4242424242424242"
 
Line 29 of lib/strongbox/lock.rb, in the "encrypt" method:
 
  if !plaintext.blank?
 
Is there a reason why updating existing attributes with empty strings is not allowed?