@@ -296,4 +296,44 @@ describe('MongoOptions', function () {
296
296
expect ( options . credentials . username ) . to . equal ( 'USERNAME' ) ;
297
297
expect ( options . credentials . password ) . to . equal ( 'PASSWORD' ) ;
298
298
} ) ;
299
+
300
+ it ( 'transforms tlsAllowInvalidCertificates and tlsAllowInvalidHostnames correctly' , function ( ) {
301
+ const optionsTrue = parseOptions ( 'mongodb://localhost/' , {
302
+ tlsAllowInvalidCertificates : true ,
303
+ tlsAllowInvalidHostnames : true
304
+ } ) ;
305
+ expect ( optionsTrue . rejectUnauthorized ) . to . equal ( false ) ;
306
+ expect ( optionsTrue . checkServerIdentity ) . to . be . a ( 'function' ) ;
307
+ expect ( optionsTrue . checkServerIdentity ( ) ) . to . equal ( undefined ) ;
308
+
309
+ const optionsFalse = parseOptions ( 'mongodb://localhost/' , {
310
+ tlsAllowInvalidCertificates : false ,
311
+ tlsAllowInvalidHostnames : false
312
+ } ) ;
313
+ expect ( optionsFalse . rejectUnauthorized ) . to . equal ( true ) ;
314
+ expect ( optionsFalse . checkServerIdentity ) . to . equal ( undefined ) ;
315
+
316
+ const optionsUndefined = parseOptions ( 'mongodb://localhost/' ) ;
317
+ expect ( optionsUndefined . rejectUnauthorized ) . to . equal ( undefined ) ;
318
+ expect ( optionsUndefined . checkServerIdentity ) . to . equal ( undefined ) ;
319
+ } ) ;
320
+
321
+ it ( 'transforms tlsInsecure correctly' , function ( ) {
322
+ const optionsTrue = parseOptions ( 'mongodb://localhost/' , {
323
+ tlsInsecure : true
324
+ } ) ;
325
+ expect ( optionsTrue . rejectUnauthorized ) . to . equal ( false ) ;
326
+ expect ( optionsTrue . checkServerIdentity ) . to . be . a ( 'function' ) ;
327
+ expect ( optionsTrue . checkServerIdentity ( ) ) . to . equal ( undefined ) ;
328
+
329
+ const optionsFalse = parseOptions ( 'mongodb://localhost/' , {
330
+ tlsInsecure : false
331
+ } ) ;
332
+ expect ( optionsFalse . rejectUnauthorized ) . to . equal ( true ) ;
333
+ expect ( optionsFalse . checkServerIdentity ) . to . equal ( undefined ) ;
334
+
335
+ const optionsUndefined = parseOptions ( 'mongodb://localhost/' ) ;
336
+ expect ( optionsUndefined . rejectUnauthorized ) . to . equal ( undefined ) ;
337
+ expect ( optionsUndefined . checkServerIdentity ) . to . equal ( undefined ) ;
338
+ } ) ;
299
339
} ) ;
0 commit comments