Skip to content

Commit

Permalink
Merge pull request #1511 from cblancog00/master
Browse files Browse the repository at this point in the history
[FIX][ISSUE 1510] Solve failed authentication when using user and pas…
  • Loading branch information
fgalan authored Oct 11, 2023
2 parents 0d1ae90 + d65634c commit 21c0081
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fix: MongoDB connection authentication (user and password were not actually used) (#1510)
- Fix: add static attributes when use explicitAttrs (#1506)
- Remove: single configuration mode (along with IOTA_SINGLE_MODE env var) (#1469)
- Remove: extractVariables from jexl plugin (no needed anymore since the removal of bidireational plugin)
Expand Down
8 changes: 7 additions & 1 deletion lib/model/dbConn.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ function init(host, db, port, options, callback) {
return previous;
}

url = 'mongodb://';

if (options.auth) {
url += options.auth.user + ':' + options.auth.password + '@';
}

const hosts = host.split(',').map(addPort).reduce(commaConcat, '');

url = 'mongodb://' + hosts + '/' + db;
url += hosts + '/' + db;

if (options.extraArgs) {
if (options.extraArgs instanceof Object && Object.keys(options.extraArgs).length > 0) {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/mongodb/mongodb-connectionoptions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('dbConn.configureDb', function () {
password: 'pass01'
},
expected: {
url: 'mongodb://example.com:27017/' + dbConn.DEFAULT_DB_NAME,
url: 'mongodb://user01:pass01@example.com:27017/' + dbConn.DEFAULT_DB_NAME,
options: {
auth: {
user: 'user01',
Expand Down Expand Up @@ -190,7 +190,7 @@ describe('dbConn.configureDb', function () {
authSource: 'admin'
},
expected: {
url: 'mongodb://example.com:98765/examples',
url: 'mongodb://user01:pass01@example.com:98765/examples',
options: {
replicaSet: 'rs0',
auth: {
Expand Down Expand Up @@ -308,7 +308,7 @@ describe('dbConn.configureDb', function () {
unknownparam: 'unknown'
},
expected: {
url: 'mongodb://example.com:98765/examples?retryWrites=true&readPreference=nearest&w=majority',
url: 'mongodb://user01:pass01@example.com:98765/examples?retryWrites=true&readPreference=nearest&w=majority',
options: {
replicaSet: 'rs0',
auth: {
Expand Down

0 comments on commit 21c0081

Please sign in to comment.