Skip to content

Commit 048bd51

Browse files
committed
PYTHON-2858 Use OP_MSG to authenticate if server supports OP_MSG (mongodb#843)
1 parent a25f5fd commit 048bd51

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

test/mockupdb/test_handshake.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def respond(r):
5050
appname='my app', # For _check_handshake_data()
5151
**dict([k_map.get((k, v), (k, v)) for k, v
5252
in kwargs.items()]))
53-
53+
5454
self.addCleanup(client.close)
5555

5656
# We have an autoresponder luckily, so no need for `go()`.
@@ -217,5 +217,42 @@ def test_handshake_not_either(self):
217217
with self.assertRaisesRegex(AssertionError, "does not match"):
218218
test_hello_with_option(self, OpMsg)
219219

220+
def test_handshake_max_wire(self):
221+
server = MockupDB()
222+
primary_response = {"hello": 1, "ok": 1,
223+
"minWireVersion": 0, "maxWireVersion": 6}
224+
self.found_auth_msg = False
225+
226+
def responder(request):
227+
if request.matches(OpMsg, saslStart=1):
228+
self.found_auth_msg = True
229+
# Immediately closes the connection with
230+
# OperationFailure: Server returned an invalid nonce.
231+
request.reply(OpMsgReply(**primary_response,
232+
**{'payload':
233+
b'r=wPleNM8S5p8gMaffMDF7Py4ru9bnmmoqb0'
234+
b'1WNPsil6o=pAvr6B1garhlwc6MKNQ93ZfFky'
235+
b'tXdF9r,'
236+
b's=4dcxugMJq2P4hQaDbGXZR8uR3ei'
237+
b'PHrSmh4uhkg==,i=15000',
238+
"saslSupportedMechs": [
239+
"SCRAM-SHA-1"]}))
240+
else:
241+
return request.reply(**primary_response)
242+
243+
server.autoresponds(responder)
244+
self.addCleanup(server.stop)
245+
server.run()
246+
client = MongoClient(server.uri,
247+
username='username',
248+
password='password',
249+
)
250+
self.addCleanup(client.close)
251+
self.assertRaises(OperationFailure, client.db.collection.find_one,
252+
{"a": 1})
253+
self.assertTrue(self.found_auth_msg, "Could not find authentication "
254+
"command with correct protocol")
255+
256+
220257
if __name__ == '__main__':
221258
unittest.main()

0 commit comments

Comments
 (0)