From 90a17c1ec3ba99eb31744369113e8b0345c8cfee Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Wed, 17 Jan 2018 10:11:52 -0500 Subject: [PATCH 1/5] test(url parser): test auth credentials are preserved --- test/functional/dns_txt_records_tests.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/functional/dns_txt_records_tests.js b/test/functional/dns_txt_records_tests.js index adee036e2b2..4b11c535278 100644 --- a/test/functional/dns_txt_records_tests.js +++ b/test/functional/dns_txt_records_tests.js @@ -42,4 +42,23 @@ describe('DNS and TXT record tests', function() { } }); }); + + it('preserves auth credentials in the connection string', { + metadata: { + requires: { topology: ['single'] } + }, + test: function(done) { + let user = 'auser'; + let password = 'apass'; + let uri = `mongodb+srv://${user}:${password}@test18.test.build.10gen.cc/?replicaSet=repl0`; + parse(uri, function(err, object) { + expect(err).to.not.exist; + expect(object.auth.user).to.not.be.undefined; + expect(object.auth.user).to.equal(user); + expect(object.auth.password).to.not.be.undefined; + expect(object.auth.password).to.equal(password); + done(); + }); + } + }); }); From d496c5eeffde86639c6ce907a9f0fa9b7661a05f Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Wed, 17 Jan 2018 10:12:27 -0500 Subject: [PATCH 2/5] fix(url parser): preserve auth creds when composing conn string --- lib/url_parser.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/url_parser.js b/lib/url_parser.js index 686c04e84cc..c188759c58e 100644 --- a/lib/url_parser.js +++ b/lib/url_parser.js @@ -49,7 +49,8 @@ module.exports = function(url, options, callback) { } let connectionStrings = addresses.map(function(address, i) { - if (i === 0) return `mongodb://${address.name}:${address.port}`; + let base = result.auth ? `mongodb://${result.auth}@` : `mongodb://`; + if (i === 0) return `${base}${address.name}:${address.port}`; else return `${address.name}:${address.port}`; }); From c9084780ab112dc5154df0997dd2ffe30be0ff15 Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Wed, 17 Jan 2018 11:15:25 -0500 Subject: [PATCH 3/5] fix(url parser): move base definition out of loop --- lib/url_parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/url_parser.js b/lib/url_parser.js index c188759c58e..f2df82fcc1b 100644 --- a/lib/url_parser.js +++ b/lib/url_parser.js @@ -48,8 +48,8 @@ module.exports = function(url, options, callback) { } } + let base = result.auth ? `mongodb://${result.auth}@` : `mongodb://`; let connectionStrings = addresses.map(function(address, i) { - let base = result.auth ? `mongodb://${result.auth}@` : `mongodb://`; if (i === 0) return `${base}${address.name}:${address.port}`; else return `${address.name}:${address.port}`; }); From 1008742c8550d7fc6579b845b33a5d67905ef946 Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Thu, 18 Jan 2018 13:30:54 -0500 Subject: [PATCH 4/5] style(dns): rename dns seedlist test file --- test/functional/dns_txt_records_tests.js | 64 ------------------------ 1 file changed, 64 deletions(-) delete mode 100644 test/functional/dns_txt_records_tests.js diff --git a/test/functional/dns_txt_records_tests.js b/test/functional/dns_txt_records_tests.js deleted file mode 100644 index 4b11c535278..00000000000 --- a/test/functional/dns_txt_records_tests.js +++ /dev/null @@ -1,64 +0,0 @@ -'use strict'; - -var fs = require('fs'); -var path = require('path'); - -var parse = require('../../lib/url_parser'); -var expect = require('chai').expect; - -function getTests() { - return fs - .readdirSync(path.join(__dirname, 'spec/dns-txt-records')) - .filter(x => x.indexOf('json') !== -1) - .map(x => [x, fs.readFileSync(path.join(__dirname, 'spec/dns-txt-records', x), 'utf8')]) - .map(x => [path.basename(x[0], '.json'), JSON.parse(x[1])]); -} - -describe('DNS and TXT record tests', function() { - getTests().forEach(function(test) { - if (!test[1].comment) test[1].comment = test[0]; - - it(test[1].comment, { - metadata: { - requires: { topology: ['single'] } - }, - test: function(done) { - parse(test[1].uri, function(err, object) { - if (test[1].error) { - expect(err).to.exist; - expect(object).to.not.exist; - } else { - expect(err).to.be.null; - expect(object).to.exist; - if (test[1].options && test[1].options.replicaSet) { - expect(object.rs_options.rs_name).to.equal(test[1].options.replicaSet); - } - if (test[1].options && test[1].options.ssl) { - expect(object.server_options.ssl).to.equal(test[1].options.ssl); - } - } - done(); - }); - } - }); - }); - - it('preserves auth credentials in the connection string', { - metadata: { - requires: { topology: ['single'] } - }, - test: function(done) { - let user = 'auser'; - let password = 'apass'; - let uri = `mongodb+srv://${user}:${password}@test18.test.build.10gen.cc/?replicaSet=repl0`; - parse(uri, function(err, object) { - expect(err).to.not.exist; - expect(object.auth.user).to.not.be.undefined; - expect(object.auth.user).to.equal(user); - expect(object.auth.password).to.not.be.undefined; - expect(object.auth.password).to.equal(password); - done(); - }); - } - }); -}); From 9d937d671e18598406d94a2ec13b6b5b029906d4 Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Thu, 18 Jan 2018 13:49:38 -0500 Subject: [PATCH 5/5] style(dns): the actual renamed file --- test/functional/mongodb_srv_tests.js | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 test/functional/mongodb_srv_tests.js diff --git a/test/functional/mongodb_srv_tests.js b/test/functional/mongodb_srv_tests.js new file mode 100644 index 00000000000..4b11c535278 --- /dev/null +++ b/test/functional/mongodb_srv_tests.js @@ -0,0 +1,64 @@ +'use strict'; + +var fs = require('fs'); +var path = require('path'); + +var parse = require('../../lib/url_parser'); +var expect = require('chai').expect; + +function getTests() { + return fs + .readdirSync(path.join(__dirname, 'spec/dns-txt-records')) + .filter(x => x.indexOf('json') !== -1) + .map(x => [x, fs.readFileSync(path.join(__dirname, 'spec/dns-txt-records', x), 'utf8')]) + .map(x => [path.basename(x[0], '.json'), JSON.parse(x[1])]); +} + +describe('DNS and TXT record tests', function() { + getTests().forEach(function(test) { + if (!test[1].comment) test[1].comment = test[0]; + + it(test[1].comment, { + metadata: { + requires: { topology: ['single'] } + }, + test: function(done) { + parse(test[1].uri, function(err, object) { + if (test[1].error) { + expect(err).to.exist; + expect(object).to.not.exist; + } else { + expect(err).to.be.null; + expect(object).to.exist; + if (test[1].options && test[1].options.replicaSet) { + expect(object.rs_options.rs_name).to.equal(test[1].options.replicaSet); + } + if (test[1].options && test[1].options.ssl) { + expect(object.server_options.ssl).to.equal(test[1].options.ssl); + } + } + done(); + }); + } + }); + }); + + it('preserves auth credentials in the connection string', { + metadata: { + requires: { topology: ['single'] } + }, + test: function(done) { + let user = 'auser'; + let password = 'apass'; + let uri = `mongodb+srv://${user}:${password}@test18.test.build.10gen.cc/?replicaSet=repl0`; + parse(uri, function(err, object) { + expect(err).to.not.exist; + expect(object.auth.user).to.not.be.undefined; + expect(object.auth.user).to.equal(user); + expect(object.auth.password).to.not.be.undefined; + expect(object.auth.password).to.equal(password); + done(); + }); + } + }); +});