Skip to content

Commit

Permalink
fix(NODE-2026): support SERVICE_REALM authentication mechanism property
Browse files Browse the repository at this point in the history
  • Loading branch information
rose-m committed Jul 1, 2021
1 parent 05035eb commit c0544fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/cmap/auth/gssapi.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit c0544fa

Please sign in to comment.