Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 15 additions & 10 deletions packages/cli-repl/src/arg-mapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ describe('arg-mapper.mapCliToDriver', () => {

it('is not mapped to authMechanismProperties', () => {
expect(mapCliToDriver(cliOptions)).to.deep.equal({
authMechanismProperties: {
CANONICALIZE_HOST_NAME: 'none'
},
driverInfo: {
name: 'mongosh',
version: packageJSON.version
Expand All @@ -334,7 +337,7 @@ describe('arg-mapper.mapCliToDriver', () => {
it('is mapped to authMechanismProperties', () => {
expect(mapCliToDriver(cliOptions)).to.deep.equal({
authMechanismProperties: {
gssapiCanonicalizeHostName: 'true'
CANONICALIZE_HOST_NAME: 'forward'
},
driverInfo: {
name: 'mongosh',
Expand All @@ -344,17 +347,19 @@ describe('arg-mapper.mapCliToDriver', () => {
});
});

context('with a value of forwardAndReverse', () => {
const cliOptions: CliOptions = { sspiHostnameCanonicalization: 'forwardAndReverse' };
context('with a value of true', () => {
const cliOptions: CliOptions = { sspiHostnameCanonicalization: 'true' };

it('is mapped to authMechanismProperties', () => {
try {
mapCliToDriver(cliOptions);
} catch (e) {
expect(e.message).to.contain('forwardAndReverse is not supported');
return;
}
expect.fail('expected error');
expect(mapCliToDriver(cliOptions)).to.deep.equal({
authMechanismProperties: {
CANONICALIZE_HOST_NAME: true
},
driverInfo: {
name: 'mongosh',
version: packageJSON.version
}
});
});
});
});
Expand Down
19 changes: 9 additions & 10 deletions packages/cli-repl/src/arg-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommonErrors, MongoshInvalidInputError, MongoshUnimplementedError } from '@mongosh/errors';
import { MongoshInvalidInputError, MongoshUnimplementedError } from '@mongosh/errors';
import { CliOptions, DevtoolsConnectOptions } from '@mongosh/service-provider-server';
import setValue from 'lodash.set';

Expand All @@ -15,7 +15,7 @@ const MAPPINGS = {
awsIamSessionToken: 'authMechanismProperties.AWS_SESSION_TOKEN',
gssapiServiceName: 'authMechanismProperties.SERVICE_NAME',
sspiRealmOverride: 'authMechanismProperties.SERVICE_REALM',
sspiHostnameCanonicalization: { opt: 'authMechanismProperties.gssapiCanonicalizeHostName', fun: mapSspiHostnameCanonicalization },
sspiHostnameCanonicalization: { opt: 'authMechanismProperties.CANONICALIZE_HOST_NAME', fun: mapGSSAPIHostnameCanonicalization },
authenticationDatabase: 'authSource',
authenticationMechanism: 'authMechanism',
keyVaultNamespace: 'autoEncryption.keyVaultNamespace',
Expand Down Expand Up @@ -125,17 +125,16 @@ function getCertificateExporter(): TlsCertificateExporter | undefined {
return undefined;
}

function mapSspiHostnameCanonicalization(value: string): string | undefined {
if (!value || value === 'none') {
function mapGSSAPIHostnameCanonicalization(value: string): string | boolean | undefined {
// Here for backwards compatibility reasons -- ideally, users should always
// just either not specify this, or use none/forward/forwardAndReverse.
if (value === '') {
return undefined;
}
if (value === 'forward') {
return 'true';
if (value === 'true' || value === 'false') {
return value === 'true';
}
throw new MongoshInvalidInputError(
`--sspiHostnameCanonicalization value ${value} is not supported`,
CommonErrors.InvalidArgument
);
return value;
}

export default mapCliToDriver;