mongoid-kms 0.0.28 → 0.0.29
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 +4 -4
- data/lib/mongoid/kms/version.rb +1 -1
- data/lib/mongoid/kms.rb +9 -1
- data/spec/lib/mongoid/kms_spec.rb +29 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ebbda51ef80389eaecf46b37d1a0f51df878c4d
|
4
|
+
data.tar.gz: 3f34f7aa3d3a6fbe073f4d012f79fee453cc56c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39ea9ef53495efc0e3772b8536e1030fd83f1f1fa476140bb04d08d2d4a3414f002c85c4710ce666a12a9ecf88e4faee1498a3fcef8a410625d03ca628feae75
|
7
|
+
data.tar.gz: ff30e0484db64775723c05c56dd500128efbdd184c1942879b10311cad04aaa017c81881ce134bf2aa2b8a2b714bd4c7a3e72290925b93f6d04f3b7e3b7e2cb6
|
data/lib/mongoid/kms/version.rb
CHANGED
data/lib/mongoid/kms.rb
CHANGED
@@ -47,6 +47,14 @@ module Mongoid
|
|
47
47
|
BSON
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
def binary_factory(data)
|
52
|
+
if defined? Moped::BSON
|
53
|
+
Moped::BSON::Binary.new(:generic, data)
|
54
|
+
elsif defined? BSON
|
55
|
+
BSON::Binary.new(data)
|
56
|
+
end
|
57
|
+
end
|
50
58
|
end
|
51
59
|
|
52
60
|
# Instance methods
|
@@ -68,7 +76,7 @@ module Mongoid
|
|
68
76
|
if value.nil?
|
69
77
|
self.send("#{encrypted_field_name}=", nil)
|
70
78
|
else
|
71
|
-
self.send("#{encrypted_field_name}=", Mongoid::Kms.
|
79
|
+
self.send("#{encrypted_field_name}=", Mongoid::Kms.binary_factory(self.class.encrypt_field(self, field_name, value)))
|
72
80
|
end
|
73
81
|
end
|
74
82
|
end
|
@@ -87,4 +87,33 @@ describe Mongoid::Kms do
|
|
87
87
|
o.bla
|
88
88
|
end
|
89
89
|
|
90
|
+
it "works with embedded documents" do
|
91
|
+
class ParentClass
|
92
|
+
include Mongoid::Document
|
93
|
+
|
94
|
+
embeds_one :child_class, class_name: "ChildClass"
|
95
|
+
|
96
|
+
field :unsecure, type: String
|
97
|
+
end
|
98
|
+
|
99
|
+
class ChildClass
|
100
|
+
include Mongoid::Document
|
101
|
+
include Mongoid::Kms
|
102
|
+
|
103
|
+
embedded_in :parent_class
|
104
|
+
|
105
|
+
secure_field :secure, type: String
|
106
|
+
field :unsecure, type: String
|
107
|
+
end
|
108
|
+
|
109
|
+
o = ParentClass.create!(unsecure: "wonder woman")
|
110
|
+
o.child_class = ChildClass.new(secure: "invisible ship", unsecure: "a whip")
|
111
|
+
o.save!
|
112
|
+
|
113
|
+
o.reload
|
114
|
+
expect(o.unsecure).to eq("wonder woman")
|
115
|
+
expect(o.child_class.secure).to eq("invisible ship")
|
116
|
+
expect(o.child_class.unsecure).to eq("a whip")
|
117
|
+
end
|
118
|
+
|
90
119
|
end
|