1+ import { expect } from 'chai' ;
2+ import { once } from 'events' ;
3+
4+ import { type MongoClient } from '../../mongodb' ;
15import { loadSpecTests } from '../../spec' ;
26import { type CmapTest , runCmapTestSuite } from '../../tools/cmap_spec_runner' ;
37import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner' ;
@@ -23,4 +27,49 @@ describe('Connection Monitoring and Pooling (Node Driver)', function () {
2327 '../integration/connection-monitoring-and-pooling/unified-cmap-node-specs'
2428 ) ;
2529 runUnifiedSuite ( unifiedTests ) ;
30+
31+ describe ( 'ConnectionPoolCreatedEvent' , ( ) => {
32+ let client : MongoClient ;
33+ beforeEach ( async function ( ) {
34+ client = this . configuration . newClient ( ) ;
35+ } ) ;
36+
37+ afterEach ( async function ( ) {
38+ await client . close ( ) ;
39+ } ) ;
40+
41+ describe ( 'constructor()' , ( ) => {
42+ it ( 'when auth is enabled redacts credentials from options' , {
43+ metadata : { requires : { auth : 'enabled' } } ,
44+ async test ( ) {
45+ const poolCreated = once ( client , 'connectionPoolCreated' ) ;
46+ await client . connect ( ) ;
47+ const [ event ] = await poolCreated ;
48+ expect ( event ) . to . have . deep . nested . property ( 'options.credentials' , { } ) ;
49+
50+ const poolOptions = Array . from ( client . topology ?. s . servers . values ( ) ?? [ ] ) . map (
51+ s => s . pool . options
52+ ) ;
53+ expect ( poolOptions ) . to . have . length . of . at . least ( 1 ) ;
54+
55+ for ( const { credentials = { } } of poolOptions ) {
56+ expect (
57+ Object . keys ( credentials ) ,
58+ 'pool.options.credentials must exist and have keys'
59+ ) . to . not . equal ( 0 ) ;
60+ }
61+ }
62+ } ) ;
63+
64+ it ( 'when auth is disabled does not add a credentials property to options' , {
65+ metadata : { requires : { auth : 'disabled' } } ,
66+ async test ( ) {
67+ const poolCreated = once ( client , 'connectionPoolCreated' ) ;
68+ await client . connect ( ) ;
69+ const [ event ] = await poolCreated ;
70+ expect ( event ) . to . not . have . nested . property ( 'options.credentials' ) ;
71+ }
72+ } ) ;
73+ } ) ;
74+ } ) ;
2675} ) ;
0 commit comments