Skip to content

Commit 48137a1

Browse files
authored
feat(cli-repl): pass through sspiHostnameCanonicalization to driver MONGOSH-856 (#1231)
Pass down `sspiHostnameCanonicalization` to the driver as-is and let the driver do the validation. We still map `true` and `false` from strings to booleans and an empty string to `undefined`, since the driver would otherwise reject those values.
1 parent 1467075 commit 48137a1

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

packages/cli-repl/src/arg-mapper.spec.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ describe('arg-mapper.mapCliToDriver', () => {
320320

321321
it('is not mapped to authMechanismProperties', () => {
322322
expect(mapCliToDriver(cliOptions)).to.deep.equal({
323+
authMechanismProperties: {
324+
CANONICALIZE_HOST_NAME: 'none'
325+
},
323326
driverInfo: {
324327
name: 'mongosh',
325328
version: packageJSON.version
@@ -334,7 +337,7 @@ describe('arg-mapper.mapCliToDriver', () => {
334337
it('is mapped to authMechanismProperties', () => {
335338
expect(mapCliToDriver(cliOptions)).to.deep.equal({
336339
authMechanismProperties: {
337-
gssapiCanonicalizeHostName: 'true'
340+
CANONICALIZE_HOST_NAME: 'forward'
338341
},
339342
driverInfo: {
340343
name: 'mongosh',
@@ -344,17 +347,19 @@ describe('arg-mapper.mapCliToDriver', () => {
344347
});
345348
});
346349

347-
context('with a value of forwardAndReverse', () => {
348-
const cliOptions: CliOptions = { sspiHostnameCanonicalization: 'forwardAndReverse' };
350+
context('with a value of true', () => {
351+
const cliOptions: CliOptions = { sspiHostnameCanonicalization: 'true' };
349352

350353
it('is mapped to authMechanismProperties', () => {
351-
try {
352-
mapCliToDriver(cliOptions);
353-
} catch (e) {
354-
expect(e.message).to.contain('forwardAndReverse is not supported');
355-
return;
356-
}
357-
expect.fail('expected error');
354+
expect(mapCliToDriver(cliOptions)).to.deep.equal({
355+
authMechanismProperties: {
356+
CANONICALIZE_HOST_NAME: true
357+
},
358+
driverInfo: {
359+
name: 'mongosh',
360+
version: packageJSON.version
361+
}
362+
});
358363
});
359364
});
360365
});

packages/cli-repl/src/arg-mapper.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CommonErrors, MongoshInvalidInputError, MongoshUnimplementedError } from '@mongosh/errors';
1+
import { MongoshInvalidInputError, MongoshUnimplementedError } from '@mongosh/errors';
22
import { CliOptions, DevtoolsConnectOptions } from '@mongosh/service-provider-server';
33
import setValue from 'lodash.set';
44

@@ -15,7 +15,7 @@ const MAPPINGS = {
1515
awsIamSessionToken: 'authMechanismProperties.AWS_SESSION_TOKEN',
1616
gssapiServiceName: 'authMechanismProperties.SERVICE_NAME',
1717
sspiRealmOverride: 'authMechanismProperties.SERVICE_REALM',
18-
sspiHostnameCanonicalization: { opt: 'authMechanismProperties.gssapiCanonicalizeHostName', fun: mapSspiHostnameCanonicalization },
18+
sspiHostnameCanonicalization: { opt: 'authMechanismProperties.CANONICALIZE_HOST_NAME', fun: mapGSSAPIHostnameCanonicalization },
1919
authenticationDatabase: 'authSource',
2020
authenticationMechanism: 'authMechanism',
2121
keyVaultNamespace: 'autoEncryption.keyVaultNamespace',
@@ -125,17 +125,16 @@ function getCertificateExporter(): TlsCertificateExporter | undefined {
125125
return undefined;
126126
}
127127

128-
function mapSspiHostnameCanonicalization(value: string): string | undefined {
129-
if (!value || value === 'none') {
128+
function mapGSSAPIHostnameCanonicalization(value: string): string | boolean | undefined {
129+
// Here for backwards compatibility reasons -- ideally, users should always
130+
// just either not specify this, or use none/forward/forwardAndReverse.
131+
if (value === '') {
130132
return undefined;
131133
}
132-
if (value === 'forward') {
133-
return 'true';
134+
if (value === 'true' || value === 'false') {
135+
return value === 'true';
134136
}
135-
throw new MongoshInvalidInputError(
136-
`--sspiHostnameCanonicalization value ${value} is not supported`,
137-
CommonErrors.InvalidArgument
138-
);
137+
return value;
139138
}
140139

141140
export default mapCliToDriver;

0 commit comments

Comments
 (0)