diff --git a/src/connection_string.ts b/src/connection_string.ts index 4aefe33d6a..3b0bb2dd7a 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -8,7 +8,12 @@ import { MongoCredentials } from './cmap/auth/mongo_credentials'; import { AUTH_MECHS_AUTH_SRC_EXTERNAL, AuthMechanism } from './cmap/auth/providers'; import { Compressor, CompressorName } from './cmap/wire_protocol/compression'; import { Encrypter } from './encrypter'; -import { MongoAPIError, MongoInvalidArgumentError, MongoParseError } from './error'; +import { + MongoAPIError, + MongoInvalidArgumentError, + MongoMissingCredentialsError, + MongoParseError +} from './error'; import { Logger, LoggerLevel } from './logger'; import { DriverInfo, @@ -407,6 +412,12 @@ export function parseOptions( }); } + if (isAws && mongoOptions.credentials.username && !mongoOptions.credentials.password) { + throw new MongoMissingCredentialsError( + `When using ${mongoOptions.credentials.mechanism} password must be set when a username is specified` + ); + } + mongoOptions.credentials.validate(); // Check if the only auth related option provided was authSource, if so we can remove credentials diff --git a/test/unit/assorted/auth.spec.test.ts b/test/unit/assorted/auth.spec.test.ts index e205bad3fc..560ec28462 100644 --- a/test/unit/assorted/auth.spec.test.ts +++ b/test/unit/assorted/auth.spec.test.ts @@ -1,8 +1,6 @@ import { loadSpecTests } from '../../spec'; import { executeUriValidationTest } from '../../tools/uri_spec_runner'; -const SKIP = ['should throw an exception if username and no password (MONGODB-AWS)']; - describe('Auth option spec tests', function () { const suites = loadSpecTests('auth'); @@ -10,10 +8,6 @@ describe('Auth option spec tests', function () { describe(suite.name, function () { for (const test of suite.tests) { it(`${test.description}`, function () { - if (SKIP.includes(test.description)) { - this.test.skipReason = 'NODE-3986: Fix MONGODB-AWS Spec Test'; - this.skip(); - } executeUriValidationTest(test); }); }