Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
fix(sdam): more explicit wire protocol error message
Browse files Browse the repository at this point in the history
NODE-1186
  • Loading branch information
Jessica Lord authored and mbroadst committed Dec 23, 2017
1 parent de62615 commit 6d6d19a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
13 changes: 12 additions & 1 deletion lib/topologies/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,18 @@ var eventHandler = function(self, event) {

if (!isSupportedServer(result.result)) {
self.destroy();
return self.emit('error', new MongoError('unsupported server version'), self);
const latestSupportedVersion = '2.6';
const message =
'Server at ' +
self.s.options.host +
':' +
self.s.options.port +
' reports wire version ' +
(result.result.maxWireVersion || 0) +
', but this version of Node.js Driver requires at least 2 (MongoDB' +
latestSupportedVersion +
').';
return self.emit('error', new MongoError(message), self);
}

// Determine whether the server is instructing us to use a compressor
Expand Down
47 changes: 40 additions & 7 deletions test/tests/functional/server_tests.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

var expect = require('chai').expect,
f = require('util').format,
locateAuthMethod = require('./shared').locateAuthMethod,
executeCommand = require('./shared').executeCommand,
Server = require('../../../lib/topologies/server'),
Bson = require('bson'),
Connection = require('../../../lib/connection/connection');
const expect = require('chai').expect;
const f = require('util').format;
const locateAuthMethod = require('./shared').locateAuthMethod;
const executeCommand = require('./shared').executeCommand;
const Server = require('../../../lib/topologies/server');
const Bson = require('bson');
const Connection = require('../../../lib/connection/connection');
const mock = require('../../mock');

describe('Server tests', function() {
it('should correctly connect server to single instance', {
Expand Down Expand Up @@ -1043,4 +1044,36 @@ describe('Server tests', function() {
}
}
);

describe('Unsupported wire protocols', function() {
let server;
beforeEach(() => mock.createServer().then(_server => (server = _server)));
afterEach(() => mock.cleanup());

it('errors when unsupported wire protocol is returned from isMaster', {
metadata: { requires: { topology: ['single'] } },

test: function(done) {
server.setMessageHandler(request => {
request.reply({ ok: 1 });
});

const client = new Server(server.address());
client.on('error', error => {
let err;
try {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.have.string('but this version of Node.js Driver requires');
} catch (e) {
err = e;
}
done(err);
});
client.on('connect', () => {
done(new Error('This should not connect'));
});
client.connect();
}
});
});
});

0 comments on commit 6d6d19a

Please sign in to comment.