Skip to content

Commit

Permalink
fix(NODE-3413): accept tls=false in mongodb+srv connection strings (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Jul 7, 2021
1 parent 3d490dc commit 526c73f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/connection_string.ts
Expand Up @@ -232,7 +232,9 @@ export function parseOptions(
if (isSRV) {
// SRV Record is resolved upon connecting
mongoOptions.srvHost = hosts[0];
options.tls = true;
if (!url.searchParams.has('tls') && !url.searchParams.has('ssl')) {
options.tls = true;
}
}

const urlOptions = new CaseInsensitiveMap();
Expand Down
8 changes: 7 additions & 1 deletion test/unit/core/mongodb_srv.test.js
Expand Up @@ -38,8 +38,14 @@ describe('mongodb+srv', function () {
expect(result).to.exist;
// Implicit SRV options must be set.
expect(options.directConnection).to.be.false;
expect(options.tls).to.be.true;
const testOptions = test[1].options;
if (testOptions && 'tls' in testOptions) {
expect(options).to.have.property('tls', testOptions.tls);
} else if (testOptions && 'ssl' in testOptions) {
expect(options).to.have.property('tls', testOptions.ssl);
} else {
expect(options.tls).to.be.true;
}
if (testOptions && testOptions.replicaSet) {
expect(options).to.have.property('replicaSet', testOptions.replicaSet);
}
Expand Down
13 changes: 13 additions & 0 deletions test/unit/mongo_client_options.test.js
Expand Up @@ -229,6 +229,19 @@ describe('MongoOptions', function () {
it('srvHost saved to options for later resolution', function () {
const options = parseOptions('mongodb+srv://server.example.com/');
expect(options).has.property('srvHost', 'server.example.com');
expect(options).has.property('tls', true);
});

it('ssl= can be used to set tls=false', function () {
const options = parseOptions('mongodb+srv://server.example.com/?ssl=false');
expect(options).has.property('srvHost', 'server.example.com');
expect(options).has.property('tls', false);
});

it('tls= can be used to set tls=false', function () {
const options = parseOptions('mongodb+srv://server.example.com/?tls=false');
expect(options).has.property('srvHost', 'server.example.com');
expect(options).has.property('tls', false);
});

it('supports ReadPreference option in url', function () {
Expand Down

0 comments on commit 526c73f

Please sign in to comment.