1
1
'use strict' ;
2
2
const { MongoClient } = require ( '../../src' ) ;
3
3
const chai = require ( 'chai' ) ;
4
+ const sinon = require ( 'sinon' ) ;
5
+ const dns = require ( 'dns' ) ;
4
6
5
7
const expect = chai . expect ;
8
+ chai . use ( require ( 'sinon-chai' ) ) ;
6
9
7
10
function verifyKerberosAuthentication ( client , done ) {
8
11
client
@@ -23,6 +26,16 @@ function verifyKerberosAuthentication(client, done) {
23
26
}
24
27
25
28
describe ( '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
+
26
39
if ( process . env . MONGODB_URI == null ) {
27
40
console . error ( 'skipping Kerberos tests, MONGODB_URI environment variable is not defined' ) ;
28
41
return ;
@@ -51,6 +64,28 @@ describe('Kerberos', function () {
51
64
} ) ;
52
65
} ) ;
53
66
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
+
54
89
// Unskip this test when a proper setup is available - see NODE-3060
55
90
it . skip ( 'validate that SERVICE_REALM and CANONICALIZE_HOST_NAME can be passed in' , function ( done ) {
56
91
const client = new MongoClient (
0 commit comments