Skip to content

Commit 9d7a19d

Browse files
committed
fix(NODE-5537): remove credentials from ConnectionPoolCreatedEvent options
1 parent c3b35b3 commit 9d7a19d

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OneOrMore } from './src/mongo_types';
1+
import { type OneOrMore } from './src/mongo_types';
22
import type { TestConfiguration } from './test/tools/runner/config';
33

44
declare global {

src/cmap/connection_pool_events.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,19 @@ export abstract class ConnectionPoolMonitoringEvent {
5454
*/
5555
export class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
5656
/** The options used to create this connection pool */
57-
options?: ConnectionPoolOptions;
57+
options: Omit<ConnectionPoolOptions, 'credentials'> & { credentials?: Record<never, never> };
5858
/** @internal */
5959
name = CONNECTION_POOL_CREATED;
6060

6161
/** @internal */
6262
constructor(pool: ConnectionPool) {
6363
super(pool);
64-
this.options = pool.options;
64+
if (pool.options.credentials != null) {
65+
// Intentionally remove credentials: NODE-5460
66+
this.options = { ...pool.options, credentials: {} };
67+
} else {
68+
this.options = pool.options;
69+
}
6570
}
6671
}
6772

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 { type MongoClient } from '../../mongodb';
15
import { loadSpecTests } from '../../spec';
26
import { type CmapTest, runCmapTestSuite } from '../../tools/cmap_spec_runner';
37
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
@@ -23,4 +27,37 @@ 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+
});
51+
52+
it('when auth is disabled does not add a credentials property to options', {
53+
metadata: { requires: { auth: 'disabled' } },
54+
async test() {
55+
const poolCreated = once(client, 'connectionPoolCreated');
56+
await client.connect();
57+
const [event] = await poolCreated;
58+
expect(event).to.not.have.nested.property('options.credentials');
59+
}
60+
});
61+
});
62+
});
2663
});

0 commit comments

Comments
 (0)