-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.3.4, 3.3.5
-
Component/s: Core
-
(copied to CRM)
-
Empty show more show less
A Client MUST use options specified in the Connection String, and options passed in as parameters in code to the MongoClient constructor (or equivalent API for each driver), to override options provided through TXT records.
Further down as an example:
Then the default in the TXT record for authSource is not used as the value in the connection string overrides it. The Client MUST treat the host information as if the following URI was used instead:
The documentation for mongodb () also provides the following example:
Given the override for the authSource, the equivalent connection string in the standard format would be: mongodb://mongodb1.example.com:27317,mongodb2.example.com:27017/?connectTimeoutMS=300000&replicaSet=mySet&authSource=aDifferentAuthDB
The spec tests in the driver also include a test for this:
https://github.com/mongodb/node-mongodb-native/blob/master/test/core/spec/initial-dns-seedlist-discovery/txt-record-with-overridden-uri-option.json
But it is not processed correctly:
https://github.com/mongodb/node-mongodb-native/blob/master/test/core/unit/mongodb_srv_tests.js#L40-L46
To reproduce there are two options:
- Fix the test and run the unit tests and see there's a failure.
- Run this minimal code:
const MongoClient = require('mongodb').MongoClient; const assert = require('assert'); const url = 'mongodb+srv://userInOtherDB:password@test5.test.build.10gen.cc/?authSource=otherDB'; // Database Name const dbName = 'someDB'; // Create a new MongoClient const client = new MongoClient(url, { useNewUrlParser: true, useUnifiedTopology: true }); // Use connect method to connect to the Server client.connect(function(err) { assert.equal(null, err); console.log("Connected successfully to server"); const db = client.db(dbName); client.close(); });
The code will fail if the user exists in otherDB and not in the TXT record defined thisDB.
I have a PR ready for this which I will post forthwith.