Skip to content

Commit 5186fb1

Browse files
test(NODE-6959): add OIDC reauth with session prose test (#4547)
Co-authored-by: Bailey Pearson <[email protected]>
1 parent bd6030f commit 5186fb1

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

test/integration/auth/mongodb_oidc.prose.test.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { expect } from 'chai';
55
import * as sinon from 'sinon';
66

77
import {
8+
type ClientSession,
89
type Collection,
910
MongoClient,
1011
type MongoDBOIDC,
@@ -639,6 +640,73 @@ describe('OIDC Auth Spec Tests', function () {
639640
expect(saslStarts.length).to.equal(1);
640641
});
641642
});
643+
644+
describe('4.5 Reauthentication Succeeds when a Session is involved', function () {
645+
let utilClient: MongoClient;
646+
let session: ClientSession;
647+
const callbackSpy = sinon.spy(createCallback());
648+
// Create an OIDC configured client.
649+
// Set a fail point for find commands of the form:
650+
// {
651+
// configureFailPoint: "failCommand",
652+
// mode: {
653+
// times: 1
654+
// },
655+
// data: {
656+
// failCommands: [
657+
// "find"
658+
// ],
659+
// errorCode: 391 // ReauthenticationRequired
660+
// }
661+
// }
662+
// Start a new session.
663+
// In the started session perform a find operation that succeeds.
664+
// Assert that the callback was called 2 times (once during the connection handshake, and again during reauthentication).
665+
// Close the session and the client.
666+
beforeEach(async function () {
667+
client = new MongoClient(uriSingle, {
668+
authMechanismProperties: {
669+
OIDC_CALLBACK: callbackSpy
670+
},
671+
retryReads: false
672+
});
673+
utilClient = new MongoClient(uriSingle, {
674+
authMechanismProperties: {
675+
OIDC_CALLBACK: createCallback()
676+
},
677+
retryReads: false
678+
});
679+
collection = client.db('test').collection('test');
680+
await utilClient
681+
.db()
682+
.admin()
683+
.command({
684+
configureFailPoint: 'failCommand',
685+
mode: {
686+
times: 1
687+
},
688+
data: {
689+
failCommands: ['find'],
690+
errorCode: 391
691+
}
692+
});
693+
session = client.startSession();
694+
});
695+
696+
afterEach(async function () {
697+
await utilClient.db().admin().command({
698+
configureFailPoint: 'failCommand',
699+
mode: 'off'
700+
});
701+
await utilClient.close();
702+
await session.endSession();
703+
});
704+
705+
it('successfully authenticates', async function () {
706+
await collection.findOne({}, { session });
707+
expect(callbackSpy).to.have.been.calledTwice;
708+
});
709+
});
642710
});
643711
});
644712

0 commit comments

Comments
 (0)