Skip to content
Merged
Changes from 2 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
68 changes: 68 additions & 0 deletions test/integration/auth/mongodb_oidc.prose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { expect } from 'chai';
import * as sinon from 'sinon';

import {
type ClientSession,
type Collection,
MongoClient,
type MongoDBOIDC,
Expand Down Expand Up @@ -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;
});
});
});
});

Expand Down