Skip to content

Commit cc8ea1d

Browse files
authored
feat(NODE-4509): send 1 with hello commands (#3508)
1 parent 2e28009 commit cc8ea1d

File tree

7 files changed

+35
-44
lines changed

7 files changed

+35
-44
lines changed

etc/notes/CHANGES_5.0.0.md

+5
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,8 @@ for await (const doc of cursor) {
7676

7777
cursor.closed // true
7878
```
79+
80+
### Driver now sends `1` instead of `true` for hello commands
81+
82+
Everywhere the driver sends a `hello` command (initial handshake and monitoring), it will now pass the command value as `1` instead of the
83+
previous `true` for spec compliance.

src/cmap/connect.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export function prepareHandshakeDocument(
231231
const { serverApi } = authContext.connection;
232232

233233
const handshakeDoc: HandshakeDocument = {
234-
[serverApi?.version ? 'hello' : LEGACY_HELLO_COMMAND]: true,
234+
[serverApi?.version ? 'hello' : LEGACY_HELLO_COMMAND]: 1,
235235
helloOk: true,
236236
client: options.metadata || makeClientMetadata(options),
237237
compression: compressors

src/sdam/monitor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
238238
const isAwaitable = topologyVersion != null;
239239

240240
const cmd = {
241-
[serverApi?.version || helloOk ? 'hello' : LEGACY_HELLO_COMMAND]: true,
241+
[serverApi?.version || helloOk ? 'hello' : LEGACY_HELLO_COMMAND]: 1,
242242
...(isAwaitable && topologyVersion
243243
? { maxAwaitTimeMS, topologyVersion: makeTopologyVersion(topologyVersion) }
244244
: {})

test/integration/mongodb-handshake/.gitkeep

Whitespace-only changes.

test/integration/mongodb-handshake/promise_handshake.test.js

-40
This file was deleted.

test/unit/cmap/connect.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,32 @@ describe('Connect Tests', function () {
120120
context('prepareHandshakeDocument', () => {
121121
const prepareHandshakeDocument = promisify(prepareHandshakeDocumentCb);
122122

123+
context('when serverApi.version is present', () => {
124+
const options = {};
125+
const authContext = {
126+
connection: { serverApi: { version: '1' } },
127+
options
128+
};
129+
130+
it('sets the hello parameter to 1', async () => {
131+
const handshakeDocument = await prepareHandshakeDocument(authContext);
132+
expect(handshakeDocument).to.have.property('hello', 1);
133+
});
134+
});
135+
136+
context('when serverApi is not present', () => {
137+
const options = {};
138+
const authContext = {
139+
connection: {},
140+
options
141+
};
142+
143+
it('sets the legacy hello parameter to 1', async () => {
144+
const handshakeDocument = await prepareHandshakeDocument(authContext);
145+
expect(handshakeDocument).to.have.property(LEGACY_HELLO_COMMAND, 1);
146+
});
147+
});
148+
123149
context('loadBalanced option', () => {
124150
context('when loadBalanced is not set as an option', () => {
125151
it('does not set loadBalanced on the handshake document', async () => {

test/unit/sdam/monitor.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ describe('monitoring', function () {
237237
const doc = request.document;
238238
docs.push(doc);
239239
if (docs.length === 2) {
240-
expect(docs[0]).to.have.property(LEGACY_HELLO_COMMAND, true);
240+
expect(docs[0]).to.have.property(LEGACY_HELLO_COMMAND, 1);
241241
expect(docs[0]).to.have.property('helloOk', true);
242-
expect(docs[1]).to.have.property('hello', true);
242+
expect(docs[1]).to.have.property('hello', 1);
243243
done();
244244
} else if (isHello(doc)) {
245245
setTimeout(() => request.reply(Object.assign({ helloOk: true }, mock.HELLO)), 250);

0 commit comments

Comments
 (0)