mongoid 9.0.11 → 9.0.13

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/lib/config/locales/en.yml +65 -0
  3. data/lib/mongoid/association/depending.rb +8 -4
  4. data/lib/mongoid/association/embedded/batchable.rb +8 -0
  5. data/lib/mongoid/association/nested/many.rb +34 -5
  6. data/lib/mongoid/association/nested/nested_buildable.rb +14 -0
  7. data/lib/mongoid/association/referenced/has_many/proxy.rb +100 -1
  8. data/lib/mongoid/association/relatable.rb +17 -0
  9. data/lib/mongoid/clients/factory.rb +2 -0
  10. data/lib/mongoid/collection_configurable.rb +8 -0
  11. data/lib/mongoid/config/encryption.rb +171 -22
  12. data/lib/mongoid/config.rb +56 -9
  13. data/lib/mongoid/contextual/aggregable/memory.rb +5 -2
  14. data/lib/mongoid/contextual/memory.rb +18 -7
  15. data/lib/mongoid/criteria/queryable/mergeable.rb +4 -0
  16. data/lib/mongoid/criteria/queryable/selectable.rb +109 -0
  17. data/lib/mongoid/encryptable.rb +73 -0
  18. data/lib/mongoid/errors/in_memory_regexp_timeout.rb +26 -0
  19. data/lib/mongoid/errors/invalid_encryption_schema.rb +27 -0
  20. data/lib/mongoid/errors/no_encryption_schema.rb +30 -0
  21. data/lib/mongoid/errors.rb +3 -0
  22. data/lib/mongoid/field_readable.rb +70 -0
  23. data/lib/mongoid/indexable.rb +39 -27
  24. data/lib/mongoid/matchable.rb +6 -1
  25. data/lib/mongoid/matcher/eq_impl_with_regexp.rb +4 -9
  26. data/lib/mongoid/matcher/regex.rb +9 -13
  27. data/lib/mongoid/matcher/regexp_budget.rb +383 -0
  28. data/lib/mongoid/matcher.rb +1 -0
  29. data/lib/mongoid/persistence_context.rb +77 -0
  30. data/lib/mongoid/search_indexable.rb +19 -8
  31. data/lib/mongoid/tasks/database.rb +33 -16
  32. data/lib/mongoid/threaded.rb +37 -0
  33. data/lib/mongoid/version.rb +1 -1
  34. data/lib/mongoid/warnings.rb +4 -0
  35. data/spec/integration/app_spec.rb +7 -0
  36. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +17 -2
  37. data/spec/integration/atomic/modifiers_spec.rb +57 -0
  38. data/spec/integration/dots_and_dollars_spec.rb +12 -2
  39. data/spec/integration/encryption_spec.rb +298 -0
  40. data/spec/integration/matcher_operator_data/regex.yml +21 -0
  41. data/spec/integration/matcher_regexp_timeout_spec.rb +215 -0
  42. data/spec/integration/query_operator_guard_spec.rb +89 -0
  43. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +48 -0
  44. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +145 -0
  45. data/spec/mongoid/attributes/nested_spec.rb +204 -10
  46. data/spec/mongoid/clients/factory_spec.rb +36 -0
  47. data/spec/mongoid/config/defaults_spec.rb +18 -0
  48. data/spec/mongoid/config/encryption_spec.rb +451 -0
  49. data/spec/mongoid/contextual/aggregable/memory_spec.rb +91 -0
  50. data/spec/mongoid/contextual/memory_spec.rb +177 -0
  51. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +2 -0
  52. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +200 -0
  53. data/spec/mongoid/criteria_spec.rb +2 -0
  54. data/spec/mongoid/encryptable_spec.rb +115 -0
  55. data/spec/mongoid/matcher/regexp_budget_spec.rb +576 -0
  56. data/spec/mongoid/search_indexable_spec.rb +34 -1
  57. data/spec/mongoid/tasks/database_spec.rb +31 -0
  58. data/spec/support/crypt/models.rb +253 -0
  59. data/spec/support/models/modifier_models.rb +32 -0
  60. metadata +17 -2
@@ -47,4 +47,257 @@ module Crypt
47
47
  field :vin, type: String, encrypt: true
48
48
  field :make, type: String
49
49
  end
50
+
51
+ # An encrypted model whose database name is a callable resolving to a
52
+ # constant. The callable form of :database is supported by store_in, but the
53
+ # encryption schema map is keyed by namespace and built once, so this model's
54
+ # namespace is not known when the map is generated.
55
+ class DynamicCar
56
+ include Mongoid::Document
57
+
58
+ store_in database: -> { 'vehicles_dynamic' }
59
+
60
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q==', deterministic: true
61
+
62
+ field :vin, type: String, encrypt: true
63
+ end
64
+
65
+ # An encrypted model using the documented multi-tenant idiom, where the
66
+ # database name is only known once a tenant is selected. There is no correct
67
+ # value to resolve at client construction time.
68
+ class TenantCar
69
+ include Mongoid::Document
70
+
71
+ # The fallback keeps this model usable by tasks that iterate every model,
72
+ # such as Mongoid::Tasks::Database.create_collections. Mongoid raises
73
+ # NoMethodError when a callable :database resolves to nil.
74
+ store_in database: -> { Thread.current[:tenant_database] || 'vehicles_no_tenant' }
75
+
76
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q==', deterministic: true
77
+
78
+ field :vin, type: String, encrypt: true
79
+ end
80
+
81
+ # An encrypted model that is embedded by more than one parent, and more than
82
+ # once by the same parent.
83
+ class Token
84
+ include Mongoid::Document
85
+
86
+ field :value, type: String, encrypt: { deterministic: true }
87
+
88
+ embedded_in :tokenized, polymorphic: true
89
+ end
90
+
91
+ # A parent whose encrypted data lives entirely in an embedded model: it has
92
+ # no encrypted field of its own and no encrypt_with.
93
+ class Wallet
94
+ include Mongoid::Document
95
+
96
+ embeds_one :token, class_name: 'Crypt::Token', as: :tokenized
97
+ end
98
+
99
+ # Two parents embedding the same encrypted model.
100
+ class Vault
101
+ include Mongoid::Document
102
+
103
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q=='
104
+
105
+ embeds_one :token, class_name: 'Crypt::Token', as: :tokenized
106
+ end
107
+
108
+ class Chest
109
+ include Mongoid::Document
110
+
111
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q=='
112
+
113
+ embeds_one :token, class_name: 'Crypt::Token', as: :tokenized
114
+ end
115
+
116
+ # A parent embedding the same encrypted model through two relations.
117
+ class Ledger
118
+ include Mongoid::Document
119
+
120
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q=='
121
+
122
+ embeds_one :primary_token, class_name: 'Crypt::Token', as: :tokenized
123
+ embeds_one :backup_token, class_name: 'Crypt::Token', as: :tokenized
124
+ end
125
+
126
+ # Three levels of nesting, where the middle level has no encrypted field of
127
+ # its own.
128
+ class Owner
129
+ include Mongoid::Document
130
+
131
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q=='
132
+
133
+ embeds_one :account, class_name: 'Crypt::Account'
134
+ end
135
+
136
+ class Account
137
+ include Mongoid::Document
138
+
139
+ embedded_in :owner, class_name: 'Crypt::Owner'
140
+ embeds_one :credential, class_name: 'Crypt::Credential'
141
+ end
142
+
143
+ class Credential
144
+ include Mongoid::Document
145
+
146
+ field :secret, type: String, encrypt: { deterministic: true }
147
+
148
+ embedded_in :account, class_name: 'Crypt::Account'
149
+ end
150
+
151
+ # A model that embeds itself. The walk over embedded relations has to stop
152
+ # here, or generating the map never terminates.
153
+ class Comment
154
+ include Mongoid::Document
155
+
156
+ field :body, type: String, encrypt: { deterministic: true }
157
+
158
+ embedded_in :commentable, polymorphic: true
159
+ embeds_one :reply, class_name: 'Crypt::Comment', as: :commentable
160
+ end
161
+
162
+ class Article
163
+ include Mongoid::Document
164
+
165
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q=='
166
+
167
+ embeds_one :comment, class_name: 'Crypt::Comment', as: :commentable
168
+ end
169
+
170
+ # A parent with no encrypted field of its own: the encrypted field lives on
171
+ # the embedded model. Used by the integration specs, so the embedded model
172
+ # carries a key id.
173
+ class Folder
174
+ include Mongoid::Document
175
+
176
+ embeds_one :note, class_name: 'Crypt::Note'
177
+ end
178
+
179
+ class Note
180
+ include Mongoid::Document
181
+
182
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q==', deterministic: true
183
+
184
+ field :text, type: String, encrypt: true
185
+
186
+ embedded_in :folder, class_name: 'Crypt::Folder'
187
+ end
188
+
189
+ # A model naming an embedded class that is never defined. The association
190
+ # cannot be used, so nothing is ever embedded through it, but every model in
191
+ # the application is walked when the schema map is generated.
192
+ class Drawer
193
+ include Mongoid::Document
194
+
195
+ embeds_one :missing_note, class_name: 'Crypt::MissingNote'
196
+ end
197
+
198
+ # The same, on a model that is encrypted itself, so the walk descends into
199
+ # its relations.
200
+ class Cabinet
201
+ include Mongoid::Document
202
+
203
+ field :label, type: String, encrypt: { deterministic: true }
204
+
205
+ embeds_one :missing_note, class_name: 'Crypt::MissingNote'
206
+ end
207
+
208
+ # Two unrelated models stored in one collection, each with its own encrypted
209
+ # field.
210
+ class Badge
211
+ include Mongoid::Document
212
+
213
+ store_in collection: 'crypt_badges'
214
+
215
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q==', deterministic: true
216
+
217
+ field :serial, type: String, encrypt: true
218
+ end
219
+
220
+ class BadgeScan
221
+ include Mongoid::Document
222
+
223
+ store_in collection: 'crypt_badges'
224
+
225
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q==', deterministic: true
226
+
227
+ field :holder, type: String, encrypt: true
228
+ end
229
+
230
+ # Single collection inheritance. Only Member is registered in
231
+ # Mongoid.models; the subclasses are not.
232
+ class Member
233
+ include Mongoid::Document
234
+
235
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q==', deterministic: true
236
+
237
+ field :ssn, type: String, encrypt: true
238
+ end
239
+
240
+ class Employee < Member
241
+ field :salary, type: String, encrypt: true
242
+ end
243
+
244
+ class Contractor < Member
245
+ field :rate, type: String, encrypt: true
246
+ end
247
+
248
+ # Single collection inheritance where only the subclass is encrypted.
249
+ class Listing
250
+ include Mongoid::Document
251
+
252
+ field :title, type: String
253
+ end
254
+
255
+ class PrivateListing < Listing
256
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q==', deterministic: true
257
+
258
+ field :owner_ssn, type: String, encrypt: true
259
+ end
260
+
261
+ # An embeds_one target whose subclass adds an encrypted field.
262
+ class Box
263
+ include Mongoid::Document
264
+
265
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q==', deterministic: true
266
+
267
+ embeds_one :item, class_name: 'Crypt::Item'
268
+ end
269
+
270
+ class Item
271
+ include Mongoid::Document
272
+
273
+ field :label, type: String, encrypt: true
274
+
275
+ embedded_in :box, class_name: 'Crypt::Box'
276
+ end
277
+
278
+ class SealedItem < Item
279
+ field :seal, type: String, encrypt: true
280
+ end
281
+
282
+ # An embeds_one target with no encrypted field, whose subclass has one.
283
+ # Nothing on Locker or Content declares encryption.
284
+ class Locker
285
+ include Mongoid::Document
286
+
287
+ embeds_one :content, class_name: 'Crypt::Content'
288
+ end
289
+
290
+ class Content
291
+ include Mongoid::Document
292
+
293
+ field :label, type: String
294
+
295
+ embedded_in :locker, class_name: 'Crypt::Locker'
296
+ end
297
+
298
+ class SecretContent < Content
299
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q==', deterministic: true
300
+
301
+ field :code, type: String, encrypt: true
302
+ end
50
303
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ModifierModels
4
+ class Cabinet
5
+ include Mongoid::Document
6
+
7
+ embeds_one :drawer, class_name: 'ModifierModels::Drawer', autobuild: true
8
+ end
9
+
10
+ class Drawer
11
+ include Mongoid::Document
12
+
13
+ field :matcher, type: String
14
+ embedded_in :cabinet, class_name: 'ModifierModels::Cabinet'
15
+ embeds_many :items, class_name: 'ModifierModels::Item'
16
+ end
17
+
18
+ class Item
19
+ include Mongoid::Document
20
+
21
+ field :name, type: String
22
+ embedded_in :drawer, class_name: 'ModifierModels::Drawer'
23
+ embeds_many :widgets, class_name: 'ModifierModels::Widget'
24
+ end
25
+
26
+ class Widget
27
+ include Mongoid::Document
28
+
29
+ field :label, type: String
30
+ embedded_in :item, class_name: 'ModifierModels::Item'
31
+ end
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.11
4
+ version: 9.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - The MongoDB Ruby Team
@@ -292,6 +292,7 @@ files:
292
292
  - lib/mongoid/errors/empty_config_file.rb
293
293
  - lib/mongoid/errors/immutable_attribute.rb
294
294
  - lib/mongoid/errors/in_memory_collation_not_supported.rb
295
+ - lib/mongoid/errors/in_memory_regexp_timeout.rb
295
296
  - lib/mongoid/errors/invalid_around_callback.rb
296
297
  - lib/mongoid/errors/invalid_async_query_executor.rb
297
298
  - lib/mongoid/errors/invalid_auto_encryption_configuration.rb
@@ -302,6 +303,7 @@ files:
302
303
  - lib/mongoid/errors/invalid_discriminator_key_target.rb
303
304
  - lib/mongoid/errors/invalid_dot_dollar_assignment.rb
304
305
  - lib/mongoid/errors/invalid_elem_match_operator.rb
306
+ - lib/mongoid/errors/invalid_encryption_schema.rb
305
307
  - lib/mongoid/errors/invalid_estimated_count_criteria.rb
306
308
  - lib/mongoid/errors/invalid_estimated_count_scoping.rb
307
309
  - lib/mongoid/errors/invalid_expression_operator.rb
@@ -335,6 +337,7 @@ files:
335
337
  - lib/mongoid/errors/no_client_hosts.rb
336
338
  - lib/mongoid/errors/no_clients_config.rb
337
339
  - lib/mongoid/errors/no_default_client.rb
340
+ - lib/mongoid/errors/no_encryption_schema.rb
338
341
  - lib/mongoid/errors/no_environment.rb
339
342
  - lib/mongoid/errors/no_map_reduce_output.rb
340
343
  - lib/mongoid/errors/no_metadata.rb
@@ -382,6 +385,7 @@ files:
382
385
  - lib/mongoid/extensions/time_with_zone.rb
383
386
  - lib/mongoid/extensions/true_class.rb
384
387
  - lib/mongoid/factory.rb
388
+ - lib/mongoid/field_readable.rb
385
389
  - lib/mongoid/fields.rb
386
390
  - lib/mongoid/fields/encrypted.rb
387
391
  - lib/mongoid/fields/foreign_key.rb
@@ -429,6 +433,7 @@ files:
429
433
  - lib/mongoid/matcher/not.rb
430
434
  - lib/mongoid/matcher/or.rb
431
435
  - lib/mongoid/matcher/regex.rb
436
+ - lib/mongoid/matcher/regexp_budget.rb
432
437
  - lib/mongoid/matcher/size.rb
433
438
  - lib/mongoid/matcher/type.rb
434
439
  - lib/mongoid/model_resolver.rb
@@ -598,9 +603,11 @@ files:
598
603
  - spec/integration/matcher_operator_data/type_timestamp.yml
599
604
  - spec/integration/matcher_operator_data/type_undefined.yml
600
605
  - spec/integration/matcher_operator_spec.rb
606
+ - spec/integration/matcher_regexp_timeout_spec.rb
601
607
  - spec/integration/matcher_spec.rb
602
608
  - spec/integration/persistence/collection_options_spec.rb
603
609
  - spec/integration/persistence/range_field_spec.rb
610
+ - spec/integration/query_operator_guard_spec.rb
604
611
  - spec/integration/server_query_spec.rb
605
612
  - spec/integration/shardable_spec.rb
606
613
  - spec/integration/stringified_symbol_field_spec.rb
@@ -764,6 +771,7 @@ files:
764
771
  - spec/mongoid/document_persistence_context_spec.rb
765
772
  - spec/mongoid/document_query_spec.rb
766
773
  - spec/mongoid/document_spec.rb
774
+ - spec/mongoid/encryptable_spec.rb
767
775
  - spec/mongoid/equality_spec.rb
768
776
  - spec/mongoid/errors/ambiguous_relationship_spec.rb
769
777
  - spec/mongoid/errors/attribute_not_loaded_spec.rb
@@ -851,6 +859,7 @@ files:
851
859
  - spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml
852
860
  - spec/mongoid/matcher/extract_attribute_data/traversal.yml
853
861
  - spec/mongoid/matcher/extract_attribute_spec.rb
862
+ - spec/mongoid/matcher/regexp_budget_spec.rb
854
863
  - spec/mongoid/model_resolver_spec.rb
855
864
  - spec/mongoid/mongoizable_spec.rb
856
865
  - spec/mongoid/monkey_patches_spec.rb
@@ -1080,6 +1089,7 @@ files:
1080
1089
  - spec/support/models/message.rb
1081
1090
  - spec/support/models/minim.rb
1082
1091
  - spec/support/models/mixed_drink.rb
1092
+ - spec/support/models/modifier_models.rb
1083
1093
  - spec/support/models/mop.rb
1084
1094
  - spec/support/models/movie.rb
1085
1095
  - spec/support/models/my_hash.rb
@@ -1245,7 +1255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1245
1255
  - !ruby/object:Gem::Version
1246
1256
  version: 1.3.6
1247
1257
  requirements: []
1248
- rubygems_version: 4.0.10
1258
+ rubygems_version: 4.0.24
1249
1259
  specification_version: 4
1250
1260
  summary: Elegant Persistence in Ruby for MongoDB.
1251
1261
  test_files:
@@ -1346,9 +1356,11 @@ test_files:
1346
1356
  - spec/integration/matcher_operator_data/type_timestamp.yml
1347
1357
  - spec/integration/matcher_operator_data/type_undefined.yml
1348
1358
  - spec/integration/matcher_operator_spec.rb
1359
+ - spec/integration/matcher_regexp_timeout_spec.rb
1349
1360
  - spec/integration/matcher_spec.rb
1350
1361
  - spec/integration/persistence/collection_options_spec.rb
1351
1362
  - spec/integration/persistence/range_field_spec.rb
1363
+ - spec/integration/query_operator_guard_spec.rb
1352
1364
  - spec/integration/server_query_spec.rb
1353
1365
  - spec/integration/shardable_spec.rb
1354
1366
  - spec/integration/stringified_symbol_field_spec.rb
@@ -1512,6 +1524,7 @@ test_files:
1512
1524
  - spec/mongoid/document_persistence_context_spec.rb
1513
1525
  - spec/mongoid/document_query_spec.rb
1514
1526
  - spec/mongoid/document_spec.rb
1527
+ - spec/mongoid/encryptable_spec.rb
1515
1528
  - spec/mongoid/equality_spec.rb
1516
1529
  - spec/mongoid/errors/ambiguous_relationship_spec.rb
1517
1530
  - spec/mongoid/errors/attribute_not_loaded_spec.rb
@@ -1599,6 +1612,7 @@ test_files:
1599
1612
  - spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml
1600
1613
  - spec/mongoid/matcher/extract_attribute_data/traversal.yml
1601
1614
  - spec/mongoid/matcher/extract_attribute_spec.rb
1615
+ - spec/mongoid/matcher/regexp_budget_spec.rb
1602
1616
  - spec/mongoid/model_resolver_spec.rb
1603
1617
  - spec/mongoid/mongoizable_spec.rb
1604
1618
  - spec/mongoid/monkey_patches_spec.rb
@@ -1828,6 +1842,7 @@ test_files:
1828
1842
  - spec/support/models/message.rb
1829
1843
  - spec/support/models/minim.rb
1830
1844
  - spec/support/models/mixed_drink.rb
1845
+ - spec/support/models/modifier_models.rb
1831
1846
  - spec/support/models/mop.rb
1832
1847
  - spec/support/models/movie.rb
1833
1848
  - spec/support/models/my_hash.rb