mongo 2.18.0.beta1 → 2.18.0

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 (149) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/mongo/bulk_write.rb +8 -2
  4. data/lib/mongo/client.rb +19 -5
  5. data/lib/mongo/client_encryption.rb +86 -4
  6. data/lib/mongo/cluster.rb +6 -4
  7. data/lib/mongo/collection/view/aggregation.rb +3 -0
  8. data/lib/mongo/collection/view/change_stream.rb +9 -0
  9. data/lib/mongo/collection/view/iterable.rb +1 -0
  10. data/lib/mongo/collection/view/readable.rb +11 -3
  11. data/lib/mongo/collection.rb +9 -1
  12. data/lib/mongo/config.rb +11 -0
  13. data/lib/mongo/crypt/auto_encrypter.rb +49 -21
  14. data/lib/mongo/crypt/binding.rb +73 -48
  15. data/lib/mongo/crypt/data_key_context.rb +6 -1
  16. data/lib/mongo/crypt/encryption_io.rb +66 -0
  17. data/lib/mongo/crypt/explicit_encrypter.rb +116 -5
  18. data/lib/mongo/crypt/explicit_encryption_context.rb +3 -8
  19. data/lib/mongo/crypt/handle.rb +26 -8
  20. data/lib/mongo/crypt/kms/aws.rb +11 -3
  21. data/lib/mongo/crypt/kms/azure.rb +14 -6
  22. data/lib/mongo/crypt/kms/gcp.rb +12 -5
  23. data/lib/mongo/crypt/kms/kmip.rb +15 -9
  24. data/lib/mongo/crypt/kms/local.rb +9 -1
  25. data/lib/mongo/crypt/kms/master_key_document.rb +1 -1
  26. data/lib/mongo/crypt/rewrap_many_data_key_context.rb +46 -0
  27. data/lib/mongo/crypt/rewrap_many_data_key_result.rb +37 -0
  28. data/lib/mongo/crypt/status.rb +8 -2
  29. data/lib/mongo/crypt.rb +2 -0
  30. data/lib/mongo/database.rb +10 -27
  31. data/lib/mongo/error/missing_file_chunk.rb +8 -2
  32. data/lib/mongo/grid/stream/read.rb +6 -0
  33. data/lib/mongo/index/view.rb +1 -0
  34. data/lib/mongo/operation/create/op_msg.rb +1 -13
  35. data/lib/mongo/operation/distinct/op_msg.rb +4 -1
  36. data/lib/mongo/protocol/msg.rb +0 -16
  37. data/lib/mongo/server/connection_pool.rb +5 -4
  38. data/lib/mongo/server/monitor/connection.rb +10 -4
  39. data/lib/mongo/server/monitor.rb +4 -0
  40. data/lib/mongo/server/push_monitor.rb +4 -0
  41. data/lib/mongo/version.rb +1 -1
  42. data/lib/mongo.rb +2 -0
  43. data/spec/README.md +14 -0
  44. data/spec/integration/change_stream_spec.rb +1 -1
  45. data/spec/integration/client_construction_spec.rb +73 -7
  46. data/spec/integration/client_side_encryption/auto_encryption_command_monitoring_spec.rb +165 -164
  47. data/spec/integration/client_side_encryption/decryption_events_prose_spec.rb +158 -0
  48. data/spec/integration/client_side_encryption/explicit_queryable_encryption_spec.rb +5 -5
  49. data/spec/integration/client_side_encryption/kms_tls_options_spec.rb +50 -8
  50. data/spec/integration/client_side_encryption/unique_index_on_key_alt_names_prose_spec.rb +85 -0
  51. data/spec/integration/ocsp_verifier_spec.rb +1 -1
  52. data/spec/integration/reconnect_spec.rb +2 -0
  53. data/spec/integration/sdam_events_spec.rb +40 -0
  54. data/spec/integration/srv_monitoring_spec.rb +1 -0
  55. data/spec/integration/srv_spec.rb +1 -0
  56. data/spec/lite_spec_helper.rb +5 -4
  57. data/spec/mongo/bulk_write_spec.rb +13 -0
  58. data/spec/mongo/client_construction_spec.rb +45 -2
  59. data/spec/mongo/client_encryption_spec.rb +0 -12
  60. data/spec/mongo/client_spec.rb +1 -1
  61. data/spec/mongo/collection/view/aggregation_spec.rb +119 -0
  62. data/spec/mongo/collection/view/readable_spec.rb +630 -5
  63. data/spec/mongo/collection_spec.rb +32 -0
  64. data/spec/mongo/crypt/auto_encrypter_spec.rb +110 -0
  65. data/spec/mongo/crypt/binding/context_spec.rb +3 -35
  66. data/spec/mongo/crypt/data_key_context_spec.rb +1 -1
  67. data/spec/mongo/crypt/explicit_encryption_context_spec.rb +8 -3
  68. data/spec/mongo/crypt/handle_spec.rb +39 -3
  69. data/spec/mongo/crypt/kms/credentials_spec.rb +0 -47
  70. data/spec/mongo/index/view_spec.rb +56 -0
  71. data/spec/mongo/operation/create/op_msg_spec.rb +0 -42
  72. data/spec/mongo/server/connection_pool_spec.rb +26 -4
  73. data/spec/mongo/socket/ssl_spec.rb +3 -3
  74. data/spec/runners/crud/requirement.rb +6 -1
  75. data/spec/runners/crud/test.rb +1 -1
  76. data/spec/runners/transactions/spec.rb +2 -2
  77. data/spec/runners/transactions/test.rb +4 -20
  78. data/spec/runners/transactions.rb +2 -2
  79. data/spec/runners/unified/assertions.rb +32 -2
  80. data/spec/runners/unified/change_stream_operations.rb +3 -0
  81. data/spec/runners/unified/client_side_encryption_operations.rb +83 -0
  82. data/spec/runners/unified/crud_operations.rb +17 -2
  83. data/spec/runners/unified/ddl_operations.rb +27 -2
  84. data/spec/runners/unified/grid_fs_operations.rb +21 -0
  85. data/spec/runners/unified/test.rb +59 -1
  86. data/spec/shared/lib/mrss/docker_runner.rb +2 -0
  87. data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
  88. data/spec/shared/lib/mrss/lite_constraints.rb +10 -2
  89. data/spec/shared/shlib/set_env.sh +3 -0
  90. data/spec/solo/clean_exit_spec.rb +5 -0
  91. data/spec/spec_tests/client_side_encryption_spec.rb +1 -1
  92. data/spec/spec_tests/client_side_encryption_unified_spec.rb +16 -0
  93. data/spec/spec_tests/data/change_streams_unified/change-streams-showExpandedEvents.yml +298 -0
  94. data/spec/spec_tests/data/client_side_encryption/create-and-createIndexes.yml +58 -0
  95. data/spec/spec_tests/data/client_side_encryption/fle2-Delete.yml +1 -1
  96. data/spec/spec_tests/data/client_side_encryption/fle2-EncryptedFields-vs-jsonSchema.yml +1 -1
  97. data/spec/spec_tests/data/client_side_encryption/fle2-FindOneAndUpdate.yml +2 -2
  98. data/spec/spec_tests/data/client_side_encryption/fle2-InsertFind-Indexed.yml +1 -1
  99. data/spec/spec_tests/data/client_side_encryption/fle2-Update.yml +2 -2
  100. data/spec/spec_tests/data/client_side_encryption/unified/addKeyAltName.yml +194 -0
  101. data/spec/spec_tests/data/client_side_encryption/unified/createDataKey-kms_providers-invalid.yml +67 -0
  102. data/spec/spec_tests/data/client_side_encryption/unified/createDataKey.yml +309 -0
  103. data/spec/spec_tests/data/client_side_encryption/unified/deleteKey.yml +159 -0
  104. data/spec/spec_tests/data/client_side_encryption/unified/getKey.yml +105 -0
  105. data/spec/spec_tests/data/client_side_encryption/unified/getKeyByAltName.yml +104 -0
  106. data/spec/spec_tests/data/client_side_encryption/unified/getKeys.yml +122 -0
  107. data/spec/spec_tests/data/client_side_encryption/unified/removeKeyAltName.yml +157 -0
  108. data/spec/spec_tests/data/client_side_encryption/unified/rewrapManyDataKey-decrypt_failure.yml +69 -0
  109. data/spec/spec_tests/data/client_side_encryption/unified/rewrapManyDataKey-encrypt_failure.yml +122 -0
  110. data/spec/spec_tests/data/client_side_encryption/unified/rewrapManyDataKey.yml +432 -0
  111. data/spec/spec_tests/data/client_side_encryption/validatorAndPartialFieldExpression.yml +166 -0
  112. data/spec/spec_tests/data/command_monitoring_unified/bulkWrite.yml +68 -0
  113. data/spec/spec_tests/data/command_monitoring_unified/command.yml +50 -0
  114. data/spec/spec_tests/data/command_monitoring_unified/deleteMany.yml +79 -0
  115. data/spec/spec_tests/data/command_monitoring_unified/deleteOne.yml +79 -0
  116. data/spec/spec_tests/data/command_monitoring_unified/find.yml +254 -0
  117. data/spec/spec_tests/data/command_monitoring_unified/insertMany.yml +79 -0
  118. data/spec/spec_tests/data/command_monitoring_unified/insertOne.yml +77 -0
  119. data/spec/spec_tests/data/command_monitoring_unified/unacknowledgedBulkWrite.yml +55 -0
  120. data/spec/spec_tests/data/command_monitoring_unified/updateMany.yml +87 -0
  121. data/spec/spec_tests/data/command_monitoring_unified/updateOne.yml +118 -0
  122. data/spec/spec_tests/data/crud_unified/distinct-comment.yml +98 -0
  123. data/spec/spec_tests/data/gridfs_unified/delete.yml +198 -0
  124. data/spec/spec_tests/data/gridfs_unified/download.yml +241 -0
  125. data/spec/spec_tests/data/gridfs_unified/downloadByName.yml +159 -0
  126. data/spec/spec_tests/data/gridfs_unified/upload-disableMD5.yml +92 -0
  127. data/spec/spec_tests/data/gridfs_unified/upload.yml +288 -0
  128. data/spec/spec_tests/gridfs_unified_spec.rb +13 -0
  129. data/spec/stress/connection_pool_timing_spec.rb +2 -2
  130. data/spec/support/background_thread_registry.rb +3 -13
  131. data/spec/support/certificates/atlas-ocsp-ca.crt +40 -47
  132. data/spec/support/certificates/atlas-ocsp.crt +101 -106
  133. data/spec/support/crypt.rb +57 -13
  134. data/spec/support/macros.rb +10 -0
  135. data/spec/support/spec_config.rb +4 -0
  136. data.tar.gz.sig +0 -0
  137. metadata +1271 -1219
  138. metadata.gz.sig +0 -0
  139. data/spec/spec_tests/command_monitoring_spec.rb +0 -71
  140. data/spec/spec_tests/data/command_monitoring/bulkWrite.yml +0 -49
  141. data/spec/spec_tests/data/command_monitoring/command.yml +0 -61
  142. data/spec/spec_tests/data/command_monitoring/deleteMany.yml +0 -55
  143. data/spec/spec_tests/data/command_monitoring/deleteOne.yml +0 -55
  144. data/spec/spec_tests/data/command_monitoring/find.yml +0 -266
  145. data/spec/spec_tests/data/command_monitoring/insertMany.yml +0 -75
  146. data/spec/spec_tests/data/command_monitoring/insertOne.yml +0 -51
  147. data/spec/spec_tests/data/command_monitoring/unacknowledgedBulkWrite.yml +0 -34
  148. data/spec/spec_tests/data/command_monitoring/updateMany.yml +0 -65
  149. data/spec/spec_tests/data/command_monitoring/updateOne.yml +0 -90
@@ -800,5 +800,37 @@ describe Mongo::Collection do
800
800
  end
801
801
  end
802
802
  end
803
+
804
+ context 'when the change stream is empty' do
805
+ require_wired_tiger
806
+ min_server_fcv '3.6'
807
+ require_topology :replica_set
808
+
809
+ context 'when setting the max_await_time_ms' do
810
+
811
+ let(:change_stream) do
812
+ authorized_collection.watch([], max_await_time_ms: 3000)
813
+ end
814
+
815
+ let(:enum) { change_stream.to_enum }
816
+
817
+ it 'sets the option correctly' do
818
+ expect(change_stream.instance_variable_get(:@cursor)).to receive(:get_more_operation).once.and_wrap_original do |m, *args, &block|
819
+ m.call(*args).tap do |op|
820
+ expect(op.max_time_ms).to eq(3000)
821
+ end
822
+ end
823
+ enum.next
824
+ end
825
+
826
+ it "waits the appropriate amount of time" do
827
+ start_time = Time.now
828
+ enum.try_next
829
+ end_time = Time.now
830
+
831
+ expect(end_time-start_time).to be >= 3
832
+ end
833
+ end
834
+ end
803
835
  end
804
836
  end
@@ -2,6 +2,7 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  require 'spec_helper'
5
+ require 'tempfile'
5
6
 
6
7
  describe Mongo::Crypt::AutoEncrypter do
7
8
  require_libmongocrypt
@@ -98,6 +99,62 @@ describe Mongo::Crypt::AutoEncrypter do
98
99
  auto_encrypter.close
99
100
  end
100
101
 
102
+ describe '#initialize' do
103
+ include_context 'with local kms_providers'
104
+
105
+ let(:auto_encryption_options) do
106
+ {
107
+ kms_providers: local_kms_providers,
108
+ key_vault_namespace: key_vault_namespace,
109
+ schema_map: { "#{db_name}.#{collection_name}": schema_map },
110
+ }
111
+ end
112
+
113
+ let(:auto_encrypter) do
114
+ described_class.new(
115
+ auto_encryption_options.merge(
116
+ client: client,
117
+ # Spawn mongocryptd on non-default port for sharded cluster tests
118
+ extra_options: extra_options
119
+ )
120
+ )
121
+ end
122
+
123
+ context 'when client has an unlimited pool' do
124
+ let(:client) do
125
+ new_local_client_nmio(
126
+ SpecConfig.instance.addresses,
127
+ SpecConfig.instance.test_options.merge(
128
+ max_pool_size: 0,
129
+ database: 'auto_encryption'
130
+ ),
131
+ )
132
+ end
133
+
134
+ it 'reuses the client as key_vault_client and metadata_client' do
135
+ expect(auto_encrypter.key_vault_client).to eq(client)
136
+ expect(auto_encrypter.metadata_client).to eq(client)
137
+ end
138
+ end
139
+
140
+ context 'when client has a limited pool' do
141
+ let(:client) do
142
+ new_local_client_nmio(
143
+ SpecConfig.instance.addresses,
144
+ SpecConfig.instance.test_options.merge(
145
+ max_pool_size: 20,
146
+ database: 'auto_encryption'
147
+ ),
148
+ )
149
+ end
150
+
151
+ it 'creates new client for key_vault_client and metadata_client' do
152
+ expect(auto_encrypter.key_vault_client).not_to eq(client)
153
+ expect(auto_encrypter.metadata_client).not_to eq(client)
154
+ end
155
+ end
156
+ end
157
+
101
158
  context 'with schema map in auto encryption commands' do
102
159
  include_context 'without jsonSchema validator'
103
160
 
@@ -136,6 +193,59 @@ describe Mongo::Crypt::AutoEncrypter do
136
193
  end
137
194
  end
138
195
 
196
+ context 'with schema map file in auto encryption commands' do
197
+ include_context 'without jsonSchema validator'
198
+
199
+ let(:schema_map_file) do
200
+ file = Tempfile.new('schema_map.json')
201
+ file.write(JSON.dump(
202
+ {
203
+ "#{db_name}.#{collection_name}" => schema_map
204
+ }
205
+ ))
206
+ file.flush
207
+ file
208
+ end
209
+
210
+ after do
211
+ schema_map_file.close
212
+ end
213
+
214
+ let(:auto_encryption_options) do
215
+ {
216
+ kms_providers: kms_providers,
217
+ kms_tls_options: kms_tls_options,
218
+ key_vault_namespace: key_vault_namespace,
219
+ schema_map_path: schema_map_file.path
220
+ }
221
+ end
222
+
223
+ context 'with AWS KMS providers' do
224
+ include_context 'with AWS kms_providers'
225
+ it_behaves_like 'a functioning auto encrypter'
226
+ end
227
+
228
+ context 'with Azure KMS providers' do
229
+ include_context 'with Azure kms_providers'
230
+ it_behaves_like 'a functioning auto encrypter'
231
+ end
232
+
233
+ context 'with GCP KMS providers' do
234
+ include_context 'with GCP kms_providers'
235
+ it_behaves_like 'a functioning auto encrypter'
236
+ end
237
+
238
+ context 'with KMIP KMS providers' do
239
+ include_context 'with KMIP kms_providers'
240
+ it_behaves_like 'a functioning auto encrypter'
241
+ end
242
+
243
+ context 'with local KMS providers' do
244
+ include_context 'with local kms_providers'
245
+ it_behaves_like 'a functioning auto encrypter'
246
+ end
247
+ end
248
+
139
249
  context 'with schema map collection validator' do
140
250
  include_context 'with jsonSchema validator'
141
251
 
@@ -255,44 +255,12 @@ describe 'Mongo::Crypt::Binding' do
255
255
  end
256
256
  end
257
257
 
258
- describe '#mongocrypt_ctx_setopt_index_type' do
259
- let(:result) do
260
- Mongo::Crypt::Binding.mongocrypt_ctx_setopt_index_type(
261
- context,
262
- index_type
263
- )
264
- end
265
-
266
- before do
267
- Mongo::Crypt::Binding.mongocrypt_init(mongocrypt)
268
- end
269
-
270
- context 'with equality index type' do
271
- let(:index_type) do
272
- :equality
273
- end
274
-
275
- it 'returns true' do
276
- expect(result).to be true
277
- end
278
- end
279
-
280
- context 'with none index type' do
281
- let(:index_type) do
282
- :none
283
- end
284
-
285
- it 'returns true' do
286
- expect(result).to be true
287
- end
288
- end
289
- end
290
-
291
258
  describe '#mongocrypt_ctx_setopt_query_type' do
292
259
  let(:result) do
293
260
  Mongo::Crypt::Binding.mongocrypt_ctx_setopt_query_type(
294
261
  context,
295
- query_type
262
+ query_type,
263
+ -1
296
264
  )
297
265
  end
298
266
 
@@ -302,7 +270,7 @@ describe 'Mongo::Crypt::Binding' do
302
270
 
303
271
  context 'with equality query type' do
304
272
  let(:query_type) do
305
- :equality
273
+ "equality"
306
274
  end
307
275
 
308
276
  it 'returns true' do
@@ -23,7 +23,7 @@ describe Mongo::Crypt::DataKeyContext do
23
23
 
24
24
  let(:key_alt_names) { [] }
25
25
 
26
- let(:context) { described_class.new(mongocrypt, io, key_document, key_alt_names) }
26
+ let(:context) { described_class.new(mongocrypt, io, key_document, key_alt_names, nil) }
27
27
 
28
28
  describe '#initialize' do
29
29
  shared_examples 'it properly sets key_alt_names' do
@@ -137,7 +137,7 @@ describe Mongo::Crypt::ExplicitEncryptionContext do
137
137
  mongocrypt,
138
138
  io,
139
139
  value,
140
- options.merge(query_type: :equality)
140
+ options.merge(query_type: "equality")
141
141
  )
142
142
  end.to raise_error(ArgumentError, /query_type is allowed only for "Indexed" algorithm/)
143
143
  end
@@ -169,7 +169,12 @@ describe Mongo::Crypt::ExplicitEncryptionContext do
169
169
 
170
170
  it 'initializes context' do
171
171
  expect do
172
- context
172
+ described_class.new(
173
+ mongocrypt,
174
+ io,
175
+ value,
176
+ options.merge(contention_factor: 0)
177
+ )
173
178
  end.not_to raise_error
174
179
  end
175
180
 
@@ -180,7 +185,7 @@ describe Mongo::Crypt::ExplicitEncryptionContext do
180
185
  mongocrypt,
181
186
  io,
182
187
  value,
183
- options.merge(query_type: :equality)
188
+ options.merge(query_type: "equality", contention_factor: 0)
184
189
  )
185
190
  end.not_to raise_error
186
191
  end
@@ -12,8 +12,22 @@ describe Mongo::Crypt::Handle do
12
12
  describe '#initialize' do
13
13
  let(:credentials) { Mongo::Crypt::KMS::Credentials.new(kms_providers) }
14
14
  let(:kms_tls_options) { {} }
15
- let(:handle) { described_class.new(credentials, kms_tls_options, schema_map: schema_map) }
16
- let(:schema_map) { nil }
15
+ let(:handle) do
16
+ described_class.new(
17
+ credentials,
18
+ kms_tls_options,
19
+ schema_map: schema_map,
20
+ schema_map_path: schema_map_path,
21
+ )
22
+ end
23
+
24
+ let(:schema_map) do
25
+ nil
26
+ end
27
+
28
+ let(:schema_map_path) do
29
+ nil
30
+ end
17
31
 
18
32
  shared_examples 'a functioning Mongo::Crypt::Handle' do
19
33
  context 'with valid schema map' do
@@ -22,11 +36,33 @@ describe Mongo::Crypt::Handle do
22
36
  end
23
37
  end
24
38
 
39
+ context 'with valid schema map in a file' do
40
+ let(:schema_map_path) do
41
+ schema_map_file_path
42
+ end
43
+
44
+ context 'without schema_map set' do
45
+ let(:schema_map) do
46
+ nil
47
+ end
48
+
49
+ it 'does not raise an exception' do
50
+ expect { handle }.not_to raise_error
51
+ end
52
+ end
53
+
54
+ context 'with schema_map set' do
55
+ it 'raises an exception' do
56
+ expect { handle }.to raise_error(ArgumentError, /Cannot set both schema_map and schema_map_path options/)
57
+ end
58
+ end
59
+ end
60
+
25
61
  context 'with invalid schema map' do
26
62
  let(:schema_map) { '' }
27
63
 
28
64
  it 'raises an exception' do
29
- expect { handle }.to raise_error(ArgumentError, /schema_map must be a Hash or nil/)
65
+ expect { handle }.to raise_error(ArgumentError, /invalid schema_map; schema_map must be a Hash or nil/)
30
66
  end
31
67
  end
32
68
 
@@ -13,17 +13,6 @@ describe Mongo::Crypt::KMS::Credentials do
13
13
  Mongo::Crypt::KMS::AWS::Credentials.new(kms_provider)
14
14
  end
15
15
 
16
- context 'with empty AWS kms_provider' do
17
- let(:kms_provider) do
18
- {}
19
- end
20
-
21
- it 'raises an exception' do
22
- expect do
23
- params
24
- end.to raise_error(ArgumentError, /The specified KMS provider options are invalid: {}. AWS KMS provider options must be in the format: { access_key_id: 'YOUR-ACCESS-KEY-ID', secret_access_key: 'SECRET-ACCESS-KEY' }/)
25
- end
26
- end
27
16
 
28
17
  %i(access_key_id secret_access_key).each do |key|
29
18
  context "with nil AWS #{key}" do
@@ -96,18 +85,6 @@ describe Mongo::Crypt::KMS::Credentials do
96
85
  Mongo::Crypt::KMS::Azure::Credentials.new(kms_provider)
97
86
  end
98
87
 
99
- context 'with empty Azure kms_provider' do
100
- let(:kms_provider) do
101
- {}
102
- end
103
-
104
- it 'raises an exception' do
105
- expect do
106
- params
107
- end.to raise_error(ArgumentError, /The specified KMS provider options are invalid: {}. Azure KMS provider options must be in the format: { tenant_id: 'TENANT-ID', client_id: 'TENANT_ID', client_secret: 'CLIENT_SECRET' }/)
108
- end
109
- end
110
-
111
88
  %i(tenant_id client_id client_secret).each do |param|
112
89
 
113
90
  context "with nil azure #{param}" do
@@ -219,18 +196,6 @@ describe Mongo::Crypt::KMS::Credentials do
219
196
  Mongo::Crypt::KMS::GCP::Credentials.new(kms_provider)
220
197
  end
221
198
 
222
- context 'with empty GCP kms_provider' do
223
- let(:kms_provider) do
224
- {}
225
- end
226
-
227
- it 'raises an exception' do
228
- expect do
229
- params
230
- end.to raise_error(ArgumentError, /The specified KMS provider options are invalid: {}. GCP KMS provider options must be in the format: { email: 'EMAIL', private_key: 'PRIVATE-KEY' }/)
231
- end
232
- end
233
-
234
199
  %i(email private_key).each do |key|
235
200
  context "with nil GCP #{key}" do
236
201
  let(:kms_provider) do
@@ -331,18 +296,6 @@ describe Mongo::Crypt::KMS::Credentials do
331
296
  Mongo::Crypt::KMS::KMIP::Credentials.new(kms_provider)
332
297
  end
333
298
 
334
- context 'with empty KMIP kms_provider' do
335
- let(:kms_provider) do
336
- {}
337
- end
338
-
339
- it 'raises an exception' do
340
- expect do
341
- params
342
- end.to raise_error(ArgumentError, /The specified KMS provider options are invalid: {}. KMIP KMS provider options must be in the format: { endpoint: 'ENDPOINT' }/)
343
- end
344
- end
345
-
346
299
  context "with nil KMIP endpoint" do
347
300
  let(:kms_provider) do
348
301
  {
@@ -909,6 +909,62 @@ describe Mongo::Index::View do
909
909
  end
910
910
  end
911
911
 
912
+ context 'when providing an invalid wildcard projection expression' do
913
+ min_server_fcv '4.2'
914
+
915
+ it 'raises an exception' do
916
+ expect {
917
+ view.create_one({ '$**' => 1 }, wildcard_projection: 5)
918
+ }.to raise_error(Mongo::Error::OperationFailure, /Error in specification.*wildcardProjection|wildcardProjection.*must be a non-empty object/)
919
+ end
920
+ end
921
+
922
+ context 'when providing a wildcard projection to an invalid base index' do
923
+ min_server_fcv '4.2'
924
+
925
+ it 'raises an exception' do
926
+ expect {
927
+ view.create_one({ 'x' => 1 }, wildcard_projection: { rating: 1 })
928
+ }.to raise_error(Mongo::Error::OperationFailure, /Error in specification.*wildcardProjection|wildcardProjection.*is only allowed/)
929
+ end
930
+ end
931
+
932
+ context 'when providing a valid wildcard projection' do
933
+ min_server_fcv '4.2'
934
+
935
+ let!(:result) do
936
+ view.create_one({ '$**' => 1 }, wildcard_projection: { 'rating' => 1 })
937
+ end
938
+
939
+ let(:indexes) do
940
+ authorized_collection.indexes.get('$**_1')
941
+ end
942
+
943
+ it 'returns ok' do
944
+ expect(result).to be_successful
945
+ end
946
+
947
+ it 'creates an index' do
948
+ expect(indexes).to_not be_nil
949
+ end
950
+
951
+ context 'on server versions <= 4.4' do
952
+ max_server_fcv '4.4'
953
+
954
+ it 'passes wildcardProjection correctly' do
955
+ expect(indexes[:wildcardProjection]).to eq({ 'rating' => 1 })
956
+ end
957
+ end
958
+
959
+ context 'on server versions >= 5.0' do
960
+ min_server_fcv '5.0'
961
+
962
+ it 'passes wildcardProjection correctly' do
963
+ expect(indexes[:wildcardProjection]).to eq({ '_id' => false, 'rating' => true })
964
+ end
965
+ end
966
+ end
967
+
912
968
  context 'when providing hidden option' do
913
969
  let(:index) { view.get('with_hidden_1') }
914
970
 
@@ -81,48 +81,6 @@ describe Mongo::Operation::Create::OpMsg do
81
81
  described_class.new(user_input).send(:selector, connection)
82
82
  end.not_to raise_error
83
83
  end
84
-
85
- context 'with encryptedFields' do
86
- let(:spec) do
87
- {
88
- :selector => { :create => authorized_collection.name },
89
- :db_name => authorized_collection.database.name,
90
- :write_concern => write_concern,
91
- :session => session,
92
- :encrypted_fields => {
93
- 'fields' => [
94
- {
95
- 'path' => "name",
96
- 'bsonType' => "string",
97
- 'queries' => {
98
- 'queryType' => "equality",
99
- 'contention' => 10
100
- }
101
- }
102
- ]
103
- }
104
- }
105
- end
106
-
107
- it 'converts contention values to BSON::Int64' do
108
- selector = op.send(:selector, connection)
109
- expect(selector).to eq({
110
- :create => authorized_collection.name,
111
- :encryptedFields => {
112
- 'fields' => [
113
- {
114
- 'path' => "name",
115
- 'bsonType' => "string",
116
- 'queries' => {
117
- 'queryType' => "equality",
118
- 'contention' => BSON::Int64.new(10)
119
- }
120
- }
121
- ]
122
- }
123
- })
124
- end
125
- end
126
84
  end
127
85
 
128
86
  describe '#message' do
@@ -83,11 +83,21 @@ describe Mongo::Server::ConnectionPool do
83
83
 
84
84
  context 'when min size exceeds default max size' do
85
85
  let (:options) do
86
- { min_pool_size: 10 }
86
+ { min_pool_size: 50 }
87
87
  end
88
88
 
89
89
  it 'sets max size to equal provided min size' do
90
- expect(pool.max_size).to eq(10)
90
+ expect(pool.max_size).to eq(50)
91
+ end
92
+ end
93
+
94
+ context 'when min size is provided and max size is zero (unlimited)' do
95
+ let (:options) do
96
+ { min_size: 10, max_size: 0 }
97
+ end
98
+
99
+ it 'sets max size to zero (unlimited)' do
100
+ expect(pool.max_size).to eq(0)
91
101
  end
92
102
  end
93
103
 
@@ -155,7 +165,7 @@ describe Mongo::Server::ConnectionPool do
155
165
 
156
166
  context 'when no pool size option is provided' do
157
167
  it 'returns the default size' do
158
- expect(pool.max_size).to eq(5)
168
+ expect(pool.max_size).to eq(20)
159
169
  end
160
170
  end
161
171
 
@@ -165,7 +175,7 @@ describe Mongo::Server::ConnectionPool do
165
175
  end
166
176
 
167
177
  it 'returns max size' do
168
- expect(pool.max_size).to eq(5)
178
+ expect(pool.max_size).to eq(20)
169
179
  end
170
180
  end
171
181
  end
@@ -460,6 +470,18 @@ describe Mongo::Server::ConnectionPool do
460
470
  server.pool
461
471
  end
462
472
 
473
+ context 'when max_size is zero (unlimited)' do
474
+ let(:options) do
475
+ { max_size: 0 }
476
+ end
477
+
478
+ it 'checks out a connection' do
479
+ expect do
480
+ pool.check_out
481
+ end.not_to raise_error
482
+ end
483
+ end
484
+
463
485
  context 'when a connection is checked out on a different thread' do
464
486
 
465
487
  let!(:connection) do
@@ -376,7 +376,7 @@ describe Mongo::Socket::SSL do
376
376
 
377
377
  let(:ssl_options) do
378
378
  super().merge(
379
- :ssl_cert => COMMAND_MONITORING_TESTS.first,
379
+ :ssl_cert => CRUD_TESTS.first,
380
380
  :ssl_key => nil,
381
381
  )
382
382
  end
@@ -394,7 +394,7 @@ describe Mongo::Socket::SSL do
394
394
  let(:ssl_options) do
395
395
  super().merge(
396
396
  :ssl_cert => nil,
397
- :ssl_key => COMMAND_MONITORING_TESTS.first,
397
+ :ssl_key => CRUD_TESTS.first,
398
398
  )
399
399
  end
400
400
 
@@ -412,7 +412,7 @@ describe Mongo::Socket::SSL do
412
412
 
413
413
  let(:ssl_options) do
414
414
  super().merge(
415
- :ssl_cert => COMMAND_MONITORING_TESTS.first,
415
+ :ssl_cert => CRUD_TESTS.first,
416
416
  :ssl_key => nil,
417
417
  )
418
418
  end
@@ -4,7 +4,7 @@
4
4
  module Mongo
5
5
  module CRUD
6
6
  class Requirement
7
- YAML_KEYS = %w(auth minServerVersion maxServerVersion topology topologies serverParameters serverless).freeze
7
+ YAML_KEYS = %w(auth minServerVersion maxServerVersion topology topologies serverParameters serverless csfle).freeze
8
8
 
9
9
  def initialize(spec)
10
10
  spec = spec.dup
@@ -49,6 +49,7 @@ module Mongo
49
49
  nil
50
50
  end
51
51
  @auth = spec['auth']
52
+ @csfle = !!spec['csfle'] if spec['csfle']
52
53
  end
53
54
 
54
55
  attr_reader :min_server_version
@@ -112,6 +113,10 @@ module Mongo
112
113
  elsif @auth == false
113
114
  ok &&= !cc.auth_enabled?
114
115
  end
116
+ if @csfle
117
+ ok &&= !!(ENV['LIBMONGOCRYPT_PATH'] || ENV['FLE'])
118
+ ok &&= Gem::Version.new(cc.fcv_ish) >= Gem::Version.new('4.2.0')
119
+ end
115
120
  ok
116
121
  end
117
122
 
@@ -96,7 +96,7 @@ module Mongo
96
96
  elsif @data.is_a?(Array)
97
97
  collection = client[spec.collection_name, write_concern: {w: :majority}]
98
98
  collection.delete_many
99
- collection.insert_many(@data)
99
+ collection.insert_many(@data) unless @data.empty?
100
100
  elsif @data.is_a?(Hash)
101
101
  converter = DataConverter.new
102
102
  @data.each do |collection_name, data|
@@ -19,9 +19,9 @@ module Mongo
19
19
  module Transactions
20
20
 
21
21
  class Spec < Mongo::CRUD::Spec
22
- def tests
22
+ def tests(expectations_bson_types: true)
23
23
  @tests.map do |test|
24
- Mongo::Transactions::TransactionsTest.new(self, @data, test)
24
+ Mongo::Transactions::TransactionsTest.new(self, @data, test, expectations_bson_types: expectations_bson_types)
25
25
  end
26
26
  end
27
27
  end