Skip to content

Commit ff3fc90

Browse files
committed
fix(NODE-2939): change canonicalization to enum
1 parent 447a49c commit ff3fc90

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/cmap/auth/gssapi.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ import { Callback, ns } from '../../utils';
1313
import { AuthContext, AuthProvider } from './auth_provider';
1414

1515
/** @public */
16-
export const CANONICALIZATION_VALUES = [
17-
true,
18-
false,
19-
'none',
20-
'forward',
21-
'forwardAndReverse'
22-
] as const;
16+
export const CanonicalizationProperties = Object.freeze({
17+
on: true,
18+
off: false,
19+
none: 'none',
20+
forward: 'forward',
21+
forwardAndReverse: 'forwardAndReverse'
22+
} as const);
2323

2424
/** @public */
25-
export type CanonicalizationProperties = typeof CANONICALIZATION_VALUES[number];
25+
export type CanonicalizationProperties =
26+
typeof CanonicalizationProperties[keyof typeof CanonicalizationProperties];
2627

2728
type MechanismProperties = {
2829
/** @deprecated use `CANONICALIZE_HOST_NAME` instead */
@@ -192,10 +193,15 @@ function performGssapiCanonicalizeHostName(
192193
callback: Callback<string>
193194
): void {
194195
const mode = mechanismProperties.CANONICALIZE_HOST_NAME;
195-
if (!mode || mode === 'none') return callback(undefined, host);
196+
if (!mode || mode === CanonicalizationProperties.none) {
197+
return callback(undefined, host);
198+
}
196199

197200
// If forward and reverse or true
198-
if (mode === true || mode === 'forwardAndReverse') {
201+
if (
202+
mode === CanonicalizationProperties.on ||
203+
mode === CanonicalizationProperties.forwardAndReverse
204+
) {
199205
// Perform the lookup of the ip address.
200206
dns.lookup(host, (error, address) => {
201207
// No ip found, return the error.

src/cmap/auth/mongo_credentials.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { Document } from '../../bson';
33
import { MongoAPIError, MongoMissingCredentialsError } from '../../error';
44
import { emitWarningOnce } from '../../utils';
5-
import { CANONICALIZATION_VALUES, CanonicalizationProperties } from './gssapi';
5+
import { CanonicalizationProperties } from './gssapi';
66
import { AUTH_MECHS_AUTH_SRC_EXTERNAL, AuthMechanism } from './providers';
77

88
// https://github.com./mongodb/specifications/blob/master/source/auth/auth.rst
@@ -170,7 +170,7 @@ export class MongoCredentials {
170170
}
171171

172172
const canonicalization = this.mechanismProperties.CANONICALIZE_HOST_NAME ?? false;
173-
if (!CANONICALIZATION_VALUES.includes(canonicalization)) {
173+
if (!Object.values(CanonicalizationProperties).includes(canonicalization)) {
174174
throw new MongoAPIError(`Invalid CANONICALIZE_HOST_NAME value: ${canonicalization}`);
175175
}
176176
}

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export type {
176176
ResumeToken,
177177
UpdateDescription
178178
} from './change_stream';
179-
export type { CANONICALIZATION_VALUES, CanonicalizationProperties } from './cmap/auth/gssapi';
179+
export type { CanonicalizationProperties } from './cmap/auth/gssapi';
180180
export type {
181181
AuthMechanismProperties,
182182
MongoCredentials,

0 commit comments

Comments
 (0)