Skip to content

Commit

Permalink
PYTHON-2858 Use OP_MSG to authenticate if server supports OP_MSG (mon…
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusgeo authored Feb 3, 2022
1 parent dd6c140 commit 5169124
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion test/mockupdb/test_handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def respond(r):
appname='my app', # For _check_handshake_data()
**dict([k_map.get((k, v), (k, v)) for k, v
in kwargs.items()]))

self.addCleanup(client.close)

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

def test_handshake_max_wire(self):
server = MockupDB()
primary_response = {"hello": 1, "ok": 1,
"minWireVersion": 0, "maxWireVersion": 6}
self.found_auth_msg = False

def responder(request):
if request.matches(OpMsg, saslStart=1):
self.found_auth_msg = True
# Immediately closes the connection with
# OperationFailure: Server returned an invalid nonce.
request.reply(OpMsgReply(**primary_response,
**{'payload':
b'r=wPleNM8S5p8gMaffMDF7Py4ru9bnmmoqb0'
b'1WNPsil6o=pAvr6B1garhlwc6MKNQ93ZfFky'
b'tXdF9r,'
b's=4dcxugMJq2P4hQaDbGXZR8uR3ei'
b'PHrSmh4uhkg==,i=15000',
"saslSupportedMechs": [
"SCRAM-SHA-1"]}))
else:
return request.reply(**primary_response)

server.autoresponds(responder)
self.addCleanup(server.stop)
server.run()
client = MongoClient(server.uri,
username='username',
password='password',
)
self.addCleanup(client.close)
self.assertRaises(OperationFailure, client.db.collection.find_one,
{"a": 1})
self.assertTrue(self.found_auth_msg, "Could not find authentication "
"command with correct protocol")


if __name__ == '__main__':
unittest.main()

0 comments on commit 5169124

Please sign in to comment.