mongo 2.18.0.beta1 → 2.18.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -292,14 +292,44 @@ describe 'Client-Side Encryption' do
292
292
 
293
293
  context 'with valid certificate' do
294
294
  it 'TLS handshake passes' do
295
- expect do
296
- client_encryption_with_tls.create_data_key(
297
- kms_provider,
298
- {
299
- master_key: master_key
300
- }
301
- )
302
- end.to raise_error(Mongo::Error::KmsError, /libmongocrypt error code/)
295
+ if should_raise_with_tls
296
+ expect do
297
+ client_encryption_with_tls.create_data_key(
298
+ kms_provider,
299
+ {
300
+ master_key: master_key
301
+ }
302
+ )
303
+ end.to raise_error(Mongo::Error::KmsError, /libmongocrypt error code/)
304
+ else
305
+ expect do
306
+ client_encryption_with_tls.create_data_key(
307
+ kms_provider,
308
+ {
309
+ master_key: master_key
310
+ }
311
+ )
312
+ end.not_to raise_error
313
+ end
314
+ end
315
+
316
+ it 'raises KmsError directly without wrapping CryptError' do
317
+ if should_raise_with_tls
318
+ begin
319
+ client_encryption_with_tls.create_data_key(
320
+ kms_provider,
321
+ {
322
+ master_key: master_key
323
+ }
324
+ )
325
+ rescue Mongo::Error::KmsError => exc
326
+ exc.message.should =~ /Error when connecting to KMS provider/
327
+ exc.message.should =~ /libmongocrypt error code/
328
+ exc.message.should_not =~ /CryptError/
329
+ else
330
+ fail 'Expected to raise KmsError'
331
+ end
332
+ end
303
333
  end
304
334
  end
305
335
 
@@ -358,6 +388,10 @@ describe 'Client-Side Encryption' do
358
388
  }
359
389
  end
360
390
 
391
+ let(:should_raise_with_tls) do
392
+ true
393
+ end
394
+
361
395
  it_behaves_like 'it respect KMS TLS options'
362
396
  end
363
397
 
@@ -375,6 +409,10 @@ describe 'Client-Side Encryption' do
375
409
  }
376
410
  end
377
411
 
412
+ let(:should_raise_with_tls) do
413
+ true
414
+ end
415
+
378
416
  it_behaves_like 'it respect KMS TLS options'
379
417
  end
380
418
 
@@ -387,6 +425,10 @@ describe 'Client-Side Encryption' do
387
425
  {}
388
426
  end
389
427
 
428
+ let(:should_raise_with_tls) do
429
+ false
430
+ end
431
+
390
432
  it_behaves_like 'it respect KMS TLS options'
391
433
  end
392
434
 
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require "spec_helper"
5
+
6
+ describe "Decryption events" do
7
+ require_enterprise
8
+ min_server_fcv "4.2"
9
+ require_libmongocrypt
10
+ include_context "define shared FLE helpers"
11
+
12
+ let(:client) do
13
+ ClientRegistry.instance.new_local_client(
14
+ SpecConfig.instance.addresses,
15
+ SpecConfig.instance.test_options.merge(
16
+ database: SpecConfig.instance.test_db,
17
+ )
18
+ )
19
+ end
20
+
21
+ let(:client_encryption) do
22
+ Mongo::ClientEncryption.new(
23
+ client,
24
+ key_vault_namespace: "#{key_vault_db}.#{key_vault_coll}",
25
+ kms_providers: local_kms_providers
26
+ )
27
+ end
28
+
29
+ let(:existing_key_alt_name) do
30
+ 'def'
31
+ end
32
+
33
+ let(:existing_key_id) do
34
+ client_encryption.create_data_key('local', key_alt_names: [existing_key_alt_name])
35
+ end
36
+
37
+ before(:each) do
38
+ client.use(key_vault_db)[key_vault_coll].drop
39
+ client.use(key_vault_db).command({
40
+ createIndexes: key_vault_coll,
41
+ indexes: [
42
+ {
43
+ name: "keyAltNames_1",
44
+ key: { "keyAltNames": 1 },
45
+ unique: true,
46
+ partialFilterExpression: { keyAltNames: { "$exists" => true } },
47
+ },
48
+ ],
49
+ writeConcern: { w: "majority" },
50
+ })
51
+ # Force key creation
52
+ existing_key_id
53
+ end
54
+
55
+ it 'tests create_data_key' do
56
+ expect do
57
+ client_encryption.create_data_key('local', key_alt_names: ['abc'])
58
+ end.not_to raise_error
59
+
60
+ expect do
61
+ client_encryption.create_data_key('local', key_alt_names: [existing_key_alt_name])
62
+ end.to raise_error(Mongo::Error::OperationFailure, /E11000/) # duplicate key error
63
+ end
64
+
65
+ it 'tests add_key_alt_name' do
66
+ key_id = client_encryption.create_data_key('local')
67
+ expect do
68
+ client_encryption.add_key_alt_name(key_id, 'abc')
69
+ end.not_to raise_error
70
+
71
+ expect do
72
+ key_document = client_encryption.add_key_alt_name(key_id, 'abc')
73
+ expect(key_document['keyAltNames']).to include('abc')
74
+ end.not_to raise_error
75
+
76
+ expect do
77
+ client_encryption.add_key_alt_name(key_id, existing_key_alt_name)
78
+ end.to raise_error(Mongo::Error::OperationFailure, /E11000/) # duplicate key error
79
+
80
+ expect do
81
+ key_document = client_encryption.add_key_alt_name(existing_key_id, existing_key_alt_name)
82
+ expect(key_document['keyAltNames']).to include(existing_key_alt_name)
83
+ end.not_to raise_error
84
+ end
85
+ end
@@ -7,7 +7,7 @@ require 'webrick'
7
7
  describe Mongo::Socket::OcspVerifier do
8
8
  require_ocsp_verifier
9
9
  with_openssl_debug
10
- retry_test
10
+ retry_test sleep: 5
11
11
 
12
12
  shared_examples 'verifies' do
13
13
  context 'mri' do
@@ -73,6 +73,7 @@ describe 'Client after reconnect' do
73
73
  end
74
74
 
75
75
  context 'SRV monitor thread' do
76
+ require_external_connectivity
76
77
 
77
78
  let(:uri) do
78
79
  "mongodb+srv://test1.test.build.10gen.cc/?tls=#{SpecConfig.instance.ssl?}"
@@ -140,6 +141,7 @@ describe 'Client after reconnect' do
140
141
  end
141
142
 
142
143
  context 'in unknown topology' do
144
+ require_external_connectivity
143
145
 
144
146
  # JRuby apparently does not implement non-blocking UDP I/O which is used
145
147
  # by RubyDNS:
@@ -135,4 +135,44 @@ describe 'SDAM events' do
135
135
  end
136
136
  end
137
137
  end
138
+
139
+ describe 'server description changed' do
140
+ require_topology :single
141
+
142
+ let(:sdam_proc) do
143
+ Proc.new do |client|
144
+ client.subscribe(Mongo::Monitoring::SERVER_DESCRIPTION_CHANGED, subscriber)
145
+ end
146
+ end
147
+
148
+ let(:client) do
149
+ new_local_client(SpecConfig.instance.addresses,
150
+ # Heartbeat interval is bound by 500 ms
151
+ SpecConfig.instance.test_options.merge(client_options).merge(
152
+ heartbeat_frequency: 0.5,
153
+ sdam_proc: sdam_proc,
154
+ ),
155
+ )
156
+ end
157
+
158
+ let(:client_options) do
159
+ {}
160
+ end
161
+
162
+ it 'is not published when there are no changes in server state' do
163
+ client
164
+ sleep 6
165
+ client.close
166
+
167
+ events = subscriber.select_succeeded_events(Mongo::Monitoring::Event::ServerDescriptionChanged)
168
+
169
+ # In 6 seconds we should have about 10 or 12 heartbeats.
170
+ # We expect 1 or 2 description changes:
171
+ # The first one from unknown to known,
172
+ # The second one because server changes the fields it returns based on
173
+ # driver server check payload (e.g. ismaster/isWritablePrimary).
174
+ events.length.should >= 1
175
+ events.length.should <= 2
176
+ end
177
+ end
138
178
  end
@@ -5,6 +5,7 @@ require 'spec_helper'
5
5
 
6
6
  describe 'SRV Monitoring' do
7
7
  clean_slate_for_all
8
+ require_external_connectivity
8
9
 
9
10
  context 'with SRV lookups mocked at Resolver' do
10
11
  let(:srv_result) do
@@ -5,6 +5,7 @@ require 'spec_helper'
5
5
 
6
6
  describe 'SRV lookup' do
7
7
  context 'end to end' do
8
+ require_external_connectivity
8
9
 
9
10
  # JRuby apparently does not implement non-blocking UDP I/O which is used
10
11
  # by RubyDNS:
@@ -10,8 +10,6 @@ SERVER_DISCOVERY_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/sdam/**/*.yml
10
10
  SDAM_MONITORING_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/sdam_monitoring/*.yml").sort
11
11
  SERVER_SELECTION_RTT_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/server_selection_rtt/*.yml").sort
12
12
  CRUD_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/crud/**/*.yml").sort
13
- CRUD2_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/crud_v2/**/*.yml").sort
14
- COMMAND_MONITORING_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/command_monitoring/**/*.yml").sort
15
13
  CONNECTION_STRING_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/connection_string/*.yml").sort
16
14
  URI_OPTIONS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/uri_options/*.yml").sort
17
15
  GRIDFS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/gridfs/*.yml").sort
@@ -34,7 +32,10 @@ else
34
32
  begin
35
33
  require 'byebug'
36
34
  rescue LoadError
37
- require 'ruby-debug'
35
+ begin
36
+ require 'ruby-debug'
37
+ rescue LoadError
38
+ end
38
39
  end
39
40
  end
40
41
 
@@ -90,7 +91,7 @@ require 'support/background_thread_registry'
90
91
  require 'mrss/session_registry'
91
92
  require 'support/local_resource_registry'
92
93
 
93
- if SpecConfig.instance.mri?
94
+ if SpecConfig.instance.mri? && !SpecConfig.instance.windows?
94
95
  require 'timeout_interrupt'
95
96
  else
96
97
  require 'timeout'
@@ -55,6 +55,19 @@ describe Mongo::BulkWrite do
55
55
  end
56
56
  end
57
57
 
58
+ context 'when providing no requests' do
59
+
60
+ let(:requests) do
61
+ []
62
+ end
63
+
64
+ it 'raises an exception' do
65
+ expect {
66
+ bulk_write.execute
67
+ }.to raise_error(ArgumentError, /Bulk write requests cannot be empty/)
68
+ end
69
+ end
70
+
58
71
  context 'when the operations do not need to be split' do
59
72
 
60
73
  context 'when a write error occurs' do
@@ -844,6 +844,20 @@ describe Mongo::Client do
844
844
  expect(client.options[:max_pool_size]).to eq(options[:max_pool_size])
845
845
  end
846
846
  end
847
+
848
+ context 'when max_pool_size is zero (unlimited)' do
849
+ let(:options) do
850
+ {
851
+ :min_pool_size => 10,
852
+ :max_pool_size => 0
853
+ }
854
+ end
855
+
856
+ it 'sets the option' do
857
+ expect(client.options[:min_pool_size]).to eq(options[:min_pool_size])
858
+ expect(client.options[:max_pool_size]).to eq(options[:max_pool_size])
859
+ end
860
+ end
847
861
  end
848
862
 
849
863
  context 'when max_pool_size is not provided' do
@@ -852,7 +866,7 @@ describe Mongo::Client do
852
866
 
853
867
  let(:options) do
854
868
  {
855
- :min_pool_size => 10
869
+ :min_pool_size => 30
856
870
  }
857
871
  end
858
872
 
@@ -891,6 +905,24 @@ describe Mongo::Client do
891
905
  end
892
906
  end
893
907
 
908
+ context 'when max_pool_size is provided' do
909
+ let(:client) do
910
+ new_local_client_nmio(['127.0.0.1:27017'], options)
911
+ end
912
+
913
+ context 'when max_pool_size is 0 (unlimited)' do
914
+ let(:options) do
915
+ {
916
+ :max_pool_size => 0
917
+ }
918
+ end
919
+
920
+ it 'sets the option' do
921
+ expect(client.options[:max_pool_size]).to eq(options[:max_pool_size])
922
+ end
923
+ end
924
+ end
925
+
894
926
  context 'when max_pool_size and min_pool_size are both nil' do
895
927
 
896
928
  let(:client) do
@@ -1081,6 +1113,17 @@ describe Mongo::Client do
1081
1113
  expect(client.options[:max_pool_size]).to eq(10)
1082
1114
  end
1083
1115
  end
1116
+
1117
+ context 'when max_pool_size is 0 (unlimited)' do
1118
+ let(:uri) do
1119
+ 'mongodb://127.0.0.1:27017/?minPoolSize=10&maxPoolSize=0'
1120
+ end
1121
+
1122
+ it 'sets the option' do
1123
+ expect(client.options[:min_pool_size]).to eq(10)
1124
+ expect(client.options[:max_pool_size]).to eq(0)
1125
+ end
1126
+ end
1084
1127
  end
1085
1128
 
1086
1129
  context 'when max_pool_size is not provided' do
@@ -1088,7 +1131,7 @@ describe Mongo::Client do
1088
1131
  context 'when the min_pool_size is greater than the default max_pool_size' do
1089
1132
 
1090
1133
  let(:uri) do
1091
- 'mongodb://127.0.0.1:27017/?minPoolSize=10'
1134
+ 'mongodb://127.0.0.1:27017/?minPoolSize=30'
1092
1135
  end
1093
1136
 
1094
1137
  it 'raises an Exception' do
@@ -148,16 +148,6 @@ describe Mongo::ClientEncryption do
148
148
  end
149
149
  end
150
150
 
151
- context 'with empty options' do
152
- let(:options) { {} }
153
-
154
- it 'raises an exception' do
155
- expect do
156
- data_key_id
157
- end.to raise_error(ArgumentError, /Key document options must contain a key named :master_key with a Hash value/)
158
- end
159
- end
160
-
161
151
  context 'with nil master key' do
162
152
  let(:options) { { master_key: nil } }
163
153
 
@@ -297,8 +287,6 @@ describe Mongo::ClientEncryption do
297
287
  end
298
288
 
299
289
  it 'raises an exception' do
300
- # RUBY-2129: This error message could be more specific and inform the user
301
- # that there is a problem with their KMS endpoint
302
290
  expect do
303
291
  data_key_id
304
292
  end.to raise_error(Mongo::Error::KmsError, /SocketError/)
@@ -836,7 +836,7 @@ describe Mongo::Client do
836
836
  expect(session).to be_a(Mongo::Session)
837
837
  end
838
838
 
839
- retry_test 4
839
+ retry_test tries: 4
840
840
  it 'sets the last use field to the current time' do
841
841
  expect(session.instance_variable_get(:@server_session).last_use).to be_within(1).of(Time.now)
842
842
  end
@@ -651,4 +651,123 @@ describe Mongo::Collection::View::Aggregation do
651
651
  end
652
652
  end
653
653
  end
654
+
655
+ context "when there is a filter on the view" do
656
+
657
+ context "when broken_view_aggregate is turned off" do
658
+ config_override :broken_view_aggregate, false
659
+
660
+ let(:documents) do
661
+ [
662
+ { city: "Berlin", pop: 18913, neighborhood: "Kreuzberg" },
663
+ { city: "Berlin", pop: 84143, neighborhood: "Mitte" },
664
+ { city: "New York", pop: 40270, neighborhood: "Brooklyn" }
665
+ ]
666
+ end
667
+
668
+ let(:pipeline) do
669
+ [{
670
+ "$project" => {
671
+ city: 1
672
+ }
673
+ }]
674
+ end
675
+
676
+ let(:view) do
677
+ authorized_collection.find(city: "Berlin")
678
+ end
679
+
680
+ before do
681
+ authorized_collection.delete_many
682
+ authorized_collection.insert_many(documents)
683
+ end
684
+
685
+ it "uses the filter on the view" do
686
+ expect(aggregation.to_a.length).to eq(2)
687
+ end
688
+
689
+ it "adds a match stage" do
690
+ expect(aggregation.pipeline.length).to eq(2)
691
+ expect(aggregation.pipeline.first).to eq({ :$match => { "city" => "Berlin" } })
692
+ end
693
+ end
694
+
695
+ context "when broken_view_aggregate is turned on" do
696
+ config_override :broken_view_aggregate, true
697
+
698
+ let(:documents) do
699
+ [
700
+ { city: "Berlin", pop: 18913, neighborhood: "Kreuzberg" },
701
+ { city: "Berlin", pop: 84143, neighborhood: "Mitte" },
702
+ { city: "New York", pop: 40270, neighborhood: "Brooklyn" }
703
+ ]
704
+ end
705
+
706
+ let(:pipeline) do
707
+ [{
708
+ "$project" => {
709
+ city: 1
710
+ }
711
+ }]
712
+ end
713
+
714
+ let(:view) do
715
+ authorized_collection.find(city: "Berlin")
716
+ end
717
+
718
+ before do
719
+ authorized_collection.delete_many
720
+ authorized_collection.insert_many(documents)
721
+ end
722
+
723
+ it "ignores the view filter" do
724
+ expect(aggregation.to_a.length).to eq(3)
725
+ end
726
+
727
+ it "does not add a match stage" do
728
+ expect(aggregation.pipeline.length).to eq(1)
729
+ expect(aggregation.pipeline).to eq([ { "$project" => { city: 1 } } ])
730
+ end
731
+ end
732
+ end
733
+
734
+ context "when there is no filter on the view" do
735
+
736
+ with_config_values :broken_view_aggregate, true, false do
737
+
738
+ let(:documents) do
739
+ [
740
+ { city: "Berlin", pop: 18913, neighborhood: "Kreuzberg" },
741
+ { city: "Berlin", pop: 84143, neighborhood: "Mitte" },
742
+ { city: "New York", pop: 40270, neighborhood: "Brooklyn" }
743
+ ]
744
+ end
745
+
746
+ let(:pipeline) do
747
+ [{
748
+ "$project" => {
749
+ city: 1
750
+ }
751
+ }]
752
+ end
753
+
754
+ let(:view) do
755
+ authorized_collection.find
756
+ end
757
+
758
+ before do
759
+ authorized_collection.delete_many
760
+ authorized_collection.insert_many(documents)
761
+ end
762
+
763
+ it "ignores the view filter" do
764
+ expect(aggregation.to_a.length).to eq(3)
765
+ end
766
+
767
+ it "does not add a match stage" do
768
+ expect(aggregation.pipeline.length).to eq(1)
769
+ expect(aggregation.pipeline).to eq([ { "$project" => { city: 1 } } ])
770
+ end
771
+ end
772
+ end
654
773
  end