Skip to content

Commit 1195d3b

Browse files
committed
fix(NODE-5536): remove credentials from ConnectionPoolCreatedEvent options
1 parent 0c1b654 commit 1195d3b

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/cmap/connection_pool_events.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ export class ConnectionPoolMonitoringEvent {
2828
*/
2929
export class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
3030
/** The options used to create this connection pool */
31-
options?: ConnectionPoolOptions;
31+
options: Omit<ConnectionPoolOptions, 'credentials'> & { credentials?: Record<never, never> };
3232

3333
/** @internal */
3434
constructor(pool: ConnectionPool) {
3535
super(pool);
36-
this.options = pool.options;
36+
if (pool.options.credentials != null) {
37+
// Intentionally remove credentials: NODE-5460
38+
this.options = { ...pool.options, credentials: {} };
39+
} else {
40+
this.options = pool.options;
41+
}
3742
}
3843
}
3944

test/integration/connection-monitoring-and-pooling/connection_monitoring_and_pooling.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { expect } from 'chai';
2+
import { once } from 'events';
3+
4+
import { MongoClient } from '../../../src';
15
import { loadSpecTests } from '../../spec';
26
import { CmapTest, runCmapTestSuite } from '../../tools/cmap_spec_runner';
37

@@ -16,4 +20,37 @@ describe('Connection Monitoring and Pooling (Node Driver)', function () {
1620
}
1721
]
1822
});
23+
24+
describe('ConnectionPoolCreatedEvent', () => {
25+
let client: MongoClient;
26+
beforeEach(async function () {
27+
client = this.configuration.newClient();
28+
});
29+
30+
afterEach(async function () {
31+
await client.close();
32+
});
33+
34+
describe('constructor()', () => {
35+
it('when auth is enabled redacts credentials from options', {
36+
metadata: { requires: { auth: 'enabled' } },
37+
async test() {
38+
const poolCreated = once(client, 'connectionPoolCreated');
39+
await client.connect();
40+
const [event] = await poolCreated;
41+
expect(event).to.have.deep.nested.property('options.credentials', {});
42+
}
43+
});
44+
45+
it('when auth is disabled does not add a credentials property to options', {
46+
metadata: { requires: { auth: 'disabled' } },
47+
async test() {
48+
const poolCreated = once(client, 'connectionPoolCreated');
49+
await client.connect();
50+
const [event] = await poolCreated;
51+
expect(event).to.not.have.nested.property('options.credentials');
52+
}
53+
});
54+
});
55+
});
1956
});

0 commit comments

Comments
 (0)