Skip to content

Commit

Permalink
refactor(NODE-3324): bump max wire version to 13 (#2875)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Jul 2, 2021
1 parent 3ce148d commit e9196ab
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/core/wireprotocol/constants.js
@@ -1,9 +1,9 @@
'use strict';

const MIN_SUPPORTED_SERVER_VERSION = '2.6';
const MAX_SUPPORTED_SERVER_VERSION = '4.4';
const MAX_SUPPORTED_SERVER_VERSION = '5.0';
const MIN_SUPPORTED_WIRE_VERSION = 2;
const MAX_SUPPORTED_WIRE_VERSION = 9;
const MAX_SUPPORTED_WIRE_VERSION = 13;

module.exports = {
MIN_SUPPORTED_SERVER_VERSION,
Expand Down
77 changes: 77 additions & 0 deletions test/unit/wire_version.test.js
@@ -0,0 +1,77 @@
'use strict';

const mock = require('mongodb-mock-server');
const expect = require('chai').expect;
const MongoServerSelectionError = require('../../lib/core/error').MongoServerSelectionError;

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', () => {
let server;

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

beforeEach(() => {
return mock.createServer().then(s => {
server = s;
});
});
afterEach(() => {
return mock.cleanup();
});

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

const client = this.configuration.newClient(
`mongodb://${server.uri()}/wireVersionTest?serverSelectionTimeoutMS=200`
);
return client
.connect()
.then(() => {
expect.fail('should fail to select server!');
})
.catch(error => {
expect(error).to.be.instanceOf(MongoServerSelectionError);
expect(error)
.to.have.property('message')
.that.includes(minCompatErrMsg);
});
});
});

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

const client = this.configuration.newClient(
`mongodb://${server.uri()}/wireVersionTest?serverSelectionTimeoutMS=200`
);
return client
.connect()
.then(() => {
expect.fail('should fail to select server!');
})
.catch(error => {
expect(error).to.be.instanceOf(MongoServerSelectionError);
expect(error)
.to.have.property('message')
.that.includes(maxCompatErrMsg);
});
});
});
});

0 comments on commit e9196ab

Please sign in to comment.