From c6eedff89acfc6b89a5690ed459a90812e2d6f7f Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Wed, 12 Nov 2025 15:48:10 +0100 Subject: [PATCH] fix(NODE-7290): use valueof for error code check --- src/sdam/server.ts | 2 +- .../auth/mongodb_oidc.prose.test.ts | 64 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/sdam/server.ts b/src/sdam/server.ts index b1f7c0e537a..f14188a0d55 100644 --- a/src/sdam/server.ts +++ b/src/sdam/server.ts @@ -356,7 +356,7 @@ export class Server extends TypedEventEmitter { } catch (operationError) { if ( operationError instanceof MongoError && - operationError.code === MONGODB_ERROR_CODES.Reauthenticate + operationError.code?.valueOf() === MONGODB_ERROR_CODES.Reauthenticate ) { reauthPromise = this.pool.reauthenticate(conn); reauthPromise.then(undefined, error => { diff --git a/test/integration/auth/mongodb_oidc.prose.test.ts b/test/integration/auth/mongodb_oidc.prose.test.ts index ea9321ac88a..ed0bc077e76 100644 --- a/test/integration/auth/mongodb_oidc.prose.test.ts +++ b/test/integration/auth/mongodb_oidc.prose.test.ts @@ -417,6 +417,70 @@ describe('OIDC Auth Spec Tests', function () { }); }); + describe('4.1 Reauthentication Succeeds (promoteValues: false)', function () { + let utilClient: MongoClient; + 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 + // } + // } + // 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 client. + beforeEach(async function () { + client = new MongoClient(uriSingle, { + authMechanismProperties: { + OIDC_CALLBACK: callbackSpy + }, + retryReads: false, + promoteValues: 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 + } + }); + }); + + afterEach(async function () { + await utilClient.db().admin().command({ + configureFailPoint: 'failCommand', + mode: 'off' + }); + await utilClient.close(); + }); + + it('successfully authenticates', async function () { + await collection.findOne(); + expect(callbackSpy).to.have.been.calledTwice; + }); + }); + describe('4.2 Read Commands Fail If Reauthentication Fails', function () { let utilClient: MongoClient; const callbackSpy = sinon.spy(createBadCallback());