Skip to content

Commit b17bf5b

Browse files
authored
refactor(NODE-3324): bump max wire version to 13 (#2874)
1 parent a4e14ff commit b17bf5b

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

src/cmap/wire_protocol/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const MIN_SUPPORTED_SERVER_VERSION = '2.6';
2-
export const MAX_SUPPORTED_SERVER_VERSION = '4.4';
2+
export const MAX_SUPPORTED_SERVER_VERSION = '5.0';
33
export const MIN_SUPPORTED_WIRE_VERSION = 2;
4-
export const MAX_SUPPORTED_WIRE_VERSION = 9;
4+
export const MAX_SUPPORTED_WIRE_VERSION = 13;
55
export const OP_REPLY = 1;
66
export const OP_UPDATE = 2001;
77
export const OP_INSERT = 2002;

test/unit/wire_version.test.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
'use strict';
2+
3+
const mock = require('../tools/mock');
4+
const { expect } = require('chai');
5+
const { MongoServerSelectionError } = require('../../src/error');
6+
7+
const minCompatErrMsg = `minimum wire version ${
8+
Number.MAX_SAFE_INTEGER - 1
9+
}, but this version of the Node.js Driver requires at most 13`;
10+
const maxCompatErrMsg = `reports maximum wire version 1, but this version of the Node.js Driver requires at least 2`;
11+
12+
describe('Wire Protocol Version', () => {
13+
/** @type {mock.MockServer} */
14+
let server;
15+
16+
function setWireProtocolMessageHandler(min, max) {
17+
server.setMessageHandler(req => {
18+
const doc = req.document;
19+
if (doc.ismaster || doc.hello) {
20+
const hello = {
21+
...mock.DEFAULT_ISMASTER_36,
22+
minWireVersion: min,
23+
maxWireVersion: max
24+
};
25+
return req.reply(hello);
26+
}
27+
});
28+
}
29+
30+
beforeEach(async () => {
31+
server = await mock.createServer();
32+
});
33+
afterEach(async () => {
34+
await mock.cleanup();
35+
});
36+
37+
describe('minimum is greater than 13', () => {
38+
it('should raise a compatibility error', async function () {
39+
setWireProtocolMessageHandler(Number.MAX_SAFE_INTEGER - 1, Number.MAX_SAFE_INTEGER);
40+
41+
/** @type {import('../../src/mongo_client').MongoClient} */
42+
const client = this.configuration.newClient(
43+
`mongodb://${server.uri()}/wireVersionTest?serverSelectionTimeoutMS=200`
44+
);
45+
try {
46+
await client.connect();
47+
expect.fail('should fail to select server!');
48+
} catch (error) {
49+
expect(error).to.be.instanceOf(MongoServerSelectionError);
50+
expect(error).to.have.property('message').that.includes(minCompatErrMsg);
51+
}
52+
await client.close();
53+
});
54+
});
55+
56+
describe('maximum is less than 2', () => {
57+
it('should raise a compatibility error', async function () {
58+
setWireProtocolMessageHandler(1, 1);
59+
60+
/** @type {import('../../src/mongo_client').MongoClient} */
61+
const client = this.configuration.newClient(
62+
`mongodb://${server.uri()}/wireVersionTest?serverSelectionTimeoutMS=200`
63+
);
64+
try {
65+
await client.connect();
66+
expect.fail('should fail to select server!');
67+
} catch (error) {
68+
expect(error).to.be.instanceOf(MongoServerSelectionError);
69+
expect(error).to.have.property('message').that.includes(maxCompatErrMsg);
70+
}
71+
await client.close();
72+
});
73+
});
74+
});

0 commit comments

Comments
 (0)