Skip to content

Commit

Permalink
fix: don't delete dbName if authSource is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Avilan committed Nov 26, 2021
1 parent 43c323d commit 8027af4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,6 @@ export function parseOptions(
}
}

if (urlOptions.has('authSource')) {
// If authSource is an explicit key in the urlOptions we need to remove the dbName
urlOptions.delete('dbName');
}

const objectOptions = new CaseInsensitiveMap(
Object.entries(options).filter(([, v]) => v != null)
);
Expand Down
11 changes: 11 additions & 0 deletions test/unit/connection_string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ describe('Connection String', function () {
expect(options.credentials.source).to.equal('0001');
});

it('should not remove dbName from the options if authSource is provided', function () {
const dbName = 'my-db-name';
const authSource = 'admin';
const options = parseOptions(
`mongodb://myName:myPassword@localhost:27017/${dbName}?authSource=${authSource}`
);

expect(options).has.property('dbName', dbName);
expect(options.credentials).to.have.property('source', authSource);
});

it('should parse a replicaSet with a leading number', function () {
const options = parseOptions('mongodb://localhost/?replicaSet=123abc');
expect(options).to.have.property('replicaSet');
Expand Down

0 comments on commit 8027af4

Please sign in to comment.