Skip to content

Commit 676dd23

Browse files
authored
CSHARP-5601: Add a prose test for OIDC reauthentication when a session is involved (#1728)
1 parent 4f44b67 commit 676dd23

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

evergreen/evergreen.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,12 +2082,17 @@ task_groups:
20822082
- func: prepare-resources
20832083
- func: fix-absolute-paths
20842084
- func: make-files-executable
2085+
- func: assume-ec2-role
20852086
- func: install-dotnet
20862087
- command: subprocess.exec
20872088
params:
20882089
binary: bash
20892090
env:
20902091
AZUREOIDC_VMNAME_PREFIX: "CSHARP_DRIVER"
2092+
include_expansions_in_env:
2093+
- "AWS_ACCESS_KEY_ID"
2094+
- "AWS_SECRET_ACCESS_KEY"
2095+
- "AWS_SESSION_TOKEN"
20912096
args:
20922097
- ${DRIVERS_TOOLS}/.evergreen/auth_oidc/azure/create-and-setup-vm.sh
20932098
teardown_group:
@@ -2108,12 +2113,17 @@ task_groups:
21082113
- func: prepare-resources
21092114
- func: fix-absolute-paths
21102115
- func: make-files-executable
2116+
- func: assume-ec2-role
21112117
- func: install-dotnet
21122118
- command: subprocess.exec
21132119
params:
21142120
binary: bash
21152121
env:
21162122
GCPOIDC_VMNAME_PREFIX: "CSHARP_DRIVER"
2123+
include_expansions_in_env:
2124+
- "AWS_ACCESS_KEY_ID"
2125+
- "AWS_SECRET_ACCESS_KEY"
2126+
- "AWS_SESSION_TOKEN"
21172127
args:
21182128
- ${DRIVERS_TOOLS}/.evergreen/auth_oidc/gcp/setup.sh
21192129
teardown_group:

tests/MongoDB.Driver.Tests/Specifications/auth/OidcAuthenticationProseTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,36 @@ public async Task Speculative_authentication_should_be_ignored_on_reauthenticati
473473
eventCapturer.Next().Should().BeOfType<CommandSucceededEvent>();
474474
}
475475

476+
// 4.5 Reauthentication Succeeds when a Session is involved
477+
// https://github.com/mongodb/specifications/blob/668992950d975d3163e538849dd20383a214fc37/source/auth/tests/mongodb-oidc.md?plain=1#L235
478+
[Theory]
479+
[ParameterAttributeData]
480+
public async Task Reauthentication_Succeeds_when_Session_involved([Values(false, true)] bool async)
481+
{
482+
EnsureOidcIsConfigured("test");
483+
484+
var callbackMock = new Mock<IOidcCallback>();
485+
// configure mock with valid access token
486+
ConfigureOidcCallback(callbackMock, GetAccessTokenValue());
487+
var credential = MongoCredential.CreateOidcCredential(callbackMock.Object);
488+
var (collection, client, eventCapturer) = CreateOidcTestObjects(credential);
489+
490+
using (ConfigureFailPoint(1, (int)ServerErrorCode.ReauthenticationRequired, "find"))
491+
{
492+
var session = client.StartSession();
493+
_ = async
494+
? await collection.FindAsync(session, Builders<BsonDocument>.Filter.Empty)
495+
: collection.FindSync(session, Builders<BsonDocument>.Filter.Empty);
496+
}
497+
498+
VerifyCallbackUsage(callbackMock, async, Times.Exactly(2));
499+
eventCapturer.Count.Should().Be(4);
500+
eventCapturer.Next().Should().BeOfType<CommandStartedEvent>();
501+
eventCapturer.Next().Should().BeOfType<CommandSucceededEvent>();
502+
eventCapturer.Next().Should().BeOfType<CommandStartedEvent>();
503+
eventCapturer.Next().Should().BeOfType<CommandSucceededEvent>();
504+
}
505+
476506
// 5.1 Azure With No Username
477507
// https://github.com/mongodb/specifications/blob/1448ba6eedfa2f16584222e683b427bea07bb085/source/auth/tests/mongodb-oidc.md?plain=1#L212
478508
[Theory]

0 commit comments

Comments
 (0)