Skip to content
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-2026): support SERVICE_REALM authentication mechanism property #2865

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/cmap/auth/gssapi.ts
Expand Up @@ -7,6 +7,7 @@ import type { Document } from '../../bson';
type MechanismProperties = {
gssapiCanonicalizeHostName?: boolean;
SERVICE_NAME?: string;
SERVICE_REALM?: string;
};

import * as dns from 'dns';
Expand Down Expand Up @@ -90,14 +91,15 @@ function makeKerberosClient(authContext: AuthContext, callback: Callback<Kerbero
Object.assign(initOptions, { user: username, password: password });
}

initializeClient(
`${serviceName}${process.platform === 'win32' ? '/' : '@'}${host}`,
initOptions,
(err: string, client: KerberosClient): void => {
if (err) return callback(new MongoDriverError(err));
callback(undefined, client);
}
);
let spn = `${serviceName}${process.platform === 'win32' ? '/' : '@'}${host}`;
if ('SERVICE_REALM' in mechanismProperties) {
spn = `${spn}@${mechanismProperties.SERVICE_REALM}`;
}

initializeClient(spn, initOptions, (err: string, client: KerberosClient): void => {
if (err) return callback(new MongoDriverError(err));
callback(undefined, client);
});
}
);
}
Expand Down
4 changes: 2 additions & 2 deletions test/manual/kerberos.test.js
Expand Up @@ -50,8 +50,8 @@ describe('Kerberos', function () {
});
});

// TODO: this test only tests that these properties do not crash anything - but not that they actually have an effect
it('validate that SERVICE_REALM and CANONICALIZE_HOST_NAME can be passed in', function (done) {
// Unskip this test when a proper setup is available - see NODE-3060
it.skip('validate that SERVICE_REALM and CANONICALIZE_HOST_NAME can be passed in', function (done) {
const client = new MongoClient(
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:false,SERVICE_REALM:windows&maxPoolSize=1`
);
Expand Down