@@ -41,6 +41,7 @@ describe('Kerberos', function () {
4141 return ;
4242 }
4343 let krb5Uri = process . env . MONGODB_URI ;
44+ const parts = krb5Uri . split ( '@' , 2 ) ;
4445
4546 if ( ! process . env . KRB5_PRINCIPAL ) {
4647 console . error ( 'skipping Kerberos tests, KRB5_PRINCIPAL environment variable is not defined' ) ;
@@ -52,7 +53,6 @@ describe('Kerberos', function () {
5253 if ( process . env . LDAPTEST_PASSWORD == null ) {
5354 throw new Error ( 'The env parameter LDAPTEST_PASSWORD must be set' ) ;
5455 }
55- const parts = krb5Uri . split ( '@' , 2 ) ;
5656 krb5Uri = `${ parts [ 0 ] } :${ process . env . LDAPTEST_PASSWORD } @${ parts [ 1 ] } ` ;
5757 }
5858
@@ -65,6 +65,10 @@ describe('Kerberos', function () {
6565 } ) ;
6666
6767 it ( 'validate that gssapiCanonicalizeHostName can be passed in' , function ( done ) {
68+ if ( process . platform === 'darwin' ) {
69+ this . test . skipReason = 'DNS does not resolve with proper CNAME record on evergreen MacOS' ;
70+ this . skip ( ) ;
71+ }
6872 const client = new MongoClient (
6973 `${ krb5Uri } &authMechanismProperties=SERVICE_NAME:mongodb,gssapiCanonicalizeHostName:true&maxPoolSize=1`
7074 ) ;
@@ -76,6 +80,10 @@ describe('Kerberos', function () {
7680 } ) ;
7781
7882 it ( 'validate that CANONICALIZE_HOST_NAME can be passed in' , function ( done ) {
83+ if ( process . platform === 'darwin' ) {
84+ this . test . skipReason = 'DNS does not resolve with proper CNAME record on evergreen MacOS' ;
85+ this . skip ( ) ;
86+ }
7987 const client = new MongoClient (
8088 `${ krb5Uri } &authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:true&maxPoolSize=1`
8189 ) ;
@@ -97,6 +105,42 @@ describe('Kerberos', function () {
97105 } ) ;
98106 } ) ;
99107
108+ context ( 'when passing SERVICE_HOST as an auth mech option' , function ( ) {
109+ context ( 'when the SERVICE_HOST is invalid' , function ( ) {
110+ const client = new MongoClient ( `${ krb5Uri } &maxPoolSize=1` , {
111+ authMechanismProperties : {
112+ SERVICE_HOST : 'example.com'
113+ }
114+ } ) ;
115+
116+ it ( 'fails to authenticate' , async function ( ) {
117+ let expectedError ;
118+ await client . connect ( ) . catch ( e => {
119+ expectedError = e ;
120+ } ) ;
121+ if ( ! expectedError ) {
122+ expect . fail ( 'Expected connect with invalid SERVICE_HOST to fail' ) ;
123+ }
124+ expect ( expectedError . message ) . to . match ( / G S S f a i l u r e | U N K N O W N _ S E R V E R / ) ;
125+ } ) ;
126+ } ) ;
127+
128+ context ( 'when the SERVICE_HOST is valid' , function ( ) {
129+ const client = new MongoClient ( `${ krb5Uri } &maxPoolSize=1` , {
130+ authMechanismProperties : {
131+ SERVICE_HOST : 'ldaptest.10gen.cc'
132+ }
133+ } ) ;
134+
135+ it ( 'authenticates' , function ( done ) {
136+ client . connect ( function ( err , client ) {
137+ expect ( err ) . to . not . exist ;
138+ verifyKerberosAuthentication ( client , done ) ;
139+ } ) ;
140+ } ) ;
141+ } ) ;
142+ } ) ;
143+
100144 describe ( 'should use the SERVICE_NAME property' , function ( ) {
101145 it ( 'as an option handed to the MongoClient' , function ( done ) {
102146 const client = new MongoClient ( `${ krb5Uri } &maxPoolSize=1` , {
0 commit comments