Skip to content

Commit

Permalink
test(NODE-3351): accept gssapiCanonicalizeHostName
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Feb 8, 2022
1 parent 44abf04 commit bd45522
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cmap/auth/mongo_credentials.ts
Expand Up @@ -89,6 +89,11 @@ export class MongoCredentials {
}
}

if ('gssapiCanonicalizeHostName' in this.mechanismProperties) {
this.mechanismProperties.CANONICALIZE_HOST_NAME =
this.mechanismProperties.gssapiCanonicalizeHostName;
}

Object.freeze(this.mechanismProperties);
Object.freeze(this);
}
Expand Down
24 changes: 24 additions & 0 deletions test/manual/kerberos.test.js
@@ -1,6 +1,8 @@
'use strict';
const { MongoClient } = require('../../src');
const chai = require('chai');
const sinon = require('sinon');
const dns = require('dns');

const expect = chai.expect;

Expand All @@ -23,6 +25,16 @@ function verifyKerberosAuthentication(client, done) {
}

describe('Kerberos', function () {
const sandbox = sinon.createSandbox();

beforeEach(function () {
sandbox.spy(dns);
});

afterEach(function () {
sandbox.restore();
});

if (process.env.MONGODB_URI == null) {
console.error('skipping Kerberos tests, MONGODB_URI environment variable is not defined');
return;
Expand Down Expand Up @@ -51,12 +63,24 @@ describe('Kerberos', function () {
});
});

it('validate that gssapiCanonicalizeHostName can be passed in', function (done) {
const client = new MongoClient(
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,gssapiCanonicalizeHostName:true&maxPoolSize=1`
);
client.connect(function (err, client) {
if (err) return done(err);
expect(dns.resolveCname.calledOnce);
verifyKerberosAuthentication(client, done);
});
});

it('validate that CANONICALIZE_HOST_NAME can be passed in', function (done) {
const client = new MongoClient(
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:true&maxPoolSize=1`
);
client.connect(function (err, client) {
if (err) return done(err);
expect(dns.resolveCname.calledOnce);
verifyKerberosAuthentication(client, done);
});
});
Expand Down

0 comments on commit bd45522

Please sign in to comment.