From 97819f26fe2098e31824c7ba498f870030fea40c Mon Sep 17 00:00:00 2001 From: Aleksander Binion Date: Sat, 3 Sep 2022 20:34:57 -0400 Subject: [PATCH 1/4] add check, update test --- src/connection_string.ts | 6 ++++++ test/unit/assorted/auth.spec.test.ts | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/connection_string.ts b/src/connection_string.ts index 4aefe33d6a..07a4abd3bf 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -407,6 +407,12 @@ export function parseOptions( }); } + if (isAws && mongoOptions.credentials.username && !mongoOptions.credentials.password) { + throw new MongoParseError( + `${mongoOptions.credentials} must receive a password 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); }); } From ae4e5103110cd0439f4131331f70d6ff9378972e Mon Sep 17 00:00:00 2001 From: Aleksander Binion Date: Sun, 4 Sep 2022 14:50:35 -0400 Subject: [PATCH 2/4] make error more specific --- src/connection_string.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connection_string.ts b/src/connection_string.ts index 07a4abd3bf..1ee3fd36b8 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -409,7 +409,7 @@ export function parseOptions( if (isAws && mongoOptions.credentials.username && !mongoOptions.credentials.password) { throw new MongoParseError( - `${mongoOptions.credentials} must receive a password when a username is specified` + `${mongoOptions.credentials.mechanism} must receive a password when a username is specified` ); } From 89ef7d3ecc5e55601f84a51b5267398328e05e84 Mon Sep 17 00:00:00 2001 From: Aleksander Binion Date: Mon, 5 Sep 2022 21:30:13 -0400 Subject: [PATCH 3/4] wording change --- src/connection_string.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connection_string.ts b/src/connection_string.ts index 1ee3fd36b8..4b0ba256e2 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -409,7 +409,7 @@ export function parseOptions( if (isAws && mongoOptions.credentials.username && !mongoOptions.credentials.password) { throw new MongoParseError( - `${mongoOptions.credentials.mechanism} must receive a password when a username is specified` + `When using ${mongoOptions.credentials.mechanism} password must be set when a username is specified` ); } From fb319ebee658f7fd2c23bd48bfc5dcf6138b2524 Mon Sep 17 00:00:00 2001 From: Aleksander Binion Date: Tue, 6 Sep 2022 10:42:28 -0400 Subject: [PATCH 4/4] use missing credentials error --- src/connection_string.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/connection_string.ts b/src/connection_string.ts index 4b0ba256e2..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, @@ -408,7 +413,7 @@ export function parseOptions( } if (isAws && mongoOptions.credentials.username && !mongoOptions.credentials.password) { - throw new MongoParseError( + throw new MongoMissingCredentialsError( `When using ${mongoOptions.credentials.mechanism} password must be set when a username is specified` ); }