Skip to content

Commit 6c02964

Browse files
test(NODE-5920): do not throw if the server returns unknown saslSupportedMechs (#4299)
1 parent 82c931c commit 6c02964

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

test/integration/mongodb-handshake/mongodb-handshake.prose.test.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
2+
import * as sinon from 'sinon';
23

3-
import { getFAASEnv, type MongoClient } from '../../mongodb';
4-
4+
import { Connection, getFAASEnv, LEGACY_HELLO_COMMAND, type MongoClient } from '../../mongodb';
55
describe('Handshake Prose Tests', function () {
66
let client: MongoClient;
77

@@ -109,4 +109,41 @@ describe('Handshake Prose Tests', function () {
109109
});
110110
});
111111
}
112+
113+
context(`Test 2: Test that the driver accepts an arbitrary auth mechanism`, function () {
114+
let stubCalled = false;
115+
beforeEach(() => {
116+
// Mock the server response in a way that saslSupportedMechs array in the hello command response contains an arbitrary string.
117+
sinon.stub(Connection.prototype, 'command').callsFake(async function (ns, cmd, options) {
118+
// @ts-expect-error: sinon will place wrappedMethod there
119+
const command = Connection.prototype.command.wrappedMethod.bind(this);
120+
if (cmd.hello || cmd[LEGACY_HELLO_COMMAND]) {
121+
return stub();
122+
}
123+
return command(ns, cmd, options);
124+
125+
async function stub() {
126+
stubCalled = true;
127+
const response = await command(ns, cmd, options);
128+
return {
129+
...response,
130+
saslSupportedMechs: [...(response.saslSupportedMechs ?? []), 'random string']
131+
};
132+
}
133+
});
134+
});
135+
136+
afterEach(() => sinon.restore());
137+
138+
it('no error is thrown', { requires: { auth: 'enabled' } }, async function () {
139+
// Create and connect a Connection object that connects to the server that returns the mocked response.
140+
// Assert that no error is raised.
141+
client = this.configuration.newClient();
142+
await client.connect();
143+
await client.db('foo').collection('bar').insertOne({ name: 'john doe' });
144+
145+
expect(stubCalled).to.be.true;
146+
await client.close();
147+
});
148+
});
112149
});

0 commit comments

Comments
 (0)