Skip to content

Commit

Permalink
fix(NODE-4518): error message with invalid authMechanism is provided …
Browse files Browse the repository at this point in the history
…(#undefined)
  • Loading branch information
baileympearson committed Mar 15, 2023
1 parent f42cb3d commit 1a16b7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/connection_string.ts
Expand Up @@ -403,7 +403,7 @@ export function parseOptions(
) {
// If authSource was explicitly given and its incorrect, we error
throw new MongoParseError(
`${mongoOptions.credentials} can only have authSource set to '$external'`
`authMechanism ${mongoOptions.credentials.mechanism} requires an authSource of '$external'`
);
}

Expand Down
12 changes: 12 additions & 0 deletions test/unit/connection_string.test.ts
Expand Up @@ -237,6 +237,18 @@ describe('Connection String', function () {
expect(options).to.not.have.property('credentials');
});

for (const mechanism of ['GSSAPI', 'MONGODB-X509']) {
context(`when the authMechanism is ${mechanism} and authSource is NOT $external`, function () {
it('throws a MongoParseError', function () {
expect(() =>
parseOptions(`mongodb+srv://hostname/?authMechanism=${mechanism}&authSource=invalid`)
)
.to.throw(MongoParseError)
.to.match(/requires an authSource of '\$external'/);
});
});
}

it('should omit credentials and not throw a MongoAPIError if the only auth related option is authSource', async () => {
// The error we're looking to **not** see is
// `new MongoInvalidArgumentError('No AuthProvider for ${credentials.mechanism} defined.')`
Expand Down

0 comments on commit 1a16b7e

Please sign in to comment.