mongo 2.13.0.rc1 → 2.13.3

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 (68) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/mongo/address.rb +1 -1
  4. data/lib/mongo/auth/aws/request.rb +27 -3
  5. data/lib/mongo/client.rb +48 -2
  6. data/lib/mongo/collection.rb +21 -12
  7. data/lib/mongo/database/view.rb +1 -1
  8. data/lib/mongo/database.rb +14 -2
  9. data/lib/mongo/error/invalid_server_auth_host.rb +22 -0
  10. data/lib/mongo/error/operation_failure.rb +5 -5
  11. data/lib/mongo/error.rb +2 -0
  12. data/lib/mongo/grid/fs_bucket.rb +37 -37
  13. data/lib/mongo/index/view.rb +3 -0
  14. data/lib/mongo/operation/collections_info/command.rb +5 -0
  15. data/lib/mongo/operation/collections_info/result.rb +16 -1
  16. data/lib/mongo/operation/parallel_scan/command.rb +1 -2
  17. data/lib/mongo/operation/shared/read_preference_supported.rb +38 -36
  18. data/lib/mongo/operation/shared/sessions_supported.rb +3 -2
  19. data/lib/mongo/protocol/message.rb +11 -2
  20. data/lib/mongo/protocol/msg.rb +22 -3
  21. data/lib/mongo/protocol/query.rb +47 -11
  22. data/lib/mongo/server/app_metadata.rb +27 -3
  23. data/lib/mongo/server/connection_base.rb +35 -11
  24. data/lib/mongo/server_selector/secondary_preferred.rb +2 -7
  25. data/lib/mongo/version.rb +1 -1
  26. data/spec/integration/bson_symbol_spec.rb +4 -2
  27. data/spec/integration/bulk_write_spec.rb +19 -0
  28. data/spec/integration/client_authentication_options_spec.rb +37 -0
  29. data/spec/integration/client_side_encryption/auto_encryption_bulk_writes_spec.rb +9 -5
  30. data/spec/integration/sdam_error_handling_spec.rb +18 -1
  31. data/spec/integration/sdam_events_spec.rb +8 -7
  32. data/spec/integration/secondary_reads_spec.rb +102 -0
  33. data/spec/integration/size_limit_spec.rb +20 -6
  34. data/spec/lite_spec_helper.rb +1 -1
  35. data/spec/mongo/auth/aws/request_region_spec.rb +42 -0
  36. data/spec/mongo/auth/aws/request_spec.rb +32 -32
  37. data/spec/mongo/client_construction_spec.rb +123 -0
  38. data/spec/mongo/client_encryption_spec.rb +16 -10
  39. data/spec/mongo/crypt/data_key_context_spec.rb +1 -1
  40. data/spec/mongo/database_spec.rb +64 -0
  41. data/spec/mongo/index/view_spec.rb +150 -2
  42. data/spec/mongo/operation/read_preference_legacy_spec.rb +9 -19
  43. data/spec/mongo/operation/read_preference_op_msg_spec.rb +3 -3
  44. data/spec/mongo/server/app_metadata_shared.rb +114 -8
  45. data/spec/mongo/server_selector/secondary_preferred_spec.rb +6 -6
  46. data/spec/runners/transactions/operation.rb +13 -2
  47. data/spec/shared/LICENSE +20 -0
  48. data/spec/shared/bin/get-mongodb-download-url +17 -0
  49. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  50. data/spec/shared/lib/mrss/cluster_config.rb +221 -0
  51. data/spec/shared/lib/mrss/constraints.rb +346 -0
  52. data/spec/shared/lib/mrss/docker_runner.rb +265 -0
  53. data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
  54. data/spec/shared/lib/mrss/server_version_registry.rb +115 -0
  55. data/spec/shared/lib/mrss/spec_organizer.rb +152 -0
  56. data/spec/shared/lib/mrss/utils.rb +15 -0
  57. data/spec/shared/share/Dockerfile.erb +231 -0
  58. data/spec/shared/shlib/distro.sh +73 -0
  59. data/spec/shared/shlib/server.sh +290 -0
  60. data/spec/shared/shlib/set_env.sh +128 -0
  61. data/spec/support/client_registry.rb +8 -4
  62. data/spec/support/client_registry_macros.rb +14 -5
  63. data/spec/support/spec_config.rb +12 -0
  64. data/spec/support/spec_setup.rb +48 -38
  65. data.tar.gz.sig +3 -1
  66. metadata +1005 -974
  67. metadata.gz.sig +0 -0
  68. data/spec/integration/size_limit_spec.rb~12e1e9c4f... RUBY-2242 Fix zlib compression (#2021) +0 -98
@@ -1382,6 +1382,118 @@ describe Mongo::Client do
1382
1382
  end
1383
1383
  end
1384
1384
  =end
1385
+
1386
+ context ':wrapping_libraries option' do
1387
+ let(:options) do
1388
+ {wrapping_libraries: wrapping_libraries}
1389
+ end
1390
+
1391
+ context 'valid input' do
1392
+ context 'symbol keys' do
1393
+ let(:wrapping_libraries) do
1394
+ [name: 'Mongoid', version: '7.1.2'].freeze
1395
+ end
1396
+
1397
+ it 'works' do
1398
+ client.options[:wrapping_libraries].should == ['name' => 'Mongoid', 'version' => '7.1.2']
1399
+ end
1400
+ end
1401
+
1402
+ context 'string keys' do
1403
+ let(:wrapping_libraries) do
1404
+ ['name' => 'Mongoid', 'version' => '7.1.2'].freeze
1405
+ end
1406
+
1407
+ it 'works' do
1408
+ client.options[:wrapping_libraries].should == ['name' => 'Mongoid', 'version' => '7.1.2']
1409
+ end
1410
+ end
1411
+
1412
+ context 'Redacted keys' do
1413
+ let(:wrapping_libraries) do
1414
+ [Mongo::Options::Redacted.new(name: 'Mongoid', version: '7.1.2')].freeze
1415
+ end
1416
+
1417
+ it 'works' do
1418
+ client.options[:wrapping_libraries].should == ['name' => 'Mongoid', 'version' => '7.1.2']
1419
+ end
1420
+ end
1421
+
1422
+ context 'two libraries' do
1423
+ let(:wrapping_libraries) do
1424
+ [
1425
+ {name: 'Mongoid', version: '7.1.2'},
1426
+ {name: 'Rails', version: '4.0', platform: 'Foobar'},
1427
+ ].freeze
1428
+ end
1429
+
1430
+ it 'works' do
1431
+ client.options[:wrapping_libraries].should == [
1432
+ {'name' => 'Mongoid', 'version' => '7.1.2'},
1433
+ {'name' => 'Rails', 'version' => '4.0', 'platform' => 'Foobar'},
1434
+ ]
1435
+ end
1436
+ end
1437
+
1438
+ context 'empty array' do
1439
+ let(:wrapping_libraries) do
1440
+ []
1441
+ end
1442
+
1443
+ it 'works' do
1444
+ client.options[:wrapping_libraries].should == []
1445
+ end
1446
+ end
1447
+
1448
+ context 'empty array' do
1449
+ let(:wrapping_libraries) do
1450
+ nil
1451
+ end
1452
+
1453
+ it 'works' do
1454
+ client.options[:wrapping_libraries].should be nil
1455
+ end
1456
+ end
1457
+ end
1458
+
1459
+ context 'valid input' do
1460
+ context 'hash given instead of an array' do
1461
+ let(:wrapping_libraries) do
1462
+ {name: 'Mongoid', version: '7.1.2'}.freeze
1463
+ end
1464
+
1465
+ it 'is rejected' do
1466
+ lambda do
1467
+ client
1468
+ end.should raise_error(ArgumentError, /:wrapping_libraries must be an array of hashes/)
1469
+ end
1470
+ end
1471
+
1472
+ context 'invalid keys' do
1473
+ let(:wrapping_libraries) do
1474
+ [name: 'Mongoid', invalid: '7.1.2'].freeze
1475
+ end
1476
+
1477
+ it 'is rejected' do
1478
+ lambda do
1479
+ client
1480
+ end.should raise_error(ArgumentError, /:wrapping_libraries element has invalid keys/)
1481
+ end
1482
+ end
1483
+
1484
+ context 'value includes |' do
1485
+ let(:wrapping_libraries) do
1486
+ [name: 'Mongoid|on|Rails', version: '7.1.2'].freeze
1487
+ end
1488
+
1489
+ it 'is rejected' do
1490
+ lambda do
1491
+ client
1492
+ end.should raise_error(ArgumentError, /:wrapping_libraries element value cannot include '|'/)
1493
+ end
1494
+ end
1495
+ end
1496
+ end
1385
1497
  end
1386
1498
 
1387
1499
  context 'when making a block client' do
@@ -1980,6 +2092,7 @@ describe Mongo::Client do
1980
2092
  sdam_proc: sdam_proc,
1981
2093
  connect_timeout: 3.08, socket_timeout: 3.09,
1982
2094
  server_selection_timeout: 2.92,
2095
+ heartbeat_frequency: 100,
1983
2096
  database: SpecConfig.instance.test_db))
1984
2097
  end
1985
2098
 
@@ -2000,6 +2113,10 @@ describe Mongo::Client do
2000
2113
  end
2001
2114
 
2002
2115
  it 'does not notify subscribers set up by sdam_proc' do
2116
+ # On 4.4, the push monitor also is receiving heartbeats.
2117
+ # Give those some time to be processed.
2118
+ sleep 2
2119
+
2003
2120
  expect(subscriber.started_events.length).to be > 0
2004
2121
  subscriber.started_events.clear
2005
2122
 
@@ -2007,6 +2124,12 @@ describe Mongo::Client do
2007
2124
  # subscriber may receive events from the original client.
2008
2125
 
2009
2126
  new_client.cluster.next_primary
2127
+
2128
+ # Diagnostics
2129
+ unless subscriber.started_events.empty?
2130
+ p subscriber.started_events
2131
+ end
2132
+
2010
2133
  expect(subscriber.started_events.length).to eq 0
2011
2134
  new_client.cluster.topology.class.should_not be Mongo::Cluster::Topology::Unknown
2012
2135
  end
@@ -268,7 +268,7 @@ describe Mongo::ClientEncryption do
268
268
  it_behaves_like 'it creates a data key'
269
269
  end
270
270
 
271
- context 'with invalid endpoint' do
271
+ context 'with https' do
272
272
  let(:options) do
273
273
  {
274
274
  master_key: {
@@ -279,20 +279,26 @@ describe Mongo::ClientEncryption do
279
279
  }
280
280
  end
281
281
 
282
- let(:expected_message) do
283
- # RUBY-2129: This error message could be more specific and inform the user
284
- # that there is a problem with their KMS endpoint
285
- if BSON::Environment.jruby?
286
- /getservbyname.* failed/
287
- else
288
- /SocketError/
289
- end
282
+ it_behaves_like 'it creates a data key'
283
+ end
284
+
285
+ context 'with invalid endpoint' do
286
+ let(:options) do
287
+ {
288
+ master_key: {
289
+ key: aws_arn,
290
+ region: aws_region,
291
+ endpoint: "invalid-nonsense-endpoint.com"
292
+ }
293
+ }
290
294
  end
291
295
 
292
296
  it 'raises an exception' do
297
+ # RUBY-2129: This error message could be more specific and inform the user
298
+ # that there is a problem with their KMS endpoint
293
299
  expect do
294
300
  data_key_id
295
- end.to raise_error(Mongo::Error::KmsError, expected_message)
301
+ end.to raise_error(Mongo::Error::KmsError, /SocketError/)
296
302
  end
297
303
  end
298
304
 
@@ -188,7 +188,7 @@ describe Mongo::Crypt::DataKeyContext do
188
188
  end
189
189
 
190
190
  context 'with valid endpoint' do
191
- let(:options) { { master_key: { region: 'us-east-2', key: 'arn', endpoint: 'endpoint/to/kms' } } }
191
+ let(:options) { { master_key: { region: 'us-east-2', key: 'arn', endpoint: 'kms.us-east-2.amazonaws.com:443' } } }
192
192
 
193
193
  it 'does not raise an exception' do
194
194
  expect do
@@ -2,6 +2,19 @@ require 'spec_helper'
2
2
 
3
3
  describe Mongo::Database do
4
4
 
5
+ shared_context 'more than 100 collections' do
6
+ let(:client) do
7
+ root_authorized_client.use('many-collections')
8
+ end
9
+
10
+ before do
11
+ 120.times do |i|
12
+ client["coll-#{i}"].drop
13
+ client["coll-#{i}"].create
14
+ end
15
+ end
16
+ end
17
+
5
18
  describe '#==' do
6
19
 
7
20
  let(:database) do
@@ -228,6 +241,20 @@ describe Mongo::Database do
228
241
  end
229
242
  end
230
243
  end
244
+
245
+ context 'when there are more than 100 collections' do
246
+ include_context 'more than 100 collections'
247
+
248
+ let(:collection_names) do
249
+ client.database.collection_names.sort
250
+ end
251
+
252
+ it 'lists all collections' do
253
+ collection_names.length.should == 120
254
+ collection_names.should include('coll-0')
255
+ collection_names.should include('coll-119')
256
+ end
257
+ end
231
258
  end
232
259
 
233
260
  describe '#list_collections' do
@@ -391,6 +418,25 @@ describe Mongo::Database do
391
418
  end
392
419
  end
393
420
  end
421
+
422
+ context 'when there are more than 100 collections' do
423
+ include_context 'more than 100 collections'
424
+
425
+ let(:collections) do
426
+ client.database.list_collections
427
+ end
428
+
429
+ let(:collection_names) do
430
+ # 2.6 server prefixes collection names with database name
431
+ collections.map { |info| info['name'].sub(/^many-collections\./, '') }.sort
432
+ end
433
+
434
+ it 'lists all collections' do
435
+ collections.length.should == 120
436
+ collection_names.should include('coll-0')
437
+ collection_names.should include('coll-119')
438
+ end
439
+ end
394
440
  end
395
441
 
396
442
  describe '#collections' do
@@ -541,6 +587,24 @@ describe Mongo::Database do
541
587
  end
542
588
  end
543
589
  end
590
+
591
+ context 'when there are more than 100 collections' do
592
+ include_context 'more than 100 collections'
593
+
594
+ let(:collections) do
595
+ client.database.collections
596
+ end
597
+
598
+ let(:collection_names) do
599
+ collections.map(&:name).sort
600
+ end
601
+
602
+ it 'lists all collections' do
603
+ collections.length.should == 120
604
+ collection_names.should include('coll-0')
605
+ collection_names.should include('coll-119')
606
+ end
607
+ end
544
608
  end
545
609
 
546
610
  describe '#command' do
@@ -305,7 +305,8 @@ describe Mongo::Index::View do
305
305
  { key: { testing: -1 }, unique: true },
306
306
  { commit_quorum: 'unsupported-value' }
307
307
  )
308
- end.to raise_error(Mongo::Error::OperationFailure, /Commit quorum cannot be satisfied with the current replica set configuration/)
308
+ # 4.4.4 changed the text of the error message
309
+ end.to raise_error(Mongo::Error::OperationFailure, /Commit quorum cannot be satisfied with the current replica set configuration|No write concern mode named 'unsupported-value' found in replica set configuration/)
309
310
  end
310
311
  end
311
312
  end
@@ -325,6 +326,81 @@ describe Mongo::Index::View do
325
326
  end
326
327
  end
327
328
 
329
+ context 'when hidden is specified' do
330
+ let(:index) { view.get('with_hidden_1') }
331
+
332
+ context 'on server versions <= 3.2' do
333
+ # DRIVERS-1220 Server versions 3.2 and older do not perform any option
334
+ # checking on index creation. The server will allow the user to create
335
+ # the index with the hidden option, but the server does not support this
336
+ # option and will not use it.
337
+ max_server_fcv '3.2'
338
+
339
+ let!(:result) do
340
+ view.create_many({ key: { with_hidden: 1 }, hidden: true })
341
+ end
342
+
343
+ it 'returns ok' do
344
+ expect(result).to be_successful
345
+ end
346
+
347
+ it 'creates an index' do
348
+ expect(index).to_not be_nil
349
+ end
350
+ end
351
+
352
+ context 'on server versions between 3.4 and 4.2' do
353
+ max_server_fcv '4.2'
354
+ min_server_fcv '3.4'
355
+
356
+ it 'raises an exception' do
357
+ expect do
358
+ view.create_many({ key: { with_hidden: 1 }, hidden: true })
359
+ end.to raise_error(/The field 'hidden' is not valid for an index specification/)
360
+ end
361
+ end
362
+
363
+ context 'on server versions >= 4.4' do
364
+ min_server_fcv '4.4'
365
+
366
+ context 'when hidden is true' do
367
+ let!(:result) do
368
+ view.create_many({ key: { with_hidden: 1 }, hidden: true })
369
+ end
370
+
371
+ it 'returns ok' do
372
+ expect(result).to be_successful
373
+ end
374
+
375
+ it 'creates an index' do
376
+ expect(index).to_not be_nil
377
+ end
378
+
379
+ it 'applies the hidden option to the index' do
380
+ expect(index['hidden']).to be true
381
+ end
382
+ end
383
+
384
+ context 'when hidden is false' do
385
+ let!(:result) do
386
+ view.create_many({ key: { with_hidden: 1 }, hidden: false })
387
+ end
388
+
389
+ it 'returns ok' do
390
+ expect(result).to be_successful
391
+ end
392
+
393
+ it 'creates an index' do
394
+ expect(index).to_not be_nil
395
+ end
396
+
397
+ it 'does not apply the hidden option to the index' do
398
+ expect(index['hidden']).to be_nil
399
+ end
400
+ end
401
+ end
402
+ end
403
+
328
404
  context 'when collation is specified' do
329
405
  min_server_fcv '3.4'
330
406
 
@@ -773,6 +849,77 @@ describe Mongo::Index::View do
773
849
  end
774
850
  end
775
851
 
852
+ context 'when providing hidden option' do
853
+ let(:index) { view.get('with_hidden_1') }
854
+
855
+ context 'on server versions <= 3.2' do
856
+ # DRIVERS-1220 Server versions 3.2 and older do not perform any option
857
+ # checking on index creation. The server will allow the user to create
858
+ # the index with the hidden option, but the server does not support this
859
+ # option and will not use it.
860
+ max_server_fcv '3.2'
861
+
862
+ let!(:result) do
863
+ view.create_one({ 'with_hidden' => 1 }, { hidden: true })
864
+ end
865
+
866
+ it 'returns ok' do
867
+ expect(result).to be_successful
868
+ end
869
+
870
+ it 'creates an index' do
871
+ expect(index).to_not be_nil
872
+ end
873
+ end
874
+
875
+ context 'on server versions between 3.4 and 4.2' do
876
+ max_server_fcv '4.2'
877
+ min_server_fcv '3.4'
878
+
879
+ it 'raises an exception' do
880
+ expect do
881
+ view.create_one({ 'with_hidden' => 1 }, { hidden: true })
882
+ end.to raise_error(/The field 'hidden' is not valid for an index specification/)
883
+ end
884
+ end
885
+
886
+ context 'on server versions >= 4.4' do
887
+ min_server_fcv '4.4'
888
+
889
+ context 'when hidden is true' do
890
+ let!(:result) { view.create_one({ 'with_hidden' => 1 }, { hidden: true }) }
891
+
892
+ it 'returns ok' do
893
+ expect(result).to be_successful
894
+ end
895
+
896
+ it 'creates an index' do
897
+ expect(index).to_not be_nil
898
+ end
899
+
900
+ it 'applies the hidden option to the index' do
901
+ expect(index['hidden']).to be true
902
+ end
903
+ end
904
+
905
+ context 'when hidden is false' do
906
+ let!(:result) { view.create_one({ 'with_hidden' => 1 }, { hidden: false }) }
907
+
908
+ it 'returns ok' do
909
+ expect(result).to be_successful
910
+ end
911
+
912
+ it 'creates an index' do
913
+ expect(index).to_not be_nil
914
+ end
915
+
916
+ it 'does not apply the hidden option to the index' do
917
+ expect(index['hidden']).to be_nil
918
+ end
919
+ end
920
+ end
921
+ end
922
+
776
923
  context 'when providing commit_quorum option' do
777
924
  require_topology :replica_set, :sharded
778
925
  context 'on server versions >= 4.4' do
@@ -818,7 +965,8 @@ describe Mongo::Index::View do
818
965
  it 'raises an exception' do
819
966
  expect do
820
967
  view.create_one({ 'x' => 1 }, commit_quorum: 'unsupported-value')
821
- end.to raise_error(Mongo::Error::OperationFailure, /Commit quorum cannot be satisfied with the current replica set configuration/)
968
+ # 4.4.4 changed the text of the error message
969
+ end.to raise_error(Mongo::Error::OperationFailure, /Commit quorum cannot be satisfied with the current replica set configuration|No write concern mode named 'unsupported-value' found in replica set configuration/)
822
970
  end
823
971
  end
824
972
  end