-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(url parser): preserve auth creds when composing conn string #1640
Conversation
lib/url_parser.js
Outdated
@@ -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://`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you compute base
outside of the loop so that you don't do it on every iteration?
This still doesn't seem to work correctly for me.
becoming:
when parser.parse returns the parsed object it decodes the password to be '3#f!69A8AZu9', Note that the new NodeJS URL API whereby one says:
behaves differently and does not decode the password |
@IrishAfrican thanks so much for reporting this! I've made a ticket for us in JIRA and we'll make the fix 👍 |
Thanks Jessica. On a different but related issue, the latest driver may have a problem with the case whereby the auth database and the database being connected to, no longer works correctly, or at least not from 3rd party systems such as Mongoose. The MongoDB Atlas, says that even on a v3.6 compliant driver I should use the /mytestdb syntax to set my database name even though I authenticate against the admin database as shown in my example previously
In the case of Mongoose they use the MongoDB driver library url_parser to parse the URL and get the DB name. In the latest version of the driver this seems to return 'admin'. If I use the 3.4 syntax as shown below it seems to work fine:
I am not sure if you would consider this a bug as it does not seem that the URL Parser is supposed to be a public API, but the url_parser does seem to have code that tries to set dbName to something other than its default of 'admin' in certain cases, and it works for the 3.4 syntax so I am assuming it is a bug. Obviously, if you feel that this is not a bug and Mongoose should not be using the MongoDB parser I will log an issue on their side. Thanks |
@IrishAfrican please file a ticket on JIRA to discuss this, thanks! |
Cool, have done: NODE-1321 |
Preserve the auth credentials used with a dns/txt record uri when composing a new connection string for the url parser.
This fix will also be backported to 2.2 which got support for dns/txt records.
NODE-1286