mongo 2.4.2 → 2.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE +1 -1
  5. data/README.md +1 -1
  6. data/lib/mongo.rb +1 -1
  7. data/lib/mongo/address.rb +23 -8
  8. data/lib/mongo/address/ipv4.rb +5 -5
  9. data/lib/mongo/address/ipv6.rb +5 -5
  10. data/lib/mongo/address/unix.rb +3 -3
  11. data/lib/mongo/auth.rb +1 -1
  12. data/lib/mongo/auth/cr.rb +1 -1
  13. data/lib/mongo/auth/ldap.rb +1 -1
  14. data/lib/mongo/auth/roles.rb +1 -1
  15. data/lib/mongo/auth/user.rb +1 -1
  16. data/lib/mongo/auth/user/view.rb +1 -1
  17. data/lib/mongo/auth/x509.rb +1 -1
  18. data/lib/mongo/bson.rb +1 -1
  19. data/lib/mongo/bulk_write.rb +1 -1
  20. data/lib/mongo/bulk_write/combineable.rb +1 -1
  21. data/lib/mongo/bulk_write/ordered_combiner.rb +1 -1
  22. data/lib/mongo/bulk_write/result.rb +1 -1
  23. data/lib/mongo/bulk_write/result_combiner.rb +1 -1
  24. data/lib/mongo/bulk_write/transformable.rb +1 -1
  25. data/lib/mongo/bulk_write/unordered_combiner.rb +1 -1
  26. data/lib/mongo/bulk_write/validatable.rb +1 -1
  27. data/lib/mongo/client.rb +1 -1
  28. data/lib/mongo/cluster.rb +2 -2
  29. data/lib/mongo/cluster/topology.rb +1 -1
  30. data/lib/mongo/cluster/topology/replica_set.rb +1 -1
  31. data/lib/mongo/cluster/topology/sharded.rb +1 -1
  32. data/lib/mongo/cluster/topology/single.rb +1 -1
  33. data/lib/mongo/cluster/topology/unknown.rb +1 -1
  34. data/lib/mongo/collection.rb +1 -1
  35. data/lib/mongo/collection/view.rb +1 -1
  36. data/lib/mongo/collection/view/aggregation.rb +1 -1
  37. data/lib/mongo/collection/view/builder.rb +1 -1
  38. data/lib/mongo/collection/view/builder/aggregation.rb +3 -2
  39. data/lib/mongo/collection/view/builder/find_command.rb +1 -1
  40. data/lib/mongo/collection/view/builder/flags.rb +1 -1
  41. data/lib/mongo/collection/view/builder/map_reduce.rb +1 -1
  42. data/lib/mongo/collection/view/builder/modifiers.rb +1 -1
  43. data/lib/mongo/collection/view/builder/op_query.rb +1 -1
  44. data/lib/mongo/collection/view/explainable.rb +1 -1
  45. data/lib/mongo/collection/view/immutable.rb +1 -1
  46. data/lib/mongo/collection/view/iterable.rb +1 -1
  47. data/lib/mongo/collection/view/map_reduce.rb +1 -1
  48. data/lib/mongo/collection/view/readable.rb +1 -1
  49. data/lib/mongo/collection/view/writable.rb +1 -1
  50. data/lib/mongo/cursor.rb +1 -1
  51. data/lib/mongo/cursor/builder.rb +1 -1
  52. data/lib/mongo/cursor/builder/get_more_command.rb +1 -1
  53. data/lib/mongo/cursor/builder/kill_cursors_command.rb +1 -1
  54. data/lib/mongo/cursor/builder/op_get_more.rb +1 -1
  55. data/lib/mongo/cursor/builder/op_kill_cursors.rb +1 -1
  56. data/lib/mongo/database.rb +1 -1
  57. data/lib/mongo/database/view.rb +1 -1
  58. data/lib/mongo/dbref.rb +1 -1
  59. data/lib/mongo/error.rb +1 -1
  60. data/lib/mongo/error/bulk_write_error.rb +1 -1
  61. data/lib/mongo/error/closed_stream.rb +1 -1
  62. data/lib/mongo/error/extra_file_chunk.rb +1 -1
  63. data/lib/mongo/error/file_not_found.rb +1 -1
  64. data/lib/mongo/error/invalid_bulk_operation.rb +1 -1
  65. data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -1
  66. data/lib/mongo/error/invalid_collection_name.rb +1 -1
  67. data/lib/mongo/error/invalid_database_name.rb +1 -1
  68. data/lib/mongo/error/invalid_document.rb +1 -1
  69. data/lib/mongo/error/invalid_file.rb +1 -1
  70. data/lib/mongo/error/invalid_file_revision.rb +1 -1
  71. data/lib/mongo/error/invalid_min_pool_size.rb +1 -1
  72. data/lib/mongo/error/invalid_nonce.rb +1 -1
  73. data/lib/mongo/error/invalid_replacement_document.rb +1 -1
  74. data/lib/mongo/error/invalid_server_preference.rb +1 -1
  75. data/lib/mongo/error/invalid_signature.rb +1 -1
  76. data/lib/mongo/error/invalid_update_document.rb +1 -1
  77. data/lib/mongo/error/invalid_uri.rb +1 -1
  78. data/lib/mongo/error/invalid_write_concern.rb +1 -1
  79. data/lib/mongo/error/max_bson_size.rb +1 -1
  80. data/lib/mongo/error/max_message_size.rb +1 -1
  81. data/lib/mongo/error/missing_file_chunk.rb +1 -1
  82. data/lib/mongo/error/multi_index_drop.rb +1 -1
  83. data/lib/mongo/error/need_primary_server.rb +1 -1
  84. data/lib/mongo/error/no_server_available.rb +1 -1
  85. data/lib/mongo/error/operation_failure.rb +1 -1
  86. data/lib/mongo/error/parser.rb +1 -1
  87. data/lib/mongo/error/socket_error.rb +1 -1
  88. data/lib/mongo/error/socket_timeout_error.rb +1 -1
  89. data/lib/mongo/error/unchangeable_collection_option.rb +1 -1
  90. data/lib/mongo/error/unexpected_chunk_length.rb +1 -1
  91. data/lib/mongo/error/unexpected_response.rb +1 -1
  92. data/lib/mongo/error/unsupported_collation.rb +1 -1
  93. data/lib/mongo/error/unsupported_features.rb +1 -1
  94. data/lib/mongo/event.rb +1 -1
  95. data/lib/mongo/event/description_changed.rb +1 -1
  96. data/lib/mongo/event/publisher.rb +1 -1
  97. data/lib/mongo/event/subscriber.rb +1 -1
  98. data/lib/mongo/grid.rb +1 -1
  99. data/lib/mongo/grid/file.rb +1 -1
  100. data/lib/mongo/grid/file/chunk.rb +1 -1
  101. data/lib/mongo/grid/file/info.rb +1 -1
  102. data/lib/mongo/grid/fs_bucket.rb +1 -1
  103. data/lib/mongo/grid/stream.rb +1 -1
  104. data/lib/mongo/grid/stream/read.rb +1 -1
  105. data/lib/mongo/grid/stream/write.rb +1 -1
  106. data/lib/mongo/index.rb +1 -1
  107. data/lib/mongo/index/view.rb +1 -1
  108. data/lib/mongo/loggable.rb +1 -1
  109. data/lib/mongo/logger.rb +1 -1
  110. data/lib/mongo/monitoring.rb +1 -1
  111. data/lib/mongo/operation.rb +1 -1
  112. data/lib/mongo/operation/commands.rb +1 -1
  113. data/lib/mongo/operation/commands/aggregate.rb +1 -1
  114. data/lib/mongo/operation/commands/aggregate/result.rb +1 -1
  115. data/lib/mongo/operation/commands/collections_info.rb +1 -1
  116. data/lib/mongo/operation/commands/collections_info/result.rb +1 -1
  117. data/lib/mongo/operation/commands/command.rb +1 -1
  118. data/lib/mongo/operation/commands/create.rb +1 -1
  119. data/lib/mongo/operation/commands/drop.rb +1 -1
  120. data/lib/mongo/operation/commands/drop_database.rb +1 -1
  121. data/lib/mongo/operation/commands/indexes.rb +1 -1
  122. data/lib/mongo/operation/commands/list_collections.rb +1 -1
  123. data/lib/mongo/operation/commands/list_collections/result.rb +1 -1
  124. data/lib/mongo/operation/commands/list_indexes.rb +1 -1
  125. data/lib/mongo/operation/commands/list_indexes/result.rb +1 -1
  126. data/lib/mongo/operation/commands/map_reduce.rb +1 -1
  127. data/lib/mongo/operation/commands/map_reduce/result.rb +1 -1
  128. data/lib/mongo/operation/commands/user_query.rb +1 -1
  129. data/lib/mongo/operation/commands/users_info.rb +1 -1
  130. data/lib/mongo/operation/commands/users_info/result.rb +1 -1
  131. data/lib/mongo/operation/executable.rb +1 -1
  132. data/lib/mongo/operation/kill_cursors.rb +1 -1
  133. data/lib/mongo/operation/limited.rb +1 -1
  134. data/lib/mongo/operation/read.rb +1 -1
  135. data/lib/mongo/operation/read/get_more.rb +1 -1
  136. data/lib/mongo/operation/read/query.rb +1 -1
  137. data/lib/mongo/operation/read/query/result.rb +1 -1
  138. data/lib/mongo/operation/read_preference.rb +1 -1
  139. data/lib/mongo/operation/result.rb +1 -1
  140. data/lib/mongo/operation/specifiable.rb +1 -1
  141. data/lib/mongo/operation/takes_write_concern.rb +1 -1
  142. data/lib/mongo/operation/write.rb +1 -1
  143. data/lib/mongo/operation/write/bulk.rb +1 -1
  144. data/lib/mongo/operation/write/bulk/bulkable.rb +1 -1
  145. data/lib/mongo/operation/write/bulk/delete.rb +1 -1
  146. data/lib/mongo/operation/write/bulk/delete/result.rb +1 -1
  147. data/lib/mongo/operation/write/bulk/insert.rb +1 -1
  148. data/lib/mongo/operation/write/bulk/insert/result.rb +1 -1
  149. data/lib/mongo/operation/write/bulk/legacy_mergable.rb +1 -1
  150. data/lib/mongo/operation/write/bulk/mergable.rb +1 -1
  151. data/lib/mongo/operation/write/bulk/update.rb +1 -1
  152. data/lib/mongo/operation/write/bulk/update/result.rb +1 -1
  153. data/lib/mongo/operation/write/command.rb +1 -1
  154. data/lib/mongo/operation/write/command/create_index.rb +1 -1
  155. data/lib/mongo/operation/write/command/create_user.rb +1 -1
  156. data/lib/mongo/operation/write/command/delete.rb +1 -1
  157. data/lib/mongo/operation/write/command/drop_index.rb +1 -1
  158. data/lib/mongo/operation/write/command/insert.rb +1 -1
  159. data/lib/mongo/operation/write/command/remove_user.rb +1 -1
  160. data/lib/mongo/operation/write/command/update.rb +1 -1
  161. data/lib/mongo/operation/write/command/update_user.rb +1 -1
  162. data/lib/mongo/operation/write/command/writable.rb +1 -1
  163. data/lib/mongo/operation/write/create_index.rb +1 -1
  164. data/lib/mongo/operation/write/create_user.rb +1 -1
  165. data/lib/mongo/operation/write/delete.rb +1 -1
  166. data/lib/mongo/operation/write/delete/result.rb +1 -1
  167. data/lib/mongo/operation/write/drop_index.rb +1 -1
  168. data/lib/mongo/operation/write/gle.rb +1 -1
  169. data/lib/mongo/operation/write/idable.rb +1 -1
  170. data/lib/mongo/operation/write/insert.rb +1 -1
  171. data/lib/mongo/operation/write/insert/result.rb +1 -1
  172. data/lib/mongo/operation/write/remove_user.rb +1 -1
  173. data/lib/mongo/operation/write/update.rb +1 -1
  174. data/lib/mongo/operation/write/update/result.rb +1 -1
  175. data/lib/mongo/operation/write/update_user.rb +1 -1
  176. data/lib/mongo/operation/write/write_command_enabled.rb +1 -1
  177. data/lib/mongo/protocol/bit_vector.rb +1 -1
  178. data/lib/mongo/protocol/delete.rb +1 -1
  179. data/lib/mongo/protocol/get_more.rb +1 -1
  180. data/lib/mongo/protocol/insert.rb +1 -1
  181. data/lib/mongo/protocol/kill_cursors.rb +1 -1
  182. data/lib/mongo/protocol/message.rb +1 -1
  183. data/lib/mongo/protocol/query.rb +2 -2
  184. data/lib/mongo/protocol/reply.rb +1 -1
  185. data/lib/mongo/protocol/serializers.rb +1 -1
  186. data/lib/mongo/protocol/update.rb +1 -1
  187. data/lib/mongo/server.rb +6 -1
  188. data/lib/mongo/server/connectable.rb +1 -13
  189. data/lib/mongo/server/connection.rb +17 -3
  190. data/lib/mongo/server/connection_pool.rb +1 -1
  191. data/lib/mongo/server/connection_pool/queue.rb +1 -1
  192. data/lib/mongo/server/context.rb +1 -1
  193. data/lib/mongo/server/description.rb +2 -2
  194. data/lib/mongo/server/description/features.rb +1 -1
  195. data/lib/mongo/server/description/inspector/description_changed.rb +1 -1
  196. data/lib/mongo/server/monitor.rb +1 -1
  197. data/lib/mongo/server/monitor/connection.rb +15 -9
  198. data/lib/mongo/server_selector.rb +1 -1
  199. data/lib/mongo/server_selector/nearest.rb +1 -1
  200. data/lib/mongo/server_selector/primary.rb +1 -1
  201. data/lib/mongo/server_selector/primary_preferred.rb +1 -1
  202. data/lib/mongo/server_selector/secondary.rb +1 -1
  203. data/lib/mongo/server_selector/secondary_preferred.rb +1 -1
  204. data/lib/mongo/server_selector/selectable.rb +1 -1
  205. data/lib/mongo/socket.rb +1 -1
  206. data/lib/mongo/socket/ssl.rb +4 -4
  207. data/lib/mongo/socket/tcp.rb +4 -4
  208. data/lib/mongo/socket/unix.rb +3 -3
  209. data/lib/mongo/uri.rb +1 -1
  210. data/lib/mongo/version.rb +2 -2
  211. data/lib/mongo/write_concern/acknowledged.rb +1 -1
  212. data/lib/mongo/write_concern/normalizable.rb +1 -1
  213. data/lib/mongo/write_concern/unacknowledged.rb +1 -1
  214. data/mongo.gemspec +0 -1
  215. data/spec/mongo/address_spec.rb +8 -7
  216. data/spec/mongo/client_spec.rb +1 -1
  217. data/spec/mongo/collection/view/aggregation_spec.rb +11 -0
  218. data/spec/mongo/collection_spec.rb +11 -0
  219. data/spec/mongo/server/connection_spec.rb +108 -2
  220. data/spec/mongo/server/description_spec.rb +5 -1
  221. data/spec/mongo/server/monitor/connection_spec.rb +116 -0
  222. data/spec/mongo/socket/ssl_spec.rb +14 -12
  223. data/spec/support/authorization.rb +4 -2
  224. data/spec/support/command_monitoring.rb +1 -1
  225. data/spec/support/connection_string.rb +1 -1
  226. data/spec/support/connection_string_tests/invalid-uris.yml +32 -0
  227. data/spec/support/connection_string_tests/valid-auth.yml +4 -19
  228. data/spec/support/connection_string_tests/valid-db-with-dotted-name.yml +77 -0
  229. data/spec/support/connection_string_tests/valid-options.yml +0 -13
  230. data/spec/support/connection_string_tests/valid-unix_socket-absolute.yml +6 -6
  231. data/spec/support/connection_string_tests/valid-unix_socket-relative.yml +4 -4
  232. data/spec/support/crud.rb +1 -1
  233. data/spec/support/crud/read.rb +3 -3
  234. data/spec/support/crud/write.rb +8 -3
  235. data/spec/support/gridfs.rb +1 -1
  236. metadata +6 -2
  237. metadata.gz.sig +0 -0
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2016 MongoDB, Inc.
1
+ # Copyright (C) 2014-2017 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the 'License');
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2016 MongoDB, Inc.
1
+ # Copyright (C) 2014-2017 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the 'License');
4
4
  # you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@ Gem::Specification.new do |s|
27
27
 
28
28
  s.executables = ['mongo_console']
29
29
  s.require_paths = ['lib']
30
- s.has_rdoc = 'yard'
31
30
  s.bindir = 'bin'
32
31
 
33
32
  s.add_dependency 'bson', '>=4.2.1', '<5.0.0'
@@ -206,17 +206,18 @@ describe Mongo::Address do
206
206
 
207
207
  describe "#socket" do
208
208
 
209
- context 'when providing a DNS entry that resolves to both IPv6 and IPv4' do
209
+ let(:address) do
210
+ default_address
211
+ end
210
212
 
211
- let(:address) do
212
- default_address
213
- end
213
+ let(:host) do
214
+ address.host
215
+ end
214
216
 
215
- let(:host) do
216
- address.host
217
- end
217
+ context 'when providing a DNS entry that resolves to both IPv6 and IPv4' do
218
218
 
219
219
  before do
220
+ address.instance_variable_set(:@resolver, nil)
220
221
  allow(::Socket).to receive(:getaddrinfo).and_return(
221
222
  [ ["AF_INET6", 0, '::1', '::1', ::Socket::AF_INET6, 1, 6],
222
223
  ["AF_INET", 0, host, host, ::Socket::AF_INET, 1, 6]]
@@ -238,7 +238,7 @@ describe Mongo::Client do
238
238
  end
239
239
 
240
240
  let(:client) do
241
- described_class.new(['127.0.0.1:27017'], options)
241
+ described_class.new(['127.0.0.1:27017'], TEST_OPTIONS.merge(options))
242
242
  end
243
243
 
244
244
  it 'sets the ssl option' do
@@ -372,6 +372,17 @@ describe Mongo::Collection::View::Aggregation do
372
372
  end
373
373
  end
374
374
 
375
+ context 'when a hint is specified' do
376
+
377
+ let(:options) do
378
+ { 'hint' => { 'y' => 1 } }
379
+ end
380
+
381
+ it 'includes the option in the spec' do
382
+ expect(aggregation.send(:aggregate_spec)[:selector][:hint]).to eq(options['hint'])
383
+ end
384
+ end
385
+
375
386
  context 'when use_cursor is set' do
376
387
 
377
388
  context 'when use_cursor is true' do
@@ -1170,6 +1170,17 @@ describe Mongo::Collection do
1170
1170
  expect(authorized_collection.aggregate([], options).options).to eq(BSON::Document.new(options))
1171
1171
  end
1172
1172
 
1173
+ context 'when a hint is provided' do
1174
+
1175
+ let(:options) do
1176
+ { 'hint' => { 'y' => 1 } }
1177
+ end
1178
+
1179
+ it 'sets the options on the Aggregation object' do
1180
+ expect(authorized_collection.aggregate([], options).options).to eq(options)
1181
+ end
1182
+ end
1183
+
1173
1184
  context 'when collation is provided' do
1174
1185
 
1175
1186
  before do
@@ -38,8 +38,8 @@ describe Mongo::Server::Connection do
38
38
  end
39
39
 
40
40
  after do
41
- expect(cluster).to receive(:pool).with(server).and_return(pool)
42
- expect(pool).to receive(:disconnect!).and_return(true)
41
+ allow(cluster).to receive(:pool).with(server).and_return(pool)
42
+ allow(pool).to receive(:disconnect!).and_return(true)
43
43
  server.disconnect!
44
44
  end
45
45
 
@@ -432,6 +432,7 @@ describe Mongo::Server::Connection do
432
432
  after do
433
433
  sleep(0.5)
434
434
  authorized_collection.delete_many
435
+ client.close
435
436
  end
436
437
 
437
438
  it 'raises a timeout when it expires' do
@@ -670,4 +671,109 @@ describe Mongo::Server::Connection do
670
671
  end
671
672
  end
672
673
  end
674
+
675
+ context 'when different timeout options are set' do
676
+
677
+ let(:client) do
678
+ authorized_client.with(options)
679
+ end
680
+
681
+ let(:server) do
682
+ client.cluster.next_primary
683
+ end
684
+
685
+ let(:address) do
686
+ server.address
687
+ end
688
+
689
+ let(:connection) do
690
+ described_class.new(server, server.options)
691
+ end
692
+
693
+ after do
694
+ client.close
695
+ end
696
+
697
+ context 'when a connect_timeout is in the options' do
698
+
699
+ context 'when a socket_timeout is in the options' do
700
+
701
+ let(:options) do
702
+ TEST_OPTIONS.merge(connect_timeout: 3, socket_timeout: 5)
703
+ end
704
+
705
+ before do
706
+ connection.connect!
707
+ end
708
+
709
+ it 'uses the connect_timeout for the address' do
710
+ expect(connection.address.send(:connect_timeout)).to eq(3)
711
+ end
712
+
713
+ it 'uses the socket_timeout as the socket_timeout' do
714
+ expect(connection.send(:socket).timeout).to eq(5)
715
+ end
716
+ end
717
+
718
+ context 'when a socket_timeout is not in the options' do
719
+
720
+ let(:options) do
721
+ TEST_OPTIONS.merge(connect_timeout: 3, socket_timeout: nil)
722
+ end
723
+
724
+ before do
725
+ connection.connect!
726
+ end
727
+
728
+ it 'uses the connect_timeout for the address' do
729
+ expect(connection.address.send(:connect_timeout)).to eq(3)
730
+ end
731
+
732
+ it 'does not use a socket_timeout' do
733
+ expect(connection.send(:socket).timeout).to be(nil)
734
+ end
735
+ end
736
+ end
737
+
738
+ context 'when a connect_timeout is not in the options' do
739
+
740
+ context 'when a socket_timeout is in the options' do
741
+
742
+ let(:options) do
743
+ TEST_OPTIONS.merge(connect_timeout: nil, socket_timeout: 5)
744
+ end
745
+
746
+ before do
747
+ connection.connect!
748
+ end
749
+
750
+ it 'uses the default connect_timeout for the address' do
751
+ expect(connection.address.send(:connect_timeout)).to eq(10)
752
+ end
753
+
754
+ it 'uses the socket_timeout' do
755
+ expect(connection.send(:socket).timeout).to eq(5)
756
+ end
757
+ end
758
+
759
+ context 'when a socket_timeout is not in the options' do
760
+
761
+ let(:options) do
762
+ TEST_OPTIONS.merge(connect_timeout: nil, socket_timeout: nil)
763
+ end
764
+
765
+ before do
766
+ connection.connect!
767
+ end
768
+
769
+ it 'uses the default connect_timeout for the address' do
770
+ expect(connection.address.send(:connect_timeout)).to eq(10)
771
+ end
772
+
773
+ it 'does not use a socket_timeout' do
774
+ expect(connection.send(:socket).timeout).to be(nil)
775
+ end
776
+ end
777
+ end
778
+ end
673
779
  end
@@ -23,6 +23,7 @@ describe Mongo::Server::Description do
23
23
  'maxWireVersion' => 2,
24
24
  'minWireVersion' => 0,
25
25
  'localTime' => Time.now,
26
+ 'lastWrite' => { 'lastWriteDate' => Time.now },
26
27
  'ok' => 1
27
28
  }
28
29
  end
@@ -838,7 +839,10 @@ describe Mongo::Server::Description do
838
839
  end
839
840
 
840
841
  let(:other) do
841
- described_class.new(address, replica.merge('localTime' => 1))
842
+ described_class.new(address, replica.merge(
843
+ 'localTime' => 1,
844
+ 'lastWrite' => { 'lastWriteDate' => 1 }
845
+ ))
842
846
  end
843
847
 
844
848
  it 'excludes certain fields' do
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongo::Server::Monitor::Connection do
4
+
5
+ let(:client) do
6
+ authorized_client.with(options)
7
+ end
8
+
9
+ let(:address) do
10
+ client.cluster.next_primary.address
11
+ end
12
+
13
+ let(:cluster) do
14
+ double('cluster').tap do |cl|
15
+ allow(cl).to receive(:topology).and_return(double('topology'))
16
+ allow(cl).to receive(:app_metadata).and_return(Mongo::Cluster::AppMetadata.new(authorized_client.cluster))
17
+ end
18
+ end
19
+
20
+ let(:server) do
21
+ Mongo::Server.new(address,
22
+ cluster,
23
+ Mongo::Monitoring.new(monitoring: false),
24
+ Mongo::Event::Listeners.new, options)
25
+ end
26
+
27
+ let(:connection) do
28
+ server.monitor.connection
29
+ end
30
+
31
+ after do
32
+ client.close
33
+ end
34
+
35
+ context 'when a connect_timeout is in the options' do
36
+
37
+ context 'when a socket_timeout is in the options' do
38
+
39
+ let(:options) do
40
+ TEST_OPTIONS.merge(connect_timeout: 3, socket_timeout: 5)
41
+ end
42
+
43
+ before do
44
+ connection.connect!
45
+ end
46
+
47
+ it 'uses the connect_timeout for the address' do
48
+ expect(connection.address.send(:connect_timeout)).to eq(3)
49
+ end
50
+
51
+ it 'uses the connect_timeout as the socket_timeout' do
52
+ expect(connection.send(:socket).timeout).to eq(3)
53
+ end
54
+ end
55
+
56
+ context 'when a socket_timeout is not in the options' do
57
+
58
+ let(:options) do
59
+ TEST_OPTIONS.merge(connect_timeout: 3, socket_timeout: nil)
60
+ end
61
+
62
+ before do
63
+ connection.connect!
64
+ end
65
+
66
+ it 'uses the connect_timeout for the address' do
67
+ expect(connection.address.send(:connect_timeout)).to eq(3)
68
+ end
69
+
70
+ it 'uses the connect_timeout as the socket_timeout' do
71
+ expect(connection.send(:socket).timeout).to eq(3)
72
+ end
73
+ end
74
+ end
75
+
76
+ context 'when a connect_timeout is not in the options' do
77
+
78
+ context 'when a socket_timeout is in the options' do
79
+
80
+ let(:options) do
81
+ TEST_OPTIONS.merge(connect_timeout: nil, socket_timeout: 5)
82
+ end
83
+
84
+ before do
85
+ connection.connect!
86
+ end
87
+
88
+ it 'uses the default connect_timeout for the address' do
89
+ expect(connection.address.send(:connect_timeout)).to eq(10)
90
+ end
91
+
92
+ it 'uses the connect_timeout as the socket_timeout' do
93
+ expect(connection.send(:socket).timeout).to eq(10)
94
+ end
95
+ end
96
+
97
+ context 'when a socket_timeout is not in the options' do
98
+
99
+ let(:options) do
100
+ TEST_OPTIONS.merge(connect_timeout: nil, socket_timeout: nil)
101
+ end
102
+
103
+ before do
104
+ connection.connect!
105
+ end
106
+
107
+ it 'uses the default connect_timeout for the address' do
108
+ expect(connection.address.send(:connect_timeout)).to eq(10)
109
+ end
110
+
111
+ it 'uses the connect_timeout as the socket_timeout' do
112
+ expect(connection.send(:socket).timeout).to eq(10)
113
+ end
114
+ end
115
+ end
116
+ end
@@ -2,22 +2,24 @@ require 'spec_helper'
2
2
 
3
3
  describe Mongo::Socket::SSL, if: running_ssl? do
4
4
 
5
- let(:family) do
6
- resolver = default_address.instance_variable_get(:@resolver)
7
- Mongo::Address::FAMILY_MAP.key(resolver.class)
5
+ let(:address) do
6
+ default_address
7
+ end
8
+
9
+ let(:resolver) do
10
+ address.instance_variable_get(:@resolver)
11
+ end
12
+
13
+ let(:socket_timeout) do
14
+ 1
8
15
  end
9
16
 
10
17
  let(:socket) do
11
- described_class.new(*default_address.to_s.split(":"), default_address.host, 5, family, options)
18
+ resolver.socket(socket_timeout, options)
12
19
  end
13
20
 
14
21
  let(:options) do
15
- {
16
- :ssl => true,
17
- :ssl_cert => CLIENT_CERT_PEM,
18
- :ssl_key => CLIENT_KEY_PEM,
19
- :ssl_verify => false
20
- }
22
+ SSL_OPTIONS
21
23
  end
22
24
 
23
25
  let (:key_string) do
@@ -276,7 +278,7 @@ describe Mongo::Socket::SSL, if: running_ssl? do
276
278
  end
277
279
  end
278
280
 
279
- context 'when ruby version is < 2.4.1', if: RUBY_VERSION < '2.4.1' do
281
+ context 'when ruby version is < 2.4.1', if: (RUBY_VERSION < '2.4.1' && running_ssl?) do
280
282
 
281
283
  context 'when a key is passed, but it is not of the right type' do
282
284
 
@@ -300,7 +302,7 @@ describe Mongo::Socket::SSL, if: running_ssl? do
300
302
 
301
303
  # Note that as of MRI 2.4, Creating a socket with the wrong key type raises
302
304
  # a NoMethodError because #private? is attempted to be called on the key.
303
- context 'when ruby version is >= 2.4.1', if: RUBY_VERSION >= '2.4.1' do
305
+ context 'when ruby version is >= 2.4.1', if: (RUBY_VERSION >= '2.4.1' && running_ssl?) do
304
306
 
305
307
  context 'when a key is passed, but it is not of the right type' do
306
308
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2016 MongoDB, Inc.
1
+ # Copyright (C) 2009-2017 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -79,7 +79,9 @@ BASE_OPTIONS = {
79
79
  max_pool_size: 1,
80
80
  write: WRITE_CONCERN,
81
81
  heartbeat_frequency: 20,
82
- max_read_retries: 5
82
+ max_read_retries: 5,
83
+ wait_queue_timeout: 2,
84
+ connect_timeout: 3
83
85
  }
84
86
 
85
87
  # Options for test suite clients.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2016 MongoDB, Inc.
1
+ # Copyright (C) 2014-2017 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2016 MongoDB, Inc.
1
+ # Copyright (C) 2014-2017 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -167,6 +167,14 @@ tests:
167
167
  hosts: ~
168
168
  auth: ~
169
169
  options: ~
170
+ -
171
+ description: "Username with password containing an unescaped colon"
172
+ uri: "mongodb://alice:foo:bar@127.0.0.1"
173
+ valid: false
174
+ warning: ~
175
+ hosts: ~
176
+ auth: ~
177
+ options: ~
170
178
  -
171
179
  description: "Username containing an unescaped at-sign"
172
180
  uri: "mongodb://alice@@127.0.0.1"
@@ -183,6 +191,30 @@ tests:
183
191
  hosts: ~
184
192
  auth: ~
185
193
  options: ~
194
+ -
195
+ description: "Username containing an unescaped slash"
196
+ uri: "mongodb://alice/@127.0.0.1/db"
197
+ valid: false
198
+ warning: ~
199
+ hosts: ~
200
+ auth: ~
201
+ options: ~
202
+ -
203
+ description: "Username containing unescaped slash with password"
204
+ uri: "mongodb://alice/bob:foo@127.0.0.1/db"
205
+ valid: false
206
+ warning: ~
207
+ hosts: ~
208
+ auth: ~
209
+ options: ~
210
+ -
211
+ description: "Username with password containing an unescaped slash"
212
+ uri: "mongodb://alice:foo/bar@127.0.0.1/db"
213
+ valid: false
214
+ warning: ~
215
+ hosts: ~
216
+ auth: ~
217
+ options: ~
186
218
  -
187
219
  description: "Host with unescaped slash"
188
220
  uri: "mongodb:///tmp/mongodb-27017.sock/"