Skip to content

Commit

Permalink
fix(url parser): preserve auth creds when composing conn string (#1640)
Browse files Browse the repository at this point in the history
Fixes NODE-1286
  • Loading branch information
Jessica Lord authored Jan 19, 2018
1 parent d9fb750 commit eddca5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/url_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ module.exports = function(url, options, callback) {
}
}

let base = result.auth ? `mongodb://${result.auth}@` : `mongodb://`;
let connectionStrings = addresses.map(function(address, i) {
if (i === 0) return `mongodb://${address.name}:${address.port}`;
if (i === 0) return `${base}${address.name}:${address.port}`;
else return `${address.name}:${address.port}`;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
});
});

0 comments on commit eddca5e

Please sign in to comment.