From e6176aeead4934f8fd077c480432e66d299782c7 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 29 Oct 2024 18:23:49 -0500 Subject: [PATCH] PYTHON-4209 Fix test for ensure that no error is raised for unknown auth mechanism --- test/mockupdb/test_handshake.py | 39 ++++----------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/test/mockupdb/test_handshake.py b/test/mockupdb/test_handshake.py index 752c4f8421..c2c978c4ad 100644 --- a/test/mockupdb/test_handshake.py +++ b/test/mockupdb/test_handshake.py @@ -218,50 +218,19 @@ def test_client_handshake_saslSupportedMechs(self): request.ok( "ismaster", True, - saslSupportedMechs=["SCRAM-SHA-256"], + # Unsupported auth mech should be ignored. + saslSupportedMechs=["SCRAM-SHA-256", "does_not_exist"], speculativeAuthenticate=auth, minWireVersion=2, maxWireVersion=MIN_SUPPORTED_WIRE_VERSION, ) # Authentication should immediately fail with: # OperationFailure: Server returned an invalid nonce. - with self.assertRaises(OperationFailure): + with self.assertRaises(OperationFailure) as cm: future() + self.assertEqual(str(cm.exception), "Server returned an invalid nonce.") return - def test_client_handshake_saslSupportedMechs_unknown(self): - server = MockupDB() - server.run() - self.addCleanup(server.stop) - - primary_response = OpReply( - "ismaster", - True, - minWireVersion=2, - maxWireVersion=MIN_SUPPORTED_WIRE_VERSION, - saslSupportedMechs=["SCRAM-SHA-256", "does_not_exist"], - ) - client = MongoClient( - server.uri, authmechanism="PLAIN", username="username", password="password" - ) - - self.addCleanup(client.close) - - # New monitoring connections send data during handshake. - heartbeat = server.receives("ismaster") - heartbeat.ok(primary_response) - - future = go(client.db.command, "whatever") - for request in server: - if request.matches("ismaster"): - request.ok(primary_response) - elif request.matches("saslStart"): - request.ok("saslStart", True, conversationId=1, payload=b"", done=True, ok=1) - else: - request.ok() - future() - return - def test_handshake_load_balanced(self): self.hello_with_option_helper(OpMsg, loadBalanced=True) with self.assertRaisesRegex(AssertionError, "does not match"):