Skip to content

Commit d2921d2

Browse files
committed
Show that insert messages are checked against max message size and other ops check max bson obj size
1 parent 5d41f7e commit d2921d2

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

spec/mongo/server/connection_spec.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,55 @@
240240
end
241241
end
242242

243+
context 'when the message exceeds the max size' do
244+
245+
context 'when the message is an insert' do
246+
247+
before do
248+
allow(connection).to receive(:max_message_size).and_return(200)
249+
end
250+
251+
let(:documents) do
252+
[{ 'name' => 'testing' } ] * 10
253+
end
254+
255+
let(:reply) do
256+
connection.dispatch([ insert ])
257+
end
258+
259+
it 'checks the size against the max message size' do
260+
expect {
261+
reply
262+
}.to raise_exception(Mongo::Error::MaxMessageSize)
263+
end
264+
end
265+
266+
context 'when the message is a command' do
267+
268+
before do
269+
allow(connection).to receive(:max_bson_object_size).and_return(100)
270+
end
271+
272+
let(:selector) do
273+
{ :getlasterror => '1' }
274+
end
275+
276+
let(:command) do
277+
Mongo::Protocol::Query.new(TEST_DB, '$cmd', selector, :limit => -1)
278+
end
279+
280+
let(:reply) do
281+
connection.dispatch([ command ])
282+
end
283+
284+
it 'checks the size against the max bson size' do
285+
expect {
286+
reply
287+
}.to raise_exception(Mongo::Error::MaxBSONSize)
288+
end
289+
end
290+
end
291+
243292
context 'when a network or socket error occurs' do
244293

245294
let(:socket) do

0 commit comments

Comments
 (0)