Skip to content

fix(NODE-3921): error on invalid TLS option combinations #3405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 4, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
remove export, update doc comment, change error type, move check
  • Loading branch information
biniona-mongodb committed Sep 11, 2022
commit 8b0ba59b4142237adaf19fa5bbe8c6195d2e34a0
13 changes: 6 additions & 7 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { ReadConcern, ReadConcernLevel } from './read_concern';
import { ReadPreference, ReadPreferenceMode } from './read_preference';
import type { TagSet } from './sdam/server_description';
import {
AnyOptions,
Callback,
DEFAULT_PK_FACTORY,
emitWarning,
Expand Down Expand Up @@ -166,14 +165,14 @@ export function resolveSRVRecord(options: MongoOptions, callback: Callback<HostA
/**
* Checks if TLS options are valid
*
* @param options - The options used for options parsing
* @throws MongoParseError if TLS options are invalid
* @param allOptions - all options provided by user
* @throws MongoAPIError if TLS options are invalid
*/
export function checkTLSOptions(allOptions: CaseInsensitiveMap): void {
function checkTLSOptions(allOptions: CaseInsensitiveMap): void {
if (!allOptions) return;
const check = (a: string, b: string) => {
if (allOptions.has(a) && allOptions.has(b)) {
throw new MongoParseError(`The '${a}' option cannot be used with '${b}'`);
throw new MongoAPIError(`The '${a}' option cannot be used with the '${b}' option`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this thread for context on why this error type was changed

}
};
check('tlsInsecure', 'tlsAllowInvalidCertificates');
Expand Down Expand Up @@ -369,6 +368,8 @@ export function parseOptions(
}
}

checkTLSOptions(allOptions);
Copy link
Contributor Author

@biniona-mongodb biniona-mongodb Sep 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed check to use allOptions from mongoOptions as mongoOptions object does not have key value pairs when value would be falsy.


const unsupportedOptions = setDifference(
allKeys,
Array.from(Object.keys(OPTIONS)).map(s => s.toLowerCase())
Expand Down Expand Up @@ -436,8 +437,6 @@ export function parseOptions(
mongoOptions.dbName = 'test';
}

checkTLSOptions(allOptions);

if (options.promiseLibrary) PromiseProvider.set(options.promiseLibrary);

const lbError = validateLoadBalancedOptions(hosts, mongoOptions, isSRV);
Expand Down