Skip to content

Commit 6d33d4f

Browse files
authored
PYTHON-5399 Add a prose test for OIDC reauthentication when a session is involved (#2351)
1 parent 454c163 commit 6d33d4f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

test/asynchronous/test_auth_oidc.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,25 @@ async def test_4_4_speculative_authentication_should_be_ignored_on_reauthenticat
10851085
# Assert there were `SaslStart` commands executed.
10861086
assert any(event.command_name.lower() == "saslstart" for event in listener.started_events)
10871087

1088+
async def test_4_5_reauthentication_succeeds_when_a_session_is_involved(self):
1089+
# Create an OIDC configured client.
1090+
client = await self.create_client()
1091+
1092+
# Set a fail point for `find` commands of the form:
1093+
async with self.fail_point(
1094+
{
1095+
"mode": {"times": 1},
1096+
"data": {"failCommands": ["find"], "errorCode": 391},
1097+
}
1098+
):
1099+
# Start a new session.
1100+
async with client.start_session() as session:
1101+
# In the started session perform a `find` operation that succeeds.
1102+
await client.test.test.find_one({}, session=session)
1103+
1104+
# Assert that the callback was called 2 times (once during the connection handshake, and again during reauthentication).
1105+
self.assertEqual(self.request_called, 2)
1106+
10881107
async def test_5_1_azure_with_no_username(self):
10891108
if ENVIRON != "azure":
10901109
raise unittest.SkipTest("Test is only supported on Azure")

test/test_auth_oidc.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,25 @@ def test_4_4_speculative_authentication_should_be_ignored_on_reauthentication(se
10831083
# Assert there were `SaslStart` commands executed.
10841084
assert any(event.command_name.lower() == "saslstart" for event in listener.started_events)
10851085

1086+
def test_4_5_reauthentication_succeeds_when_a_session_is_involved(self):
1087+
# Create an OIDC configured client.
1088+
client = self.create_client()
1089+
1090+
# Set a fail point for `find` commands of the form:
1091+
with self.fail_point(
1092+
{
1093+
"mode": {"times": 1},
1094+
"data": {"failCommands": ["find"], "errorCode": 391},
1095+
}
1096+
):
1097+
# Start a new session.
1098+
with client.start_session() as session:
1099+
# In the started session perform a `find` operation that succeeds.
1100+
client.test.test.find_one({}, session=session)
1101+
1102+
# Assert that the callback was called 2 times (once during the connection handshake, and again during reauthentication).
1103+
self.assertEqual(self.request_called, 2)
1104+
10861105
def test_5_1_azure_with_no_username(self):
10871106
if ENVIRON != "azure":
10881107
raise unittest.SkipTest("Test is only supported on Azure")

0 commit comments

Comments
 (0)