-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(NODE-3921): error on invalid TLS option combinations #3405
Changes from all commits
87096c6
8b0ba59
5bcf4a7
75cb6cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
DEFAULT_PK_FACTORY, | ||
emitWarning, | ||
emitWarningOnce, | ||
|
@@ -157,14 +156,14 @@ export async function resolveSRVRecord(options: MongoOptions): Promise<HostAddre | |
/** | ||
* 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 or included in default options map | ||
* @throws MongoAPIError if TLS options are invalid | ||
*/ | ||
export function checkTLSOptions(options: AnyOptions): void { | ||
if (!options) return; | ||
function checkTLSOptions(allOptions: CaseInsensitiveMap): void { | ||
if (!allOptions) return; | ||
const check = (a: string, b: string) => { | ||
if (Reflect.has(options, a) && Reflect.has(options, b)) { | ||
throw new MongoParseError(`The '${a}' option cannot be used with '${b}'`); | ||
if (allOptions.has(a) && allOptions.has(b)) { | ||
throw new MongoAPIError(`The '${a}' option cannot be used with the '${b}' option`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||
|
@@ -360,6 +359,8 @@ export function parseOptions( | |
} | ||
} | ||
|
||
checkTLSOptions(allOptions); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed check to use |
||
|
||
const unsupportedOptions = setDifference( | ||
allKeys, | ||
Array.from(Object.keys(OPTIONS)).map(s => s.toLowerCase()) | ||
|
@@ -427,8 +428,6 @@ export function parseOptions( | |
mongoOptions.dbName = 'test'; | ||
} | ||
|
||
checkTLSOptions(mongoOptions); | ||
|
||
if (options.promiseLibrary) { | ||
PromiseProvider.set(options.promiseLibrary); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
export
because AFAICTcheckTLSOptions
is not used outside this module and is not included in public API.