Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/connection_string.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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