mongo 2.13.3 → 2.14.0.rc1

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 (197) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/mongo/address/ipv4.rb +1 -1
  4. data/lib/mongo/address/ipv6.rb +1 -1
  5. data/lib/mongo/address.rb +1 -1
  6. data/lib/mongo/bulk_write.rb +17 -0
  7. data/lib/mongo/caching_cursor.rb +74 -0
  8. data/lib/mongo/client.rb +47 -8
  9. data/lib/mongo/cluster/topology/single.rb +1 -1
  10. data/lib/mongo/cluster.rb +3 -3
  11. data/lib/mongo/collection/view/aggregation.rb +25 -4
  12. data/lib/mongo/collection/view/builder/find_command.rb +38 -18
  13. data/lib/mongo/collection/view/explainable.rb +27 -8
  14. data/lib/mongo/collection/view/iterable.rb +72 -12
  15. data/lib/mongo/collection/view/readable.rb +12 -2
  16. data/lib/mongo/collection/view/writable.rb +15 -1
  17. data/lib/mongo/collection/view.rb +24 -20
  18. data/lib/mongo/collection.rb +26 -2
  19. data/lib/mongo/crypt/encryption_io.rb +6 -6
  20. data/lib/mongo/cursor.rb +1 -0
  21. data/lib/mongo/database/view.rb +1 -1
  22. data/lib/mongo/database.rb +8 -14
  23. data/lib/mongo/error/invalid_read_concern.rb +28 -0
  24. data/lib/mongo/error/server_certificate_revoked.rb +22 -0
  25. data/lib/mongo/error/unsupported_option.rb +14 -12
  26. data/lib/mongo/error.rb +2 -0
  27. data/lib/mongo/grid/fs_bucket.rb +37 -37
  28. data/lib/mongo/lint.rb +2 -1
  29. data/lib/mongo/logger.rb +3 -3
  30. data/lib/mongo/operation/aggregate/result.rb +9 -8
  31. data/lib/mongo/operation/collections_info/command.rb +0 -5
  32. data/lib/mongo/operation/collections_info/result.rb +3 -16
  33. data/lib/mongo/operation/delete/bulk_result.rb +2 -0
  34. data/lib/mongo/operation/delete/result.rb +3 -0
  35. data/lib/mongo/operation/explain/command.rb +4 -0
  36. data/lib/mongo/operation/explain/legacy.rb +4 -0
  37. data/lib/mongo/operation/explain/op_msg.rb +6 -0
  38. data/lib/mongo/operation/explain/result.rb +3 -0
  39. data/lib/mongo/operation/find/legacy/result.rb +2 -0
  40. data/lib/mongo/operation/find/result.rb +3 -0
  41. data/lib/mongo/operation/get_more/result.rb +3 -0
  42. data/lib/mongo/operation/indexes/result.rb +5 -0
  43. data/lib/mongo/operation/insert/bulk_result.rb +5 -0
  44. data/lib/mongo/operation/insert/result.rb +5 -0
  45. data/lib/mongo/operation/list_collections/result.rb +5 -0
  46. data/lib/mongo/operation/map_reduce/result.rb +10 -0
  47. data/lib/mongo/operation/parallel_scan/command.rb +2 -1
  48. data/lib/mongo/operation/parallel_scan/result.rb +4 -0
  49. data/lib/mongo/operation/result.rb +35 -6
  50. data/lib/mongo/operation/shared/bypass_document_validation.rb +1 -0
  51. data/lib/mongo/operation/shared/causal_consistency_supported.rb +1 -0
  52. data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +2 -0
  53. data/lib/mongo/operation/shared/executable.rb +1 -0
  54. data/lib/mongo/operation/shared/idable.rb +2 -1
  55. data/lib/mongo/operation/shared/limited.rb +1 -0
  56. data/lib/mongo/operation/shared/object_id_generator.rb +1 -0
  57. data/lib/mongo/operation/shared/read_preference_supported.rb +36 -38
  58. data/lib/mongo/operation/shared/result/aggregatable.rb +1 -0
  59. data/lib/mongo/operation/shared/sessions_supported.rb +3 -3
  60. data/lib/mongo/operation/shared/specifiable.rb +1 -0
  61. data/lib/mongo/operation/shared/write.rb +1 -0
  62. data/lib/mongo/operation/shared/write_concern_supported.rb +1 -0
  63. data/lib/mongo/operation/update/legacy/result.rb +7 -0
  64. data/lib/mongo/operation/update/result.rb +8 -0
  65. data/lib/mongo/operation/users_info/result.rb +3 -0
  66. data/lib/mongo/operation.rb +2 -0
  67. data/lib/mongo/protocol/msg.rb +2 -2
  68. data/lib/mongo/protocol/query.rb +11 -11
  69. data/lib/mongo/query_cache.rb +242 -0
  70. data/lib/mongo/retryable.rb +8 -1
  71. data/lib/mongo/server/connection_common.rb +2 -2
  72. data/lib/mongo/server/connection_pool.rb +3 -0
  73. data/lib/mongo/server/monitor/connection.rb +3 -3
  74. data/lib/mongo/server/monitor.rb +1 -1
  75. data/lib/mongo/server/pending_connection.rb +2 -2
  76. data/lib/mongo/server/push_monitor.rb +1 -1
  77. data/lib/mongo/server.rb +5 -1
  78. data/lib/mongo/server_selector/base.rb +5 -1
  79. data/lib/mongo/server_selector/secondary_preferred.rb +7 -2
  80. data/lib/mongo/session.rb +3 -0
  81. data/lib/mongo/socket/ocsp_cache.rb +97 -0
  82. data/lib/mongo/socket/ocsp_verifier.rb +368 -0
  83. data/lib/mongo/socket/ssl.rb +45 -24
  84. data/lib/mongo/socket.rb +6 -4
  85. data/lib/mongo/srv/monitor.rb +7 -13
  86. data/lib/mongo/srv/resolver.rb +14 -10
  87. data/lib/mongo/timeout.rb +2 -0
  88. data/lib/mongo/uri/options_mapper.rb +582 -0
  89. data/lib/mongo/uri/srv_protocol.rb +3 -2
  90. data/lib/mongo/uri.rb +21 -390
  91. data/lib/mongo/utils.rb +12 -1
  92. data/lib/mongo/version.rb +1 -1
  93. data/lib/mongo.rb +9 -0
  94. data/spec/NOTES.aws-auth.md +12 -7
  95. data/spec/README.md +56 -1
  96. data/spec/integration/bson_symbol_spec.rb +2 -4
  97. data/spec/integration/bulk_write_spec.rb +48 -0
  98. data/spec/integration/client_authentication_options_spec.rb +55 -28
  99. data/spec/integration/connection_pool_populator_spec.rb +3 -1
  100. data/spec/integration/cursor_reaping_spec.rb +53 -17
  101. data/spec/integration/ocsp_connectivity_spec.rb +26 -0
  102. data/spec/integration/ocsp_verifier_cache_spec.rb +188 -0
  103. data/spec/integration/ocsp_verifier_spec.rb +334 -0
  104. data/spec/integration/query_cache_spec.rb +1045 -0
  105. data/spec/integration/query_cache_transactions_spec.rb +179 -0
  106. data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -0
  107. data/spec/integration/retryable_writes/shared/performs_legacy_retries.rb +2 -0
  108. data/spec/integration/sdam_error_handling_spec.rb +69 -18
  109. data/spec/integration/sdam_events_spec.rb +7 -8
  110. data/spec/integration/server_selection_spec.rb +36 -0
  111. data/spec/integration/srv_monitoring_spec.rb +38 -3
  112. data/spec/integration/srv_spec.rb +56 -0
  113. data/spec/lite_spec_helper.rb +4 -2
  114. data/spec/mongo/address_spec.rb +1 -1
  115. data/spec/mongo/caching_cursor_spec.rb +70 -0
  116. data/spec/mongo/client_construction_spec.rb +54 -1
  117. data/spec/mongo/client_encryption_spec.rb +10 -16
  118. data/spec/mongo/client_spec.rb +40 -0
  119. data/spec/mongo/cluster/topology/single_spec.rb +14 -5
  120. data/spec/mongo/cluster_spec.rb +3 -0
  121. data/spec/mongo/collection/view/explainable_spec.rb +87 -4
  122. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -0
  123. data/spec/mongo/collection_spec.rb +60 -0
  124. data/spec/mongo/crypt/auto_decryption_context_spec.rb +1 -1
  125. data/spec/mongo/crypt/auto_encryption_context_spec.rb +1 -1
  126. data/spec/mongo/crypt/data_key_context_spec.rb +1 -1
  127. data/spec/mongo/crypt/explicit_decryption_context_spec.rb +1 -1
  128. data/spec/mongo/crypt/explicit_encryption_context_spec.rb +1 -1
  129. data/spec/mongo/database_spec.rb +44 -64
  130. data/spec/mongo/error/no_server_available_spec.rb +1 -1
  131. data/spec/mongo/index/view_spec.rb +2 -4
  132. data/spec/mongo/logger_spec.rb +13 -11
  133. data/spec/mongo/operation/read_preference_legacy_spec.rb +19 -9
  134. data/spec/mongo/operation/read_preference_op_msg_spec.rb +3 -3
  135. data/spec/mongo/query_cache_spec.rb +279 -0
  136. data/spec/mongo/server/app_metadata_shared.rb +7 -33
  137. data/spec/mongo/server/connection_pool_spec.rb +7 -3
  138. data/spec/mongo/server/connection_spec.rb +14 -7
  139. data/spec/mongo/server_selector/secondary_preferred_spec.rb +6 -6
  140. data/spec/mongo/socket/ssl_spec.rb +1 -1
  141. data/spec/mongo/socket_spec.rb +1 -1
  142. data/spec/mongo/uri/srv_protocol_spec.rb +64 -33
  143. data/spec/mongo/uri_option_parsing_spec.rb +11 -11
  144. data/spec/mongo/uri_spec.rb +68 -41
  145. data/spec/mongo/utils_spec.rb +39 -0
  146. data/spec/runners/auth.rb +3 -0
  147. data/spec/runners/connection_string.rb +35 -124
  148. data/spec/runners/transactions/operation.rb +2 -13
  149. data/spec/spec_tests/cmap_spec.rb +7 -3
  150. data/spec/spec_tests/data/change_streams/change-streams-errors.yml +0 -1
  151. data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
  152. data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +6 -2
  153. data/spec/spec_tests/data/cmap/pool-create-min-size.yml +3 -0
  154. data/spec/spec_tests/data/connection_string/valid-warnings.yml +24 -0
  155. data/spec/spec_tests/data/sdam_monitoring/discovered_standalone.yml +1 -3
  156. data/spec/spec_tests/data/sdam_monitoring/standalone.yml +2 -2
  157. data/spec/spec_tests/data/sdam_monitoring/standalone_repeated.yml +2 -2
  158. data/spec/spec_tests/data/sdam_monitoring/standalone_suppress_equal_description_changes.yml +2 -2
  159. data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +2 -2
  160. data/spec/spec_tests/data/uri_options/auth-options.yml +25 -0
  161. data/spec/spec_tests/data/uri_options/compression-options.yml +6 -3
  162. data/spec/spec_tests/data/uri_options/read-preference-options.yml +24 -0
  163. data/spec/spec_tests/data/uri_options/ruby-connection-options.yml +1 -0
  164. data/spec/spec_tests/data/uri_options/tls-options.yml +160 -4
  165. data/spec/spec_tests/dns_seedlist_discovery_spec.rb +9 -1
  166. data/spec/spec_tests/uri_options_spec.rb +31 -33
  167. data/spec/support/certificates/atlas-ocsp-ca.crt +28 -0
  168. data/spec/support/certificates/atlas-ocsp.crt +41 -0
  169. data/spec/support/client_registry.rb +4 -8
  170. data/spec/support/client_registry_macros.rb +4 -4
  171. data/spec/support/common_shortcuts.rb +45 -0
  172. data/spec/support/constraints.rb +23 -0
  173. data/spec/support/lite_constraints.rb +24 -0
  174. data/spec/support/matchers.rb +16 -0
  175. data/spec/support/ocsp +1 -0
  176. data/spec/support/session_registry.rb +52 -0
  177. data/spec/support/spec_config.rb +22 -12
  178. data/spec/support/spec_setup.rb +38 -48
  179. data/spec/support/utils.rb +19 -1
  180. data.tar.gz.sig +1 -3
  181. metadata +938 -933
  182. metadata.gz.sig +0 -0
  183. data/spec/integration/secondary_reads_spec.rb +0 -102
  184. data/spec/shared/LICENSE +0 -20
  185. data/spec/shared/bin/get-mongodb-download-url +0 -17
  186. data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
  187. data/spec/shared/lib/mrss/cluster_config.rb +0 -221
  188. data/spec/shared/lib/mrss/constraints.rb +0 -346
  189. data/spec/shared/lib/mrss/docker_runner.rb +0 -265
  190. data/spec/shared/lib/mrss/lite_constraints.rb +0 -191
  191. data/spec/shared/lib/mrss/server_version_registry.rb +0 -115
  192. data/spec/shared/lib/mrss/spec_organizer.rb +0 -152
  193. data/spec/shared/lib/mrss/utils.rb +0 -15
  194. data/spec/shared/share/Dockerfile.erb +0 -231
  195. data/spec/shared/shlib/distro.sh +0 -73
  196. data/spec/shared/shlib/server.sh +0 -290
  197. data/spec/shared/shlib/set_env.sh +0 -128
@@ -175,13 +175,13 @@ describe Mongo::Operation::SessionsSupported do
175
175
  let(:tag_sets) { nil }
176
176
 
177
177
  context 'without tag_sets specified' do
178
- it_behaves_like 'adds read preference'
178
+ it_behaves_like 'does not modify selector'
179
179
  end
180
180
 
181
181
  context 'with empty tag_sets' do
182
182
  let(:tag_sets) { [] }
183
183
 
184
- it_behaves_like 'adds read preference'
184
+ it_behaves_like 'does not modify selector'
185
185
  end
186
186
 
187
187
  context 'with tag_sets specified' do
@@ -256,7 +256,7 @@ describe Mongo::Operation::SessionsSupported do
256
256
  let(:hedge) { nil }
257
257
 
258
258
  context 'when tag_sets and hedge are not specified' do
259
- it_behaves_like 'adds read preference'
259
+ it_behaves_like 'does not modify selector'
260
260
  end
261
261
 
262
262
  context 'when tag_sets are specified' do
@@ -0,0 +1,279 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongo::QueryCache do
4
+
5
+ around do |spec|
6
+ Mongo::QueryCache.clear
7
+ Mongo::QueryCache.cache { spec.run }
8
+ end
9
+
10
+ before do
11
+ authorized_collection.delete_many
12
+ end
13
+
14
+ let(:subscriber) { EventSubscriber.new }
15
+
16
+ let(:client) do
17
+ authorized_client.tap do |client|
18
+ client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
19
+ end
20
+ end
21
+
22
+ let(:authorized_collection) { client['collection_spec'] }
23
+
24
+ let(:events) do
25
+ subscriber.command_started_events('find')
26
+ end
27
+
28
+ describe '#enabled' do
29
+
30
+ context 'when query cache is disabled' do
31
+
32
+ before do
33
+ Mongo::QueryCache.enabled = false
34
+ end
35
+
36
+ it 'disables the query cache' do
37
+ expect(Mongo::QueryCache.enabled?).to be(false)
38
+ end
39
+ end
40
+
41
+ context 'when query cache is enabled' do
42
+
43
+ before do
44
+ Mongo::QueryCache.enabled = true
45
+ end
46
+
47
+ it 'enables the query cache' do
48
+ expect(Mongo::QueryCache.enabled?).to be(true)
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '#cache' do
54
+
55
+ before do
56
+ Mongo::QueryCache.enabled = false
57
+ end
58
+
59
+ it 'enables the query cache inside the block' do
60
+ Mongo::QueryCache.cache do
61
+ expect(Mongo::QueryCache.enabled?).to be(true)
62
+ end
63
+ expect(Mongo::QueryCache.enabled?).to be(false)
64
+ end
65
+ end
66
+
67
+ describe '#uncached' do
68
+
69
+ it 'disables the query cache inside the block' do
70
+ Mongo::QueryCache.uncached do
71
+ expect(Mongo::QueryCache.enabled?).to be(false)
72
+ end
73
+ expect(Mongo::QueryCache.enabled?).to be(true)
74
+ end
75
+ end
76
+
77
+ describe '#cache_table' do
78
+
79
+ before do
80
+ authorized_collection.insert_one({ name: 'testing' })
81
+ authorized_collection.find(name: 'testing').to_a
82
+ end
83
+
84
+ it 'gets the cached query' do
85
+ expect(Mongo::QueryCache.send(:cache_table).length).to eq(1)
86
+ authorized_collection.find(name: 'testing').to_a
87
+ expect(events.length).to eq(1)
88
+ end
89
+ end
90
+
91
+ describe '#clear' do
92
+
93
+ before do
94
+ authorized_collection.insert_one({ name: 'testing' })
95
+ authorized_collection.find(name: 'testing').to_a
96
+ end
97
+
98
+ it 'clears the cache' do
99
+ expect(Mongo::QueryCache.send(:cache_table).length).to eq(1)
100
+ Mongo::QueryCache.clear
101
+ expect(Mongo::QueryCache.send(:cache_table).length).to eq(0)
102
+ end
103
+ end
104
+
105
+ describe '#set' do
106
+ let(:caching_cursor) { double("Mongo::CachingCursor") }
107
+ let(:namespace) { 'db.coll' }
108
+ let(:selector) { { field: 'value' } }
109
+ let(:skip) { 5 }
110
+ let(:sort) { { field: 'asc' } }
111
+ let(:limit) { 5 }
112
+ let(:projection) { { field: 1 } }
113
+ let(:collation) { { locale: 'fr_CA' } }
114
+ let(:read_concern) { { level: :majority } }
115
+ let(:read_preference) { { mode: :secondary } }
116
+
117
+ let(:options) do
118
+ {
119
+ namespace: namespace,
120
+ selector: selector,
121
+ skip: skip,
122
+ sort: sort,
123
+ limit: limit,
124
+ projection: projection,
125
+ collation: collation,
126
+ read_concern: read_concern,
127
+ read_preference: read_preference,
128
+ }
129
+ end
130
+
131
+ it 'stores the cursor at the correct key' do
132
+ Mongo::QueryCache.set(caching_cursor, **options)
133
+ expect(Mongo::QueryCache.send(:cache_table)[namespace][[namespace, selector, skip, sort, projection, collation, read_concern, read_preference]]).to eq(caching_cursor)
134
+ end
135
+ end
136
+
137
+ describe '#get' do
138
+ let(:view) { double("Mongo::Collection::View") }
139
+ let(:result) { double("Mongo::Operation::Result") }
140
+ let(:server) { double("Mongo::Server") }
141
+ let(:caching_cursor) { Mongo::CachingCursor.new(view, result, server) }
142
+
143
+ let(:options) do
144
+ {
145
+ namespace: 'db.coll',
146
+ selector: { field: 'value' },
147
+ }
148
+ end
149
+
150
+ before do
151
+ allow(result).to receive(:cursor_id) { 0 }
152
+ allow(view).to receive(:limit) { nil }
153
+ end
154
+
155
+ context 'when there is no entry in the cache' do
156
+ it 'returns nil' do
157
+ expect(Mongo::QueryCache.get(**options)).to be_nil
158
+ end
159
+ end
160
+
161
+ context 'when there is an entry in the cache' do
162
+ before do
163
+ Mongo::QueryCache.set(caching_cursor, **caching_cursor_options)
164
+ end
165
+
166
+ context 'when that entry has no limit' do
167
+ let(:caching_cursor_options) do
168
+ {
169
+ namespace: 'db.coll',
170
+ selector: { field: 'value' },
171
+ }
172
+ end
173
+
174
+ let(:query_options) do
175
+ caching_cursor_options.merge(limit: limit)
176
+ end
177
+
178
+ context 'when the query has a limit' do
179
+ let(:limit) { 5 }
180
+
181
+ it 'returns the caching cursor' do
182
+ expect(Mongo::QueryCache.get(**query_options)).to eq(caching_cursor)
183
+ end
184
+ end
185
+
186
+ context 'when the query has no limit' do
187
+ let(:limit) { nil }
188
+
189
+ it 'returns the caching cursor' do
190
+ expect(Mongo::QueryCache.get(**query_options)).to eq(caching_cursor)
191
+ end
192
+ end
193
+ end
194
+
195
+ context 'when that entry has a limit' do
196
+ let(:caching_cursor_options) do
197
+ {
198
+ namespace: 'db.coll',
199
+ selector: { field: 'value' },
200
+ limit: 5,
201
+ }
202
+ end
203
+
204
+ let(:query_options) do
205
+ caching_cursor_options.merge(limit: limit)
206
+ end
207
+
208
+ before do
209
+ allow(view).to receive(:limit) { 5 }
210
+ end
211
+
212
+ context 'and the new query has a smaller limit' do
213
+ let(:limit) { 4 }
214
+
215
+ it 'returns the caching cursor' do
216
+ expect(Mongo::QueryCache.get(**query_options)).to eq(caching_cursor)
217
+ end
218
+ end
219
+
220
+ context 'and the new query has a larger limit' do
221
+ let(:limit) { 6 }
222
+
223
+ it 'returns nil' do
224
+ expect(Mongo::QueryCache.get(**query_options)).to be_nil
225
+ end
226
+ end
227
+
228
+ context 'and the new query has the same limit' do
229
+ let(:limit) { 5 }
230
+
231
+ it 'returns the caching cursor' do
232
+ expect(Mongo::QueryCache.get(**query_options)).to eq(caching_cursor)
233
+ end
234
+ end
235
+
236
+ context 'and the new query has no limit' do
237
+ let(:limit) { nil }
238
+
239
+ it 'returns nil' do
240
+ expect(Mongo::QueryCache.get(**query_options)).to be_nil
241
+ end
242
+ end
243
+ end
244
+ end
245
+ end
246
+
247
+ describe '#clear_namespace' do
248
+ let(:caching_cursor) { double("Mongo::CachingCursor") }
249
+ let(:namespace1) { 'db.coll' }
250
+ let(:namespace2) { 'db.coll2' }
251
+ let(:namespace3) { 'db.coll3' }
252
+ let(:selector) { { field: 'value' } }
253
+
254
+ before do
255
+ Mongo::QueryCache.set(caching_cursor, namespace: namespace1, selector: selector)
256
+ Mongo::QueryCache.set(caching_cursor, namespace: namespace2, selector: selector)
257
+ Mongo::QueryCache.set(caching_cursor, namespace: namespace3, selector: selector, multi_collection: true)
258
+ end
259
+
260
+ it 'returns nil' do
261
+ expect(Mongo::QueryCache.clear_namespace(namespace1)).to be_nil
262
+ end
263
+
264
+ it 'clears the specified namespace in the query cache' do
265
+ Mongo::QueryCache.clear_namespace(namespace1)
266
+ expect(Mongo::QueryCache.send(:cache_table)[namespace1]).to be_nil
267
+ end
268
+
269
+ it 'does not clear other namespaces in the query cache' do
270
+ Mongo::QueryCache.clear_namespace(namespace1)
271
+ expect(Mongo::QueryCache.send(:cache_table)[namespace2]).not_to be_nil
272
+ end
273
+
274
+ it 'clears the nil namespace' do
275
+ Mongo::QueryCache.clear_namespace(namespace1)
276
+ expect(Mongo::QueryCache.send(:cache_table)[nil]).to be_nil
277
+ end
278
+ end
279
+ end
@@ -8,40 +8,14 @@ shared_examples 'app metadata document' do
8
8
  document[:client][:driver][:version].should == Mongo::VERSION
9
9
  end
10
10
 
11
- context 'linux' do
12
- before(:all) do
13
- unless SpecConfig.instance.linux?
14
- skip "Linux required, we have #{RbConfig::CONFIG['host_os']}"
15
- end
16
- end
17
-
18
- it 'includes operating system information' do
19
- document[:client][:os][:type].should == 'linux'
20
- if BSON::Environment.jruby? || RUBY_VERSION >= '3.0'
21
- document[:client][:os][:name].should == 'linux'
22
- else
23
- document[:client][:os][:name].should == 'linux-gnu'
24
- end
25
- document[:client][:os][:architecture].should == 'x86_64'
26
- end
27
- end
28
-
29
- context 'macos' do
30
- before(:all) do
31
- unless SpecConfig.instance.macos?
32
- skip "MacOS required, we have #{RbConfig::CONFIG['host_os']}"
33
- end
34
- end
35
-
36
- it 'includes operating system information' do
37
- document[:client][:os][:type].should == 'darwin'
38
- if BSON::Environment.jruby?
39
- document[:client][:os][:name].should == 'darwin'
40
- else
41
- document[:client][:os][:name].should =~ /darwin\d+/
42
- end
43
- document[:client][:os][:architecture].should == 'x86_64'
11
+ it 'includes operating system information' do
12
+ document[:client][:os][:type].should == 'linux'
13
+ if BSON::Environment.jruby?
14
+ document[:client][:os][:name].should == 'linux'
15
+ else
16
+ document[:client][:os][:name].should == 'linux-gnu'
44
17
  end
18
+ document[:client][:os][:architecture].should == 'x86_64'
45
19
  end
46
20
 
47
21
  context 'mri' do
@@ -5,9 +5,13 @@ describe Mongo::Server::ConnectionPool do
5
5
  let(:options) { {} }
6
6
 
7
7
  let(:server_options) do
8
- SpecConfig.instance.ssl_options.merge(SpecConfig.instance.compressor_options)
9
- .merge(SpecConfig.instance.retry_writes_options).merge(SpecConfig.instance.auth_options)
10
- .merge(options)
8
+ Mongo::Utils.shallow_symbolize_keys(Mongo::Client.canonicalize_ruby_options(
9
+ SpecConfig.instance.all_test_options,
10
+ )).tap do |opts|
11
+ opts.delete(:min_pool_size)
12
+ opts.delete(:max_pool_size)
13
+ opts.delete(:wait_queue_timeout)
14
+ end.update(options)
11
15
  end
12
16
 
13
17
  let(:address) do
@@ -158,6 +158,8 @@ describe Mongo::Server::Connection do
158
158
  end
159
159
 
160
160
  shared_examples_for 'logs a warning' do
161
+ require_warning_clean
162
+
161
163
  it 'logs a warning' do
162
164
  messages = []
163
165
  expect(Mongo::Logger.logger).to receive(:warn) do |msg|
@@ -172,6 +174,8 @@ describe Mongo::Server::Connection do
172
174
  end
173
175
 
174
176
  shared_examples_for 'adds server diagnostics' do
177
+ require_warning_clean
178
+
175
179
  it 'adds server diagnostics' do
176
180
  messages = []
177
181
  expect(Mongo::Logger.logger).to receive(:warn) do |msg|
@@ -248,8 +252,9 @@ describe Mongo::Server::Connection do
248
252
  require_auth
249
253
 
250
254
  let(:server_options) do
251
- SpecConfig.instance.test_options.merge(monitoring_io: false).
252
- merge(SpecConfig.instance.auth_options)
255
+ Mongo::Client.canonicalize_ruby_options(
256
+ SpecConfig.instance.all_test_options,
257
+ ).update(monitoring_io: false)
253
258
  end
254
259
 
255
260
  let(:exception) do
@@ -589,10 +594,12 @@ describe Mongo::Server::Connection do
589
594
  server,
590
595
  SpecConfig.instance.test_options.merge(
591
596
  :database => SpecConfig.instance.test_user.database,
592
- ).merge(SpecConfig.instance.credentials_or_external_user(
593
- user: SpecConfig.instance.test_user.name,
594
- password: SpecConfig.instance.test_user.password,
595
- ))
597
+ ).merge(Mongo::Utils.shallow_symbolize_keys(Mongo::Client.canonicalize_ruby_options(
598
+ SpecConfig.instance.credentials_or_external_user(
599
+ user: SpecConfig.instance.test_user.name,
600
+ password: SpecConfig.instance.test_user.password,
601
+ ),
602
+ )))
596
603
  ).tap do |connection|
597
604
  connection.connect!
598
605
  end
@@ -1099,7 +1106,7 @@ describe Mongo::Server::Connection do
1099
1106
  :user => SpecConfig.instance.test_user.name,
1100
1107
  :password => SpecConfig.instance.test_user.password,
1101
1108
  :database => SpecConfig.instance.test_db,
1102
- :auth_mech => :mongodb_cr
1109
+ :auth_mech => :mongodb_cr,
1103
1110
  )
1104
1111
  end
1105
1112
 
@@ -78,8 +78,8 @@ describe Mongo::ServerSelector::SecondaryPreferred do
78
78
 
79
79
  context 'tag sets not provided' do
80
80
 
81
- it 'returns secondaryPreferred' do
82
- selector.to_mongos.should == {mode: 'secondaryPreferred'}
81
+ it 'returns nil' do
82
+ expect(selector.to_mongos).to be_nil
83
83
  end
84
84
  end
85
85
 
@@ -89,8 +89,8 @@ describe Mongo::ServerSelector::SecondaryPreferred do
89
89
  { :mode => 'secondaryPreferred' }
90
90
  end
91
91
 
92
- it 'returns secondaryPreferred' do
93
- selector.to_mongos.should == {mode: 'secondaryPreferred'}
92
+ it 'returns nil' do
93
+ expect(selector.to_mongos).to be_nil
94
94
  end
95
95
  end
96
96
 
@@ -120,8 +120,8 @@ describe Mongo::ServerSelector::SecondaryPreferred do
120
120
  context 'hedge not provided' do
121
121
  let(:hedge) { nil }
122
122
 
123
- it 'returns secondaryPreferred' do
124
- selector.to_mongos.should == {mode: 'secondaryPreferred'}
123
+ it 'returns nil' do
124
+ expect(selector.to_mongos).to be_nil
125
125
  end
126
126
  end
127
127
 
@@ -246,7 +246,7 @@ describe Mongo::Socket::SSL, retry: 3 do
246
246
  it 'raises an error' do
247
247
  lambda do
248
248
  socket
249
- end.should raise_error(Mongo::Error::SocketError, /SSL handshake failed due to a hostname mismatch/)
249
+ end.should raise_error(Mongo::Error::SocketError, /TLS handshake failed due to a hostname mismatch/)
250
250
  end
251
251
  end
252
252
 
@@ -48,7 +48,7 @@ describe Mongo::Socket do
48
48
  socket.send(:map_exceptions) do
49
49
  raise OpenSSL::SSL::SSLError.new('Test error')
50
50
  end
51
- end.to raise_error(Mongo::Error::SocketError, 'OpenSSL::SSL::SSLError: Test error (for fake-address) (MongoDB may not be configured with SSL support)')
51
+ end.to raise_error(Mongo::Error::SocketError, 'OpenSSL::SSL::SSLError: Test error (for fake-address) (MongoDB may not be configured with TLS support)')
52
52
  end
53
53
  end
54
54
 
@@ -567,8 +567,8 @@ describe Mongo::URI::SRVProtocol do
567
567
  'readPreference=secondary&maxStalenessSeconds=89'
568
568
  end
569
569
 
570
- it 'does not raise an exception until the read preference is used' do
571
- expect(client.read_preference).to eq(BSON::Document.new(mode: :secondary, max_staleness: 89))
570
+ it 'does not raise an exception and is omitted' do
571
+ expect(client.read_preference).to eq(BSON::Document.new(mode: :secondary))
572
572
  end
573
573
  end
574
574
  end
@@ -715,83 +715,114 @@ describe Mongo::URI::SRVProtocol do
715
715
  end
716
716
  end
717
717
 
718
+ # This context exactly duplicates the same one in uri_spec.rb
718
719
  context 'auth mechanism properties provided' do
719
720
 
721
+ shared_examples 'sets options in the expected manner' do
722
+ it 'preserves case in auth mechanism properties returned from URI' do
723
+ expect(uri.uri_options[:auth_mech_properties]).to eq(expected_uri_options)
724
+ end
725
+
726
+ it 'downcases auth mechanism properties keys in client options' do
727
+ client = new_local_client_nmio(string)
728
+ expect(client.options[:auth_mech_properties]).to eq(expected_client_options)
729
+ end
730
+ end
731
+
720
732
  context 'service_name' do
721
733
  let(:options) do
722
- "authMechanismProperties=SERVICE_NAME:#{service_name}"
734
+ "authMechanismProperties=SERVICE_name:#{service_name}"
723
735
  end
724
736
 
725
737
  let(:service_name) { 'foo' }
726
- let(:expected) { Mongo::Options::Redacted.new({ service_name: service_name }) }
727
738
 
728
- it 'sets the auth mechanism properties' do
729
- expect(uri.uri_options[:auth_mech_properties]).to eq(expected)
739
+ let(:expected_uri_options) do
740
+ Mongo::Options::Redacted.new(
741
+ SERVICE_name: service_name,
742
+ )
730
743
  end
731
744
 
732
- it 'sets the options on a client created with the uri' do
733
- expect(client.options[:auth_mech_properties]).to eq(expected)
745
+ let(:expected_client_options) do
746
+ Mongo::Options::Redacted.new(
747
+ service_name: service_name,
748
+ )
734
749
  end
750
+
751
+ include_examples 'sets options in the expected manner'
735
752
  end
736
753
 
737
754
  context 'canonicalize_host_name' do
738
755
  let(:options) do
739
- "authMechanismProperties=CANONICALIZE_HOST_NAME:#{canonicalize_host_name}"
756
+ "authMechanismProperties=CANONICALIZE_HOST_name:#{canonicalize_host_name}"
740
757
  end
758
+
741
759
  let(:canonicalize_host_name) { 'true' }
742
- let(:expected) { Mongo::Options::Redacted.new({ canonicalize_host_name: true }) }
743
760
 
744
- it 'sets the auth mechanism properties' do
745
- expect(uri.uri_options[:auth_mech_properties]).to eq(expected)
761
+ let(:expected_uri_options) do
762
+ Mongo::Options::Redacted.new(
763
+ CANONICALIZE_HOST_name: true,
764
+ )
746
765
  end
747
766
 
748
- it 'sets the options on a client created with the uri' do
749
- expect(client.options[:auth_mech_properties]).to eq(expected)
767
+ let(:expected_client_options) do
768
+ Mongo::Options::Redacted.new(
769
+ canonicalize_host_name: true,
770
+ )
750
771
  end
772
+
773
+ include_examples 'sets options in the expected manner'
751
774
  end
752
775
 
753
776
  context 'service_realm' do
754
777
  let(:options) do
755
- "authMechanismProperties=SERVICE_REALM:#{service_realm}"
778
+ "authMechanismProperties=SERVICE_realm:#{service_realm}"
756
779
  end
757
780
 
758
781
  let(:service_realm) { 'dumdum' }
759
- let(:expected) { Mongo::Options::Redacted.new({ service_realm: service_realm }) }
760
782
 
761
-
762
- it 'sets the auth mechanism properties' do
763
- expect(uri.uri_options[:auth_mech_properties]).to eq(expected)
783
+ let(:expected_uri_options) do
784
+ Mongo::Options::Redacted.new(
785
+ SERVICE_realm: service_realm,
786
+ )
764
787
  end
765
788
 
766
- it 'sets the options on a client created with the uri' do
767
- expect(client.options[:auth_mech_properties]).to eq(expected)
789
+ let(:expected_client_options) do
790
+ Mongo::Options::Redacted.new(
791
+ service_realm: service_realm,
792
+ )
768
793
  end
794
+
795
+ include_examples 'sets options in the expected manner'
769
796
  end
770
797
 
771
798
  context 'multiple properties' do
772
799
  let(:options) do
773
- "authMechanismProperties=SERVICE_REALM:#{service_realm}," +
774
- "CANONICALIZE_HOST_NAME:#{canonicalize_host_name}," +
775
- "SERVICE_NAME:#{service_name}"
800
+ "authMechanismProperties=SERVICE_realm:#{service_realm}," +
801
+ "CANONICALIZE_HOST_name:#{canonicalize_host_name}," +
802
+ "SERVICE_name:#{service_name}"
776
803
  end
777
804
 
778
805
  let(:service_name) { 'foo' }
779
806
  let(:canonicalize_host_name) { 'true' }
780
807
  let(:service_realm) { 'dumdum' }
781
808
 
782
- let(:expected) do
783
- Mongo::Options::Redacted.new({ service_name: service_name,
784
- canonicalize_host_name: true,
785
- service_realm: service_realm })
809
+ let(:expected_uri_options) do
810
+ Mongo::Options::Redacted.new(
811
+ SERVICE_name: service_name,
812
+ CANONICALIZE_HOST_name: true,
813
+ SERVICE_realm: service_realm,
814
+ )
786
815
  end
787
816
 
788
- it 'sets the auth mechanism properties' do
789
- expect(uri.uri_options[:auth_mech_properties]).to eq(expected)
817
+ let(:expected_client_options) do
818
+ Mongo::Options::Redacted.new(
819
+ service_name: service_name,
820
+ canonicalize_host_name: true,
821
+ service_realm: service_realm,
822
+ )
790
823
  end
791
824
 
792
- it 'sets the options on a client created with the uri' do
793
- expect(client.options[:auth_mech_properties]).to eq(expected)
794
- end
825
+ include_examples 'sets options in the expected manner'
795
826
  end
796
827
  end
797
828