mongoid-kms 0.0.32 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8740fb7087ff5321a6b9384407c4904db55aa66c
4
- data.tar.gz: 69935f5dfcfa7bb76f2e8a02e0e4db34757ecb5b
3
+ metadata.gz: 223bbdfbc44f7c82f1dddc67f033201abbc6f760
4
+ data.tar.gz: 9213598783f90c60f3dc71fdbf95b530a18f958e
5
5
  SHA512:
6
- metadata.gz: 8c7e9b9284539a70e9d96be0036a3dfad343c4711e8777ea8b2322afa558a65e227f17826c07757a743c6f0a80950a434469619b7b126fab7ae2835150c350c1
7
- data.tar.gz: 8a0726d5ddb9c3c275d1a1af4ffc741d9a91e69a96252143e40c3c98e5dfbfc063639c2ca480fb68b92a129cfed63b69ee01a5a4344a182841cd9dd1bcb07320
6
+ metadata.gz: def657da1f529c0b15579fd6607a4e1d005c86637e7c286e83d6a7df93645bcdbd6f273d2760747ad06f01937b906ee34549e86b6a09cac119e9610f92d82c33
7
+ data.tar.gz: d88d272042c7638c0b756dc93291148f26fc9dccda7909d4e5f3b16945f43a811e8ae8cc8e7e43a9f139912bd090a85d731e95ac20823f04af136028f10c0bd8
@@ -65,7 +65,7 @@ module Mongoid
65
65
  kms_context_value_changed?(field_name) # checks if any of the context fields have changed
66
66
  encrypted_field_name = self.class.get_encrypted_field_name(field_name)
67
67
 
68
- if instance_variable_get("@#{field_name}").nil? && kms_context_value_changed?(field_name)
68
+ if !instance_variable_defined?("@#{field_name}") && kms_context_value_changed?(field_name)
69
69
  raw = self.send(encrypted_field_name)
70
70
  raw = raw.data if raw.is_a?(Mongoid::Kms.bson_class::Binary)
71
71
  value = self.class.decrypt_field(self, field_name, raw, self.class.kms_context_was(self, field_name))
@@ -73,7 +73,7 @@ module Mongoid
73
73
  value = send("#{field_name}")
74
74
  end
75
75
 
76
- if value.nil?
76
+ if value.nil? || value == ""
77
77
  self.send("#{encrypted_field_name}=", nil)
78
78
  else
79
79
  self.send("#{encrypted_field_name}=", Mongoid::Kms.binary_factory(self.class.encrypt_field(self, field_name, value)))
@@ -160,7 +160,9 @@ module Mongoid
160
160
  field encrypted_field_name, type: Mongoid::Kms.bson_class::Binary
161
161
 
162
162
  define_method(field_name) do
163
- instance_variable_get("@#{field_name}") || begin
163
+ if instance_variable_defined?("@#{field_name}")
164
+ instance_variable_get("@#{field_name}")
165
+ else
164
166
  raw = send("kms_secure_#{field_name}")
165
167
  raw = raw.data if raw.is_a?(Mongoid::Kms.bson_class::Binary)
166
168
 
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Kms
3
- VERSION = "0.0.32"
3
+ VERSION = "0.0.33"
4
4
  end
5
5
  end
@@ -19,6 +19,61 @@ describe Mongoid::Kms do
19
19
  expect(o.unsecure).to eq("robin")
20
20
  end
21
21
 
22
+ it "ingores nil on create" do
23
+ o = MyClass.new(unsecure: "robin", secure: nil)
24
+ o.save!
25
+
26
+ o = MyClass.find(o.id)
27
+ expect(o.secure).to be_nil
28
+ expect(o.unsecure).to eq("robin")
29
+ end
30
+
31
+ it "ingores empty string on create" do
32
+ o = MyClass.new(unsecure: "robin", secure: "")
33
+ o.save!
34
+
35
+ o = MyClass.find(o.id)
36
+ expect(o.secure).to be_nil
37
+ expect(o.unsecure).to eq("robin")
38
+ end
39
+
40
+ it "sets nil on update" do
41
+ o = MyClass.new(unsecure: "robin", secure: "old-secure-value")
42
+ o.save!
43
+
44
+ o.update_attributes!(secure: nil)
45
+
46
+ o = MyClass.find(o.id)
47
+ expect(o.secure).to be_nil
48
+ expect(o.unsecure).to eq("robin")
49
+ end
50
+
51
+ it "sets empty string on update" do
52
+ o = MyClass.new(unsecure: "robin", secure: "old-secure-value")
53
+ o.save!
54
+
55
+ o.secure = ""
56
+ o.save!
57
+
58
+ o = MyClass.find(o.id)
59
+ expect(o.secure).to be_nil
60
+ expect(o.unsecure).to eq("robin")
61
+ end
62
+
63
+ it "udpates nil values properly" do
64
+ o = MyClass.new(unsecure: "robin", secure: nil)
65
+ o.save!
66
+
67
+ o.secure = "batman"
68
+ o.save!
69
+
70
+ o = MyClass.find(o.id)
71
+ expect(o.secure).to eq("batman")
72
+ expect(o.unsecure).to eq("robin")
73
+ end
74
+
75
+
76
+
22
77
  it "encrypts the other fields" do
23
78
  o = OtherClass.new(unsecure: "pengiun", super_secure: "joker")
24
79
  o.save!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-kms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.32
4
+ version: 0.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Winslett