From ab0744bb18c57479f91022886e7df6904eb757f8 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Mon, 2 Jun 2025 11:31:01 -0400 Subject: [PATCH 1/2] test(NODE-6959): add reauth test with session --- .../auth/mongodb_oidc.prose.test.ts | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/integration/auth/mongodb_oidc.prose.test.ts b/test/integration/auth/mongodb_oidc.prose.test.ts index 477283ba617..ffb98a7c677 100644 --- a/test/integration/auth/mongodb_oidc.prose.test.ts +++ b/test/integration/auth/mongodb_oidc.prose.test.ts @@ -5,6 +5,7 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; import { + ClientSession, type Collection, MongoClient, type MongoDBOIDC, @@ -639,6 +640,73 @@ describe('OIDC Auth Spec Tests', function () { expect(saslStarts.length).to.equal(1); }); }); + + describe('4.5 Reauthentication Succeeds when a Session is involved', function () { + let utilClient: MongoClient; + let session: ClientSession; + const callbackSpy = sinon.spy(createCallback()); + // Create an OIDC configured client. + // Set a fail point for find commands of the form: + // { + // configureFailPoint: "failCommand", + // mode: { + // times: 1 + // }, + // data: { + // failCommands: [ + // "find" + // ], + // errorCode: 391 // ReauthenticationRequired + // } + // } + // Start a new session. + // In the started session perform a find operation that succeeds. + // Assert that the callback was called 2 times (once during the connection handshake, and again during reauthentication). + // Close the session and the client. + beforeEach(async function () { + client = new MongoClient(uriSingle, { + authMechanismProperties: { + OIDC_CALLBACK: callbackSpy + }, + retryReads: false + }); + utilClient = new MongoClient(uriSingle, { + authMechanismProperties: { + OIDC_CALLBACK: createCallback() + }, + retryReads: false + }); + collection = client.db('test').collection('test'); + await utilClient + .db() + .admin() + .command({ + configureFailPoint: 'failCommand', + mode: { + times: 1 + }, + data: { + failCommands: ['find'], + errorCode: 391 + } + }); + session = client.startSession(); + }); + + afterEach(async function () { + await utilClient.db().admin().command({ + configureFailPoint: 'failCommand', + mode: 'off' + }); + await utilClient.close(); + await session.endSession(); + }); + + it('successfully authenticates', async function () { + await collection.findOne({}, { session }); + expect(callbackSpy).to.have.been.calledTwice; + }); + }); }); }); From 610dbe5ee974bc6958912789d21338370432ae2b Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Mon, 2 Jun 2025 12:00:59 -0400 Subject: [PATCH 2/2] fix: lint --- test/integration/auth/mongodb_oidc.prose.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/auth/mongodb_oidc.prose.test.ts b/test/integration/auth/mongodb_oidc.prose.test.ts index ffb98a7c677..3b821b68832 100644 --- a/test/integration/auth/mongodb_oidc.prose.test.ts +++ b/test/integration/auth/mongodb_oidc.prose.test.ts @@ -5,7 +5,7 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; import { - ClientSession, + type ClientSession, type Collection, MongoClient, type MongoDBOIDC,