mongo 2.12.3 → 2.12.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d246db379228f5a887c2fdc21098808da28bcfba008dd6d3218475c6d00b112e
4
- data.tar.gz: 34be39488f7ce9de6746e03db0524d80815c12bcd384a488734572576f491eec
3
+ metadata.gz: c810c7a786a9400b9a55c53b59a8078ec63e57703e8cf564e5001188cd33144b
4
+ data.tar.gz: 2230cea6d335950d790fb19f414113f7115241ce105d228f7e42a06606795b5e
5
5
  SHA512:
6
- metadata.gz: 1998d33cea6ea9d43e473075b737452c5dff52d0fc7af2ef02b50fa7a56e741f26161bb475e89bba1a4fdfadd31c863b337a9c8dd26bfd5d4a21ccf43a741f7d
7
- data.tar.gz: 42aa2fc57a621849a814e2fec41a7e982927303caa4199892b970289c38a620995764c76c6848090c1d74d7af56b1b1f9c99ce12f9de44a05b3255bf510b6f3a
6
+ metadata.gz: 1c0fd06e7e5e937ddb6a2c27f98574e79cf39e71f10a41b874186478708db34bcc6c9fa0a2cf5d191bf57ef35c613fbc40a47b8fca3ee660bd7e92dbb4f4b956
7
+ data.tar.gz: 28f1e23f087f9944ba3f236d78621e48b7fe91b7c75b57e9eac44d67dbe0f345c19d6be2ec96700e36de4952126fe42997702bd018eda9a70e2c25701991853a
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/mongo/client.rb CHANGED
@@ -446,7 +446,18 @@ module Mongo
446
446
  # construction
447
447
  sdam_proc = options.delete(:sdam_proc)
448
448
 
449
- options = default_options(options).merge(options)
449
+ # For gssapi service_name, the default option is given in a hash
450
+ # (one level down from the top level).
451
+ merged_options = default_options(options)
452
+ options.each do |k, v|
453
+ default_v = merged_options[k]
454
+ if Hash === default_v
455
+ v = default_v.merge(v)
456
+ end
457
+ merged_options[k] = v
458
+ end
459
+ options = merged_options
460
+
450
461
  @options = validate_new_options!(options)
451
462
  =begin WriteConcern object support
452
463
  if @options[:write_concern].is_a?(WriteConcern::Base)
@@ -605,7 +616,7 @@ module Mongo
605
616
  #
606
617
  # @return [ BSON::Document ] The user-defined read preference.
607
618
  # The document may have the following fields:
608
- # - *:read* -- read preference specified as a symbol; valid values are
619
+ # - *:mode* -- read preference specified as a symbol; valid values are
609
620
  # *:primary*, *:primary_preferred*, *:secondary*, *:secondary_preferred*
610
621
  # and *:nearest*.
611
622
  # - *:tag_sets* -- an array of hashes.
@@ -278,8 +278,12 @@ module Mongo
278
278
  }).execute(next_primary(nil, session), client: client)
279
279
  end
280
280
  rescue Error::OperationFailure => ex
281
- raise ex unless ex.message =~ /ns not found/
282
- false
281
+ # NamespaceNotFound
282
+ if ex.code == 26 || ex.code.nil? && ex.message =~ /ns not found/
283
+ false
284
+ else
285
+ raise
286
+ end
283
287
  end
284
288
 
285
289
  # Find documents in the collection.
@@ -89,7 +89,8 @@ module Mongo
89
89
  # @since 2.1.1
90
90
  # @deprecated
91
91
  def retryable?
92
- write_retryable? || RETRY_MESSAGES.any?{ |m| message.include?(m) }
92
+ write_retryable? ||
93
+ code.nil? && RETRY_MESSAGES.any?{ |m| message.include?(m) }
93
94
  end
94
95
 
95
96
  # Whether the error is a retryable error according to the modern retryable
@@ -102,11 +103,11 @@ module Mongo
102
103
  #
103
104
  # @since 2.4.2
104
105
  def write_retryable?
105
- WRITE_RETRY_MESSAGES.any? { |m| message.include?(m) } ||
106
- write_retryable_code?
106
+ write_retryable_code? ||
107
+ code.nil? && WRITE_RETRY_MESSAGES.any? { |m| message.include?(m) }
107
108
  end
108
109
 
109
- def write_retryable_code?
110
+ private def write_retryable_code?
110
111
  if code
111
112
  WRITE_RETRY_ERRORS.any? { |e| e[:code] == code }
112
113
  else
@@ -114,7 +115,6 @@ module Mongo
114
115
  false
115
116
  end
116
117
  end
117
- private :write_retryable_code?
118
118
 
119
119
  # Error codes and code names that should result in a failing getMore
120
120
  # command on a change stream NOT being resumed.
@@ -177,10 +177,19 @@ module Mongo
177
177
  #
178
178
  # @param buffer [String] buffer where the message should be inserted
179
179
  # @return [String] buffer containing the serialized message
180
- def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil)
180
+ def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil, bson_overhead = nil)
181
+ max_size =
182
+ if max_bson_size && bson_overhead
183
+ max_bson_size + bson_overhead
184
+ elsif max_bson_size
185
+ max_bson_size
186
+ else
187
+ nil
188
+ end
189
+
181
190
  start = buffer.length
182
191
  serialize_header(buffer)
183
- serialize_fields(buffer, max_bson_size)
192
+ serialize_fields(buffer, max_size)
184
193
  buffer.replace_int32(start, buffer.length - start)
185
194
  end
186
195
 
@@ -139,7 +139,7 @@ module Mongo
139
139
  # @return [ BSON::ByteBuffer ] buffer containing the serialized message.
140
140
  #
141
141
  # @since 2.5.0
142
- def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil)
142
+ def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil, bson_overhead = nil)
143
143
  validate_document_size!(max_bson_size)
144
144
 
145
145
  super
@@ -115,12 +115,48 @@ module Mongo
115
115
  compress_if_possible(selector.keys.first, compressor, zlib_compression_level)
116
116
  end
117
117
 
118
+ # Serializes message into bytes that can be sent on the wire.
119
+ #
120
+ # @param [ BSON::ByteBuffer ] buffer where the message should be inserted.
121
+ # @param [ Integer ] max_bson_size The maximum bson object size.
122
+ #
123
+ # @return [ BSON::ByteBuffer ] buffer containing the serialized message.
124
+ def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil, bson_overhead = nil)
125
+ validate_document_size!(max_bson_size)
126
+
127
+ super
128
+ end
129
+
118
130
  protected
119
131
 
120
132
  attr_reader :upconverter
121
133
 
122
134
  private
123
135
 
136
+ # Validate that the documents in this message are all smaller than the
137
+ # maxBsonObjectSize. If not, raise an exception.
138
+ def validate_document_size!(max_bson_size)
139
+ max_bson_size ||= Mongo::Server::ConnectionBase::DEFAULT_MAX_BSON_OBJECT_SIZE
140
+
141
+ documents = if @selector.key?(:documents)
142
+ @selector[:documents]
143
+ elsif @selector.key?(:deletes)
144
+ @selector[:deletes]
145
+ elsif @selector.key?(:updates)
146
+ @selector[:updates]
147
+ else
148
+ []
149
+ end
150
+
151
+ contains_too_large_document = documents.any? do |doc|
152
+ doc.to_bson.length > max_bson_size
153
+ end
154
+
155
+ if contains_too_large_document
156
+ raise Error::MaxBSONSize.new('The document exceeds maximum allowed BSON object size after serialization')
157
+ end
158
+ end
159
+
124
160
  # The operation code required to specify a Query message.
125
161
  # @return [Fixnum] the operation code.
126
162
  #
@@ -189,10 +189,8 @@ module Mongo
189
189
  if message.bulk_write?
190
190
  # Make the new maximum size equal to the specified reduced size
191
191
  # limit plus the 16KiB overhead allowance.
192
- max_bson_size = REDUCED_MAX_BSON_SIZE + MAX_BSON_COMMAND_OVERHEAD
192
+ max_bson_size = REDUCED_MAX_BSON_SIZE
193
193
  end
194
- else
195
- max_bson_size += MAX_BSON_COMMAND_OVERHEAD
196
194
  end
197
195
 
198
196
  # RUBY-2234: It is necessary to check that the message size does not
@@ -217,7 +215,7 @@ module Mongo
217
215
  # TODO: address the fact that this line mutates the buffer.
218
216
  temp_buffer.put_bytes(buffer.get_bytes(buffer.length))
219
217
 
220
- message.serialize(temp_buffer, max_bson_size)
218
+ message.serialize(temp_buffer, max_bson_size, MAX_BSON_COMMAND_OVERHEAD)
221
219
  if temp_buffer.length > max_message_size
222
220
  raise Error::MaxMessageSize.new(max_message_size)
223
221
  end
@@ -228,7 +226,7 @@ module Mongo
228
226
  # layer should be refactored to allow compression on an already-
229
227
  # serialized message.
230
228
  final_message = message.maybe_compress(compressor, options[:zlib_compression_level])
231
- final_message.serialize(buffer, max_bson_size)
229
+ final_message.serialize(buffer, max_bson_size, MAX_BSON_COMMAND_OVERHEAD)
232
230
 
233
231
  buffer
234
232
  end
data/lib/mongo/version.rb CHANGED
@@ -17,5 +17,5 @@ module Mongo
17
17
  # The current version of the driver.
18
18
  #
19
19
  # @since 2.0.0
20
- VERSION = '2.12.3'.freeze
20
+ VERSION = '2.12.4'.freeze
21
21
  end
@@ -256,6 +256,43 @@ describe 'Client authentication options' do
256
256
  expect(client.options[:auth_mech_properties]).to eq({ 'service_name' => 'mongodb' })
257
257
  end
258
258
  end
259
+
260
+ context 'when properties are given but not service name' do
261
+ context 'with URI options' do
262
+ let(:credentials) { "#{user}:#{pwd}@" }
263
+
264
+ context 'with default auth mech properties' do
265
+ let(:options) { '?authMechanism=GSSAPI&authMechanismProperties=service_realm:foo' }
266
+
267
+ it 'sets service name to mongodb' do
268
+ expect(client.options[:auth_mech_properties]).to eq(
269
+ 'service_name' => 'mongodb',
270
+ 'service_realm' => 'foo',
271
+ )
272
+ end
273
+ end
274
+ end
275
+
276
+ context 'with client options' do
277
+ let(:client_opts) do
278
+ {
279
+ auth_mech: :gssapi,
280
+ user: user,
281
+ password: pwd,
282
+ auth_mech_properties: {
283
+ service_realm: 'foo',
284
+ }.freeze,
285
+ }.freeze
286
+ end
287
+
288
+ it 'sets default auth mech properties' do
289
+ expect(client.options[:auth_mech_properties]).to eq(
290
+ 'service_name' => 'mongodb',
291
+ 'service_realm' => 'foo',
292
+ )
293
+ end
294
+ end
295
+ end
259
296
  end
260
297
 
261
298
  context 'with PLAIN auth mechanism' do
@@ -162,15 +162,19 @@ describe 'Bulk writes with auto-encryption enabled' do
162
162
  context 'when one operation is larger than 16MiB' do
163
163
  let(:requests) do
164
164
  [
165
- { update_one: { filter: { _id: 1 }, update: { ssn: 'a' * (Mongo::Server::ConnectionBase::DEFAULT_MAX_BSON_OBJECT_SIZE - 100) } } },
165
+ { update_one: { filter: { _id: 1 }, update: { ssn: 'a' * (Mongo::Server::ConnectionBase::DEFAULT_MAX_BSON_OBJECT_SIZE) } } },
166
166
  { update_one: { filter: { _id: 2 }, update: { ssn: 'a' * size_limit } } },
167
167
  ]
168
168
  end
169
169
 
170
+ before do
171
+ expect(requests.first.to_bson.length).to be > Mongo::Server::ConnectionBase::DEFAULT_MAX_BSON_OBJECT_SIZE
172
+ end
173
+
170
174
  it 'raises an exception' do
171
175
  expect do
172
176
  bulk_write.execute
173
- end.to raise_error(Mongo::Error::MaxBSONSize, /maximum allowed size: 16777216 bytes/)
177
+ end.to raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
174
178
  end
175
179
  end
176
180
  end
@@ -62,30 +62,31 @@ describe 'BSON & command size limits' do
62
62
  authorized_collection.insert_one(document)
63
63
  end
64
64
 
65
- context 'on server versions >= 3.6' do
66
- min_server_fcv '3.6'
65
+ it 'fails on the driver when a document larger than 16MiB is inserted' do
66
+ document = { key: 'a' * (max_document_size - 27), _id: 'foo' }
67
+ expect(document.to_bson.length).to eq(max_document_size+1)
67
68
 
68
- it 'fails on the driver when a document larger than 16MiB is inserted' do
69
- document = { key: 'a' * (max_document_size - 27), _id: 'foo' }
70
- expect(document.to_bson.length).to eq(max_document_size+1)
71
-
72
- lambda do
73
- authorized_collection.insert_one(document)
74
- end.should raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
75
- end
69
+ lambda do
70
+ authorized_collection.insert_one(document)
71
+ end.should raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
76
72
  end
77
73
 
78
- context 'on server versions <= 3.4' do
79
- max_server_fcv '3.4'
74
+ it 'fails on the driver when an update larger than 16MiB is performed' do
75
+ document = { key: 'a' * (max_document_size - 14) }
76
+ expect(document.to_bson.length).to eq(max_document_size+1)
77
+
78
+ lambda do
79
+ authorized_collection.update_one({ _id: 'foo' }, document)
80
+ end.should raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
81
+ end
80
82
 
81
- it 'fails on the server when a document larger than 16MiB is inserted' do
82
- document = { key: 'a' * (max_document_size - 27), _id: 'foo' }
83
- expect(document.to_bson.length).to eq(max_document_size+1)
83
+ it 'fails on the driver when an delete larger than 16MiB is performed' do
84
+ document = { key: 'a' * (max_document_size - 14) }
85
+ expect(document.to_bson.length).to eq(max_document_size+1)
84
86
 
85
- lambda do
86
- authorized_collection.insert_one(document)
87
- end.should raise_error(Mongo::Error::OperationFailure, /object to insert too large/)
88
- end
87
+ lambda do
88
+ authorized_collection.delete_one(document)
89
+ end.should raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
89
90
  end
90
91
 
91
92
  it 'fails in the driver when a document larger than 16MiB+16KiB is inserted' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.3
4
+ version: 2.12.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Brock
@@ -31,7 +31,7 @@ cert_chain:
31
31
  gpvfPNWMwyBDlHaNS3GfO6cRRxBOvEG05GUCsvtTY4Bpe8yjE64wg1ymb47LMOnv
32
32
  Qb1lGORmf/opg45mluKUYl7pQNZHD0d3
33
33
  -----END CERTIFICATE-----
34
- date: 2020-07-30 00:00:00.000000000 Z
34
+ date: 2020-10-09 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bson
metadata.gz.sig CHANGED
Binary file