Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import * as sinon from 'sinon';

import { getFAASEnv, type MongoClient } from '../../mongodb';

import { Connection, getFAASEnv, LEGACY_HELLO_COMMAND, type MongoClient } from '../../mongodb';
describe('Handshake Prose Tests', function () {
let client: MongoClient;

Expand Down Expand Up @@ -109,4 +109,41 @@ describe('Handshake Prose Tests', function () {
});
});
}

context(`Test 2: Test that the driver accepts an arbitrary auth mechanism`, function () {
let stubCalled = false;
beforeEach(() => {
// Mock the server response in a way that saslSupportedMechs array in the hello command response contains an arbitrary string.
sinon.stub(Connection.prototype, 'command').callsFake(async function (ns, cmd, options) {
// @ts-expect-error: sinon will place wrappedMethod there
const command = Connection.prototype.command.wrappedMethod.bind(this);
if (cmd.hello || cmd[LEGACY_HELLO_COMMAND]) {
return stub();
}
return command(ns, cmd, options);

async function stub() {
stubCalled = true;
const response = await command(ns, cmd, options);
return {
...response,
saslSupportedMechs: [...(response.saslSupportedMechs ?? []), 'random string']
};
}
});
});

afterEach(() => sinon.restore());

it('no error is thrown', { requires: { auth: 'enabled' } }, async function () {
// Create and connect a Connection object that connects to the server that returns the mocked response.
// Assert that no error is raised.
client = this.configuration.newClient();
await client.connect();
await client.db('foo').collection('bar').insertOne({ name: 'john doe' });

expect(stubCalled).to.be.true;
await client.close();
});
});
});