Skip to content

Commit

Permalink
fix: remove catch for synchronous socket errors and remove validation…
Browse files Browse the repository at this point in the history
… on nodejs option (#2746)


NODE-3061
  • Loading branch information
nbbeeken authored and ljhaywar committed Nov 9, 2021
1 parent ab1a480 commit 94d622a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 35 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@types/chai-subset": "^1.3.3",
"@types/kerberos": "^1.1.0",
"@types/mocha": "^8.2.0",
"@types/node": "^14.6.4",
"@types/node": "^14.14.31",
"@types/saslprep": "^1.0.0",
"@types/semver": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^4.15.1",
Expand Down
27 changes: 7 additions & 20 deletions src/cmap/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,6 @@ function parseSslOptions(options: ConnectionOptions): TLSConnectionOpts {
}
}

// Override checkServerIdentity behavior
if (!options.checkServerIdentity) {
// Skip the identity check by retuning undefined as per node documents
// https://nodejs.org/api/tls.html#tls_tls_connect_options_callback
result.checkServerIdentity = () => undefined;
} else if (typeof options.checkServerIdentity === 'function') {
result.checkServerIdentity = options.checkServerIdentity;
}

// Set default sni servername to be the same as host
if (result.servername == null) {
result.servername = result.host;
Expand Down Expand Up @@ -289,18 +280,14 @@ function makeConnection(options: ConnectionOptions, _callback: CallbackWithType<
_callback(err, ret);
};

try {
if (useTLS) {
const tlsSocket = tls.connect(parseSslOptions(options));
if (typeof tlsSocket.disableRenegotiation === 'function') {
tlsSocket.disableRenegotiation();
}
socket = tlsSocket;
} else {
socket = net.createConnection(parseConnectOptions(options));
if (useTLS) {
const tlsSocket = tls.connect(parseSslOptions(options));
if (typeof tlsSocket.disableRenegotiation === 'function') {
tlsSocket.disableRenegotiation();
}
} catch (err) {
return callback(err);
socket = tlsSocket;
} else {
socket = net.createConnection(parseConnectOptions(options));
}

socket.setKeepAlive(keepAlive, keepAliveInitialDelay);
Expand Down
11 changes: 1 addition & 10 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,16 +575,6 @@ export const OPTIONS = {
checkKeys: {
type: 'boolean'
},
checkServerIdentity: {
target: 'checkServerIdentity',
transform({
values: [value]
}): boolean | ((hostname: string, cert: Document) => Error | undefined) {
if (typeof value !== 'boolean' && typeof value !== 'function')
throw new MongoParseError('check server identity must be a boolean or custom function');
return value as boolean | ((hostname: string, cert: Document) => Error | undefined);
}
},
compressors: {
default: 'none',
target: 'compressors',
Expand Down Expand Up @@ -1041,6 +1031,7 @@ export const OPTIONS = {
enableTrace: { type: 'any' },
requestCert: { type: 'any' },
rejectUnauthorized: { type: 'any' },
checkServerIdentity: { type: 'any' },
ALPNProtocols: { type: 'any' },
SNICallback: { type: 'any' },
session: { type: 'any' },
Expand Down
2 changes: 1 addition & 1 deletion test/functional/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ describe('Indexes', function () {
metadata: {
requires: {
topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'],
mongodb: '>=3.0.0'
mongodb: '>=3.0.0 <=4.8.0'
}
},

Expand Down

0 comments on commit 94d622a

Please sign in to comment.