Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2335

Node Driver does not follow Initial DNS Seedlist Discovery spec

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.5, 3.4.0
    • Affects Version/s: 3.3.4, 3.3.5
    • Component/s: Core

      According to https://github.com/mongodb/specifications/blob/master/source/initial-dns-seedlist-discovery/initial-dns-seedlist-discovery.rst

      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.

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            miguel@miguelpilar.com Miguel Pilar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: