From b362a6608c3007ffd6e11c1c418b88523c809ba2 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Tue, 3 Jan 2023 16:20:08 +0100 Subject: [PATCH 1/4] feat(NODE-4509): send 1 with hello commands --- src/cmap/connect.ts | 2 +- src/sdam/monitor.ts | 2 +- test/integration/mongodb-handshake/promise_handshake.test.js | 2 +- test/unit/sdam/monitor.test.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmap/connect.ts b/src/cmap/connect.ts index 0fc10c93e00..a69289befaa 100644 --- a/src/cmap/connect.ts +++ b/src/cmap/connect.ts @@ -231,7 +231,7 @@ export function prepareHandshakeDocument( const { serverApi } = authContext.connection; const handshakeDoc: HandshakeDocument = { - [serverApi?.version ? 'hello' : LEGACY_HELLO_COMMAND]: true, + [serverApi?.version ? 'hello' : LEGACY_HELLO_COMMAND]: 1, helloOk: true, client: options.metadata || makeClientMetadata(options), compression: compressors diff --git a/src/sdam/monitor.ts b/src/sdam/monitor.ts index b35093b435a..2625efa1e79 100644 --- a/src/sdam/monitor.ts +++ b/src/sdam/monitor.ts @@ -238,7 +238,7 @@ function checkServer(monitor: Monitor, callback: Callback) { const isAwaitable = topologyVersion != null; const cmd = { - [serverApi?.version || helloOk ? 'hello' : LEGACY_HELLO_COMMAND]: true, + [serverApi?.version || helloOk ? 'hello' : LEGACY_HELLO_COMMAND]: 1, ...(isAwaitable && topologyVersion ? { maxAwaitTimeMS, topologyVersion: makeTopologyVersion(topologyVersion) } : {}) diff --git a/test/integration/mongodb-handshake/promise_handshake.test.js b/test/integration/mongodb-handshake/promise_handshake.test.js index ac4abfafbce..09066b28b3e 100644 --- a/test/integration/mongodb-handshake/promise_handshake.test.js +++ b/test/integration/mongodb-handshake/promise_handshake.test.js @@ -28,7 +28,7 @@ describe('Handshake', function () { // Execute legacy hello command client .db(configuration.db) - .command({ [LEGACY_HELLO_COMMAND]: true }) + .command({ [LEGACY_HELLO_COMMAND]: 1 }) .then(function (result) { test.ok(result !== null); diff --git a/test/unit/sdam/monitor.test.ts b/test/unit/sdam/monitor.test.ts index 4bb611155df..06fdd804eda 100644 --- a/test/unit/sdam/monitor.test.ts +++ b/test/unit/sdam/monitor.test.ts @@ -237,7 +237,7 @@ describe('monitoring', function () { const doc = request.document; docs.push(doc); if (docs.length === 2) { - expect(docs[0]).to.have.property(LEGACY_HELLO_COMMAND, true); + expect(docs[0]).to.have.property(LEGACY_HELLO_COMMAND, 1); expect(docs[0]).to.have.property('helloOk', true); expect(docs[1]).to.have.property('hello', true); done(); From a19df86eae916f33cea794b49a5d073d175b08ff Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Tue, 3 Jan 2023 17:23:20 +0100 Subject: [PATCH 2/4] chore: update migration guide --- etc/notes/CHANGES_5.0.0.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/etc/notes/CHANGES_5.0.0.md b/etc/notes/CHANGES_5.0.0.md index 7729a4b87a8..11a85308e07 100644 --- a/etc/notes/CHANGES_5.0.0.md +++ b/etc/notes/CHANGES_5.0.0.md @@ -61,3 +61,8 @@ for await (const doc of cursor) { cursor.closed // true ``` + +### Driver now sends `1` instead of `true` for hello commands + +Everywhere the driver sends a `hello` command (initial handshake and monitoring), it will now pass the command value as `1` instead of the +previous `true` for spec compliance. From ffc1cc8ecdb8b1faf45e57c45745150529a5cec9 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Tue, 3 Jan 2023 17:47:54 +0100 Subject: [PATCH 3/4] test: fix second hello assertion --- test/unit/sdam/monitor.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/sdam/monitor.test.ts b/test/unit/sdam/monitor.test.ts index 06fdd804eda..97a7273666b 100644 --- a/test/unit/sdam/monitor.test.ts +++ b/test/unit/sdam/monitor.test.ts @@ -239,7 +239,7 @@ describe('monitoring', function () { if (docs.length === 2) { expect(docs[0]).to.have.property(LEGACY_HELLO_COMMAND, 1); expect(docs[0]).to.have.property('helloOk', true); - expect(docs[1]).to.have.property('hello', true); + expect(docs[1]).to.have.property('hello', 1); done(); } else if (isHello(doc)) { setTimeout(() => request.reply(Object.assign({ helloOk: true }, mock.HELLO)), 250); From eb5849faa340775b722b577af7788cb9abffc55a Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Tue, 3 Jan 2023 20:17:38 +0100 Subject: [PATCH 4/4] test: update tests --- test/integration/mongodb-handshake/.gitkeep | 0 .../promise_handshake.test.js | 40 ------------------- test/unit/cmap/connect.test.js | 26 ++++++++++++ 3 files changed, 26 insertions(+), 40 deletions(-) delete mode 100644 test/integration/mongodb-handshake/.gitkeep delete mode 100644 test/integration/mongodb-handshake/promise_handshake.test.js diff --git a/test/integration/mongodb-handshake/.gitkeep b/test/integration/mongodb-handshake/.gitkeep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/integration/mongodb-handshake/promise_handshake.test.js b/test/integration/mongodb-handshake/promise_handshake.test.js deleted file mode 100644 index 09066b28b3e..00000000000 --- a/test/integration/mongodb-handshake/promise_handshake.test.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; -const { assert: test, setupDatabase } = require('../shared'); -const f = require('util').format; -const { LEGACY_HELLO_COMMAND } = require('../../../src/constants'); - -describe('Handshake', function () { - before(function () { - return setupDatabase(this.configuration); - }); - - it('Should correctly execute legacy hello command using Promise', { - metadata: { - requires: { - topology: ['single'] - } - }, - - test: function (done) { - var configuration = this.configuration; - var url = configuration.url(); - url = - url.indexOf('?') !== -1 - ? f('%s&%s', url, 'maxPoolSize=5') - : f('%s?%s', url, 'maxPoolSize=5'); - - const client = configuration.newClient(url); - client.connect().then(function (client) { - // Execute legacy hello command - client - .db(configuration.db) - .command({ [LEGACY_HELLO_COMMAND]: 1 }) - .then(function (result) { - test.ok(result !== null); - - client.close(done); - }); - }); - } - }); -}); diff --git a/test/unit/cmap/connect.test.js b/test/unit/cmap/connect.test.js index ce8e0e65b5d..1c95e81b49a 100644 --- a/test/unit/cmap/connect.test.js +++ b/test/unit/cmap/connect.test.js @@ -120,6 +120,32 @@ describe('Connect Tests', function () { context('prepareHandshakeDocument', () => { const prepareHandshakeDocument = promisify(prepareHandshakeDocumentCb); + context('when serverApi.version is present', () => { + const options = {}; + const authContext = { + connection: { serverApi: { version: '1' } }, + options + }; + + it('sets the hello parameter to 1', async () => { + const handshakeDocument = await prepareHandshakeDocument(authContext); + expect(handshakeDocument).to.have.property('hello', 1); + }); + }); + + context('when serverApi is not present', () => { + const options = {}; + const authContext = { + connection: {}, + options + }; + + it('sets the legacy hello parameter to 1', async () => { + const handshakeDocument = await prepareHandshakeDocument(authContext); + expect(handshakeDocument).to.have.property(LEGACY_HELLO_COMMAND, 1); + }); + }); + context('loadBalanced option', () => { context('when loadBalanced is not set as an option', () => { it('does not set loadBalanced on the handshake document', async () => {