From bd4552224382ff5236264fa88663f5c557d063e3 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Tue, 8 Feb 2022 14:48:21 +0100 Subject: [PATCH] test(NODE-3351): accept gssapiCanonicalizeHostName --- src/cmap/auth/mongo_credentials.ts | 5 +++++ test/manual/kerberos.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/cmap/auth/mongo_credentials.ts b/src/cmap/auth/mongo_credentials.ts index 6f0e453ed3..096f2180da 100644 --- a/src/cmap/auth/mongo_credentials.ts +++ b/src/cmap/auth/mongo_credentials.ts @@ -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); } diff --git a/test/manual/kerberos.test.js b/test/manual/kerberos.test.js index f792a7f8a2..45b8f59add 100644 --- a/test/manual/kerberos.test.js +++ b/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; @@ -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; @@ -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); }); });