11'use strict' ;
22const { MongoClient } = require ( '../../src' ) ;
33const chai = require ( 'chai' ) ;
4+ const sinon = require ( 'sinon' ) ;
5+ const dns = require ( 'dns' ) ;
46
57const expect = chai . expect ;
8+ chai . use ( require ( 'sinon-chai' ) ) ;
69
710function verifyKerberosAuthentication ( client , done ) {
811 client
@@ -23,6 +26,16 @@ function verifyKerberosAuthentication(client, done) {
2326}
2427
2528describe ( 'Kerberos' , function ( ) {
29+ const sandbox = sinon . createSandbox ( ) ;
30+
31+ beforeEach ( function ( ) {
32+ sandbox . spy ( dns ) ;
33+ } ) ;
34+
35+ afterEach ( function ( ) {
36+ sandbox . restore ( ) ;
37+ } ) ;
38+
2639 if ( process . env . MONGODB_URI == null ) {
2740 console . error ( 'skipping Kerberos tests, MONGODB_URI environment variable is not defined' ) ;
2841 return ;
@@ -51,6 +64,28 @@ describe('Kerberos', function () {
5164 } ) ;
5265 } ) ;
5366
67+ it ( 'validate that gssapiCanonicalizeHostName can be passed in' , function ( done ) {
68+ const client = new MongoClient (
69+ `${ krb5Uri } &authMechanismProperties=SERVICE_NAME:mongodb,gssapiCanonicalizeHostName:true&maxPoolSize=1`
70+ ) ;
71+ client . connect ( function ( err , client ) {
72+ if ( err ) return done ( err ) ;
73+ expect ( dns . resolveCname ) . to . be . calledOnce ;
74+ verifyKerberosAuthentication ( client , done ) ;
75+ } ) ;
76+ } ) ;
77+
78+ it ( 'validate that CANONICALIZE_HOST_NAME can be passed in' , function ( done ) {
79+ const client = new MongoClient (
80+ `${ krb5Uri } &authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:true&maxPoolSize=1`
81+ ) ;
82+ client . connect ( function ( err , client ) {
83+ if ( err ) return done ( err ) ;
84+ expect ( dns . resolveCname ) . to . be . calledOnce ;
85+ verifyKerberosAuthentication ( client , done ) ;
86+ } ) ;
87+ } ) ;
88+
5489 // Unskip this test when a proper setup is available - see NODE-3060
5590 it . skip ( 'validate that SERVICE_REALM and CANONICALIZE_HOST_NAME can be passed in' , function ( done ) {
5691 const client = new MongoClient (
0 commit comments