Skip to content

Commit 1a550df

Browse files
authoredOct 4, 2022
fix(NODE-3921): error on invalid TLS option combinations (#3405)
1 parent dc62bcb commit 1a550df

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed
 

‎src/connection_string.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { ReadConcern, ReadConcernLevel } from './read_concern';
2929
import { ReadPreference, ReadPreferenceMode } from './read_preference';
3030
import type { TagSet } from './sdam/server_description';
3131
import {
32-
AnyOptions,
3332
DEFAULT_PK_FACTORY,
3433
emitWarning,
3534
emitWarningOnce,
@@ -157,14 +156,14 @@ export async function resolveSRVRecord(options: MongoOptions): Promise<HostAddre
157156
/**
158157
* Checks if TLS options are valid
159158
*
160-
* @param options - The options used for options parsing
161-
* @throws MongoParseError if TLS options are invalid
159+
* @param allOptions - All options provided by user or included in default options map
160+
* @throws MongoAPIError if TLS options are invalid
162161
*/
163-
export function checkTLSOptions(options: AnyOptions): void {
164-
if (!options) return;
162+
function checkTLSOptions(allOptions: CaseInsensitiveMap): void {
163+
if (!allOptions) return;
165164
const check = (a: string, b: string) => {
166-
if (Reflect.has(options, a) && Reflect.has(options, b)) {
167-
throw new MongoParseError(`The '${a}' option cannot be used with '${b}'`);
165+
if (allOptions.has(a) && allOptions.has(b)) {
166+
throw new MongoAPIError(`The '${a}' option cannot be used with the '${b}' option`);
168167
}
169168
};
170169
check('tlsInsecure', 'tlsAllowInvalidCertificates');
@@ -360,6 +359,8 @@ export function parseOptions(
360359
}
361360
}
362361

362+
checkTLSOptions(allOptions);
363+
363364
const unsupportedOptions = setDifference(
364365
allKeys,
365366
Array.from(Object.keys(OPTIONS)).map(s => s.toLowerCase())
@@ -427,8 +428,6 @@ export function parseOptions(
427428
mongoOptions.dbName = 'test';
428429
}
429430

430-
checkTLSOptions(mongoOptions);
431-
432431
if (options.promiseLibrary) {
433432
PromiseProvider.set(options.promiseLibrary);
434433
}

‎test/unit/assorted/uri_options.spec.test.ts

-10
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ describe('URI option spec tests', function () {
1010
// Skipped because this does not apply to Node
1111
'Valid options specific to single-threaded drivers are parsed correctly',
1212

13-
// TODO(NODE-3921): fix tls option validation
14-
'tlsInsecure and tlsAllowInvalidCertificates both present (and true) raises an error',
15-
'tlsInsecure and tlsAllowInvalidCertificates both present (and false) raises an error',
16-
'tlsAllowInvalidCertificates and tlsInsecure both present (and true) raises an error',
17-
'tlsAllowInvalidCertificates and tlsInsecure both present (and false) raises an error',
18-
'tlsAllowInvalidHostnames and tlsInsecure both present (and true) raises an error',
19-
'tlsAllowInvalidHostnames and tlsInsecure both present (and false) raises an error',
20-
'tlsInsecure and tlsAllowInvalidHostnames both present (and true) raises an error',
21-
'tlsInsecure and tlsAllowInvalidHostnames both present (and false) raises an error',
22-
2313
// TODO(NODE-3922): have not implemented option support
2414
'tlsDisableCertificateRevocationCheck can be set to true',
2515
'tlsDisableCertificateRevocationCheck can be set to false',

0 commit comments

Comments
 (0)
Please sign in to comment.