Skip to content

Commit

Permalink
fix(mongo_client_ops): only skip authentication if no authMechanism i…
Browse files Browse the repository at this point in the history
…s specified

Fixes NODE-1840
  • Loading branch information
kvwalker committed Feb 15, 2019
1 parent 7664486 commit 3b6957d
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions lib/operations/mongo_client_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ function connect(mongoClient, url, options, callback) {
try {
_finalOptions.credentials = generateCredentials(
mongoClient,
_finalOptions.user,
_finalOptions.password,
_finalOptions.auth.user,
_finalOptions.auth.password,
_finalOptions
);
} catch (err) {
Expand Down Expand Up @@ -579,21 +579,14 @@ function transformUrlOptions(_object) {
object[camelCaseName] = object[name];
}
}
if (_object.auth) {
const auth = _object.auth;
for (let i in auth) {
if (auth[i]) {
object[i] = auth[i];
}
}

if (auth.username) {
object.auth = auth;
object.user = auth.username;
if (_object.auth) {
object.auth = Object.assign({}, _object.auth);
if (object.auth.db) {
object.authSource = object.authSource || object.auth.db;
}

if (auth.db) {
object.authSource = object.authSource || auth.db;
if (object.auth.username) {
object.auth.user = object.auth.username;
}
}

Expand Down

0 comments on commit 3b6957d

Please sign in to comment.