Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/cmap/wire_protocol/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const MIN_SUPPORTED_SERVER_VERSION = '2.6';
export const MAX_SUPPORTED_SERVER_VERSION = '4.4';
export const MAX_SUPPORTED_SERVER_VERSION = '5.0';
export const MIN_SUPPORTED_WIRE_VERSION = 2;
export const MAX_SUPPORTED_WIRE_VERSION = 9;
export const MAX_SUPPORTED_WIRE_VERSION = 13;
export const OP_REPLY = 1;
export const OP_UPDATE = 2001;
export const OP_INSERT = 2002;
Expand Down
74 changes: 74 additions & 0 deletions test/unit/wire_version.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict';

const mock = require('../tools/mock');
const { expect } = require('chai');
const { MongoServerSelectionError } = require('../../src/error');

const minCompatErrMsg = `minimum wire version ${
Number.MAX_SAFE_INTEGER - 1
}, but this version of the Node.js Driver requires at most 13`;
const maxCompatErrMsg = `reports maximum wire version 1, but this version of the Node.js Driver requires at least 2`;

describe('Wire Protocol Version', () => {
/** @type {mock.MockServer} */
let server;

function setWireProtocolMessageHandler(min, max) {
server.setMessageHandler(req => {
const doc = req.document;
if (doc.ismaster || doc.hello) {
const hello = {
...mock.DEFAULT_ISMASTER_36,
minWireVersion: min,
maxWireVersion: max
};
return req.reply(hello);
}
});
}

beforeEach(async () => {
server = await mock.createServer();
});
afterEach(async () => {
await mock.cleanup();
});

describe('minimum is greater than 13', () => {
it('should raise a compatibility error', async function () {
setWireProtocolMessageHandler(Number.MAX_SAFE_INTEGER - 1, Number.MAX_SAFE_INTEGER);

/** @type {import('../../src/mongo_client').MongoClient} */
const client = this.configuration.newClient(
`mongodb://${server.uri()}/wireVersionTest?serverSelectionTimeoutMS=200`
);
try {
await client.connect();
expect.fail('should fail to select server!');
} catch (error) {
expect(error).to.be.instanceOf(MongoServerSelectionError);
expect(error).to.have.property('message').that.includes(minCompatErrMsg);
}
await client.close();
});
});

describe('maximum is less than 2', () => {
it('should raise a compatibility error', async function () {
setWireProtocolMessageHandler(1, 1);

/** @type {import('../../src/mongo_client').MongoClient} */
const client = this.configuration.newClient(
`mongodb://${server.uri()}/wireVersionTest?serverSelectionTimeoutMS=200`
);
try {
await client.connect();
expect.fail('should fail to select server!');
} catch (error) {
expect(error).to.be.instanceOf(MongoServerSelectionError);
expect(error).to.have.property('message').that.includes(maxCompatErrMsg);
}
await client.close();
});
});
});