Skip to content

PYTHON-5399 Add a prose test for OIDC reauthentication when a session is involved #2351

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 4 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions test/asynchronous/test_auth_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,25 @@ async def test_4_4_speculative_authentication_should_be_ignored_on_reauthenticat
# Assert there were `SaslStart` commands executed.
assert any(event.command_name.lower() == "saslstart" for event in listener.started_events)

async def test_4_5_reauthentication_succeeds_when_a_session_is_involved(self):
# Create an OIDC configured client.
client = await self.create_client()

# Set a fail point for `find` commands of the form:
async with self.fail_point(
{
"mode": {"times": 1},
"data": {"failCommands": ["find"], "errorCode": 391},
}
):
# Start a new session.
async with client.start_session() as session:
# In the started session perform a `find` operation that succeeds.
await client.test.test.find_one({}, session=session)

# Assert that the callback was called 2 times (once during the connection handshake, and again during reauthentication).
self.assertEqual(self.request_called, 2)

async def test_5_1_azure_with_no_username(self):
if ENVIRON != "azure":
raise unittest.SkipTest("Test is only supported on Azure")
Expand Down
19 changes: 19 additions & 0 deletions test/test_auth_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,25 @@ def test_4_4_speculative_authentication_should_be_ignored_on_reauthentication(se
# Assert there were `SaslStart` commands executed.
assert any(event.command_name.lower() == "saslstart" for event in listener.started_events)

def test_4_5_reauthentication_succeeds_when_a_session_is_involved(self):
# Create an OIDC configured client.
client = self.create_client()

# Set a fail point for `find` commands of the form:
with self.fail_point(
{
"mode": {"times": 1},
"data": {"failCommands": ["find"], "errorCode": 391},
}
):
# Start a new session.
with client.start_session() as session:
# In the started session perform a `find` operation that succeeds.
client.test.test.find_one({}, session=session)

# Assert that the callback was called 2 times (once during the connection handshake, and again during reauthentication).
self.assertEqual(self.request_called, 2)

def test_5_1_azure_with_no_username(self):
if ENVIRON != "azure":
raise unittest.SkipTest("Test is only supported on Azure")
Expand Down
Loading