Skip to content

CSHARP-5601: Add a prose test for OIDC reauthentication when a session is involved #1728

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 2 commits into from
Jul 16, 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
10 changes: 10 additions & 0 deletions evergreen/evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2110,12 +2110,17 @@ task_groups:
- func: prepare-resources
- func: fix-absolute-paths
- func: make-files-executable
- func: assume-ec2-role
- func: install-dotnet
- command: subprocess.exec
params:
binary: bash
env:
AZUREOIDC_VMNAME_PREFIX: "CSHARP_DRIVER"
include_expansions_in_env:
- "AWS_ACCESS_KEY_ID"
- "AWS_SECRET_ACCESS_KEY"
- "AWS_SESSION_TOKEN"
args:
- ${DRIVERS_TOOLS}/.evergreen/auth_oidc/azure/create-and-setup-vm.sh
teardown_group:
Expand All @@ -2136,12 +2141,17 @@ task_groups:
- func: prepare-resources
- func: fix-absolute-paths
- func: make-files-executable
- func: assume-ec2-role
- func: install-dotnet
- command: subprocess.exec
params:
binary: bash
env:
GCPOIDC_VMNAME_PREFIX: "CSHARP_DRIVER"
include_expansions_in_env:
- "AWS_ACCESS_KEY_ID"
- "AWS_SECRET_ACCESS_KEY"
- "AWS_SESSION_TOKEN"
args:
- ${DRIVERS_TOOLS}/.evergreen/auth_oidc/gcp/setup.sh
teardown_group:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,36 @@ public async Task Speculative_authentication_should_be_ignored_on_reauthenticati
eventCapturer.Next().Should().BeOfType<CommandSucceededEvent>();
}

// 4.5 Reauthentication Succeeds when a Session is involved
// https://github.com/mongodb/specifications/blob/668992950d975d3163e538849dd20383a214fc37/source/auth/tests/mongodb-oidc.md?plain=1#L235
[Theory]
[ParameterAttributeData]
public async Task Reauthentication_Succeeds_when_Session_involved([Values(false, true)] bool async)
{
EnsureOidcIsConfigured("test");

var callbackMock = new Mock<IOidcCallback>();
// configure mock with valid access token
ConfigureOidcCallback(callbackMock, GetAccessTokenValue());
var credential = MongoCredential.CreateOidcCredential(callbackMock.Object);
var (collection, client, eventCapturer) = CreateOidcTestObjects(credential);

using (ConfigureFailPoint(1, (int)ServerErrorCode.ReauthenticationRequired, "find"))
{
var session = client.StartSession();
_ = async
? await collection.FindAsync(session, Builders<BsonDocument>.Filter.Empty)
: collection.FindSync(session, Builders<BsonDocument>.Filter.Empty);
}

VerifyCallbackUsage(callbackMock, async, Times.Exactly(2));
eventCapturer.Count.Should().Be(4);
eventCapturer.Next().Should().BeOfType<CommandStartedEvent>();
eventCapturer.Next().Should().BeOfType<CommandSucceededEvent>();
eventCapturer.Next().Should().BeOfType<CommandStartedEvent>();
eventCapturer.Next().Should().BeOfType<CommandSucceededEvent>();
}

// 5.1 Azure With No Username
// https://github.com/mongodb/specifications/blob/1448ba6eedfa2f16584222e683b427bea07bb085/source/auth/tests/mongodb-oidc.md?plain=1#L212
[Theory]
Expand Down