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. 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/.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 ac4abfafbce..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]: true }) - .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 () => { diff --git a/test/unit/sdam/monitor.test.ts b/test/unit/sdam/monitor.test.ts index 4bb611155df..97a7273666b 100644 --- a/test/unit/sdam/monitor.test.ts +++ b/test/unit/sdam/monitor.test.ts @@ -237,9 +237,9 @@ 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); + expect(docs[1]).to.have.property('hello', 1); done(); } else if (isHello(doc)) { setTimeout(() => request.reply(Object.assign({ helloOk: true }, mock.HELLO)), 250);