Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/sdam/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
} 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 => {
Expand Down
64 changes: 64 additions & 0 deletions test/integration/auth/mongodb_oidc.prose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down