Skip to content

PYTHON-2858 Use OP_MSG to authenticate if server supports OP_MSG #843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()