Skip to content

Commit 1039f1d

Browse files
authored
feat(devtools-proxy-support): support Node.js allowPartialTrustChain flag COMPASS-8253 (#476)
This should allow getting back to faster startup times in mongosh.
1 parent b9f28be commit 1039f1d

File tree

12 files changed

+248
-60
lines changed

12 files changed

+248
-60
lines changed

package-lock.json

Lines changed: 40 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/devtools-connect/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
},
5656
"peerDependencies": {
5757
"@mongodb-js/oidc-plugin": "^1.1.0",
58-
"mongodb": "^6.8.0",
58+
"mongodb": "^6.9.0",
5959
"mongodb-log-writer": "^1.4.2"
6060
},
6161
"devDependencies": {
@@ -75,7 +75,7 @@
7575
"eslint-plugin-promise": "^6.1.1",
7676
"gen-esm-wrapper": "^1.1.0",
7777
"mocha": "^8.4.0",
78-
"mongodb": "^6.8.0",
78+
"mongodb": "^6.9.0",
7979
"mongodb-log-writer": "^1.4.2",
8080
"nyc": "^15.1.0",
8181
"os-dns-native": "^1.2.0",

packages/devtools-connect/src/connect.spec.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('devtools connect', function () {
5151
expect(mClientType.getCalls()[0].args[0]).to.equal(uri);
5252
expect(
5353
Object.keys(mClientType.getCalls()[0].args[1]).sort()
54-
).to.deep.equal(['ca', 'lookup']);
54+
).to.deep.equal(['allowPartialTrustChain', 'ca', 'lookup']);
5555
expect(mClient.connect.getCalls()).to.have.lengthOf(1);
5656
expect(result.client).to.equal(mClient);
5757
});
@@ -73,7 +73,12 @@ describe('devtools connect', function () {
7373
expect(mClientType.getCalls()[0].args[0]).to.equal(uri);
7474
expect(
7575
Object.keys(mClientType.getCalls()[0].args[1]).sort()
76-
).to.deep.equal(['autoEncryption', 'ca', 'lookup']);
76+
).to.deep.equal([
77+
'allowPartialTrustChain',
78+
'autoEncryption',
79+
'ca',
80+
'lookup',
81+
]);
7782
expect(mClientType.getCalls()[0].args[1].autoEncryption).to.deep.equal(
7883
opts.autoEncryption
7984
);
@@ -114,7 +119,7 @@ describe('devtools connect', function () {
114119
expect(calls[0].args[0]).to.equal(uri);
115120
expect(
116121
Object.keys(mClientType.getCalls()[0].args[1]).sort()
117-
).to.deep.equal(['ca', 'lookup']);
122+
).to.deep.equal(['allowPartialTrustChain', 'ca', 'lookup']);
118123
expect(commandSpy).to.have.been.calledOnceWithExactly({ buildInfo: 1 });
119124
expect(result.client).to.equal(mClientSecond);
120125
});
@@ -192,7 +197,12 @@ describe('devtools connect', function () {
192197
expect(mClientType.getCalls()[0].args[0]).to.equal(uri);
193198
expect(
194199
Object.keys(mClientType.getCalls()[0].args[1]).sort()
195-
).to.deep.equal(['autoEncryption', 'ca', 'lookup']);
200+
).to.deep.equal([
201+
'allowPartialTrustChain',
202+
'autoEncryption',
203+
'ca',
204+
'lookup',
205+
]);
196206
expect(mClient.connect.getCalls()).to.have.lengthOf(1);
197207
expect(result.client).to.equal(mClient);
198208
});
@@ -230,7 +240,7 @@ describe('devtools connect', function () {
230240
expect(mClientType.getCalls()[0].args[0]).to.equal(uri);
231241
expect(
232242
Object.keys(mClientType.getCalls()[0].args[1]).sort()
233-
).to.deep.equal(['ca', 'lookup']);
243+
).to.deep.equal(['allowPartialTrustChain', 'ca', 'lookup']);
234244
expect(commandSpy).to.have.been.calledOnceWithExactly({ buildInfo: 1 });
235245
expect(result.client).to.equal(mClientSecond);
236246
});

packages/devtools-connect/src/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ export async function connectMongoClient(
498498
{},
499499
clientOptions,
500500
shouldAddOidcCallbacks ? state.oidcPlugin.mongoClientOptions : {},
501-
{ ca }
501+
{ ca, allowPartialTrustChain: true }
502502
);
503503

504504
// Adopt dns result order changes with Node v18 that affected the VSCode extension VSCODE-458.

packages/devtools-proxy-support/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"https-proxy-agent": "^7.0.5",
6565
"socks-proxy-agent": "^8.0.4",
6666
"ssh2": "^1.15.0",
67-
"system-ca": "^2.0.0"
67+
"system-ca": "^2.0.1"
6868
},
6969
"devDependencies": {
7070
"@mongodb-js/eslint-config-devtools": "0.9.10",

packages/devtools-proxy-support/src/agent.spec.ts

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import { expect } from 'chai';
77
import sinon from 'sinon';
88
import { HTTPServerProxyTestSetup } from '../test/helpers';
99
import path from 'path';
10+
import type { Server as TLSServer } from 'tls';
11+
import { createServer as createTLSServer } from 'tls';
12+
import { promises as fs } from 'fs';
13+
import type { AddressInfo } from 'net';
14+
import { tlsSupportsAllowPartialTrustChainFlag } from './system-ca';
1015

1116
describe('createAgent', function () {
1217
let setup: HTTPServerProxyTestSetup;
@@ -38,9 +43,11 @@ describe('createAgent', function () {
3843
agents = [];
3944
setup = new HTTPServerProxyTestSetup();
4045
await setup.listen();
46+
resetSystemCACache();
4147
});
4248

4349
afterEach(async function () {
50+
resetSystemCACache();
4451
await setup.teardown();
4552
for (const agent of new Set(agents)) {
4653
agent.destroy();
@@ -183,13 +190,6 @@ describe('createAgent', function () {
183190
});
184191

185192
context('ca support', function () {
186-
beforeEach(function () {
187-
resetSystemCACache();
188-
});
189-
afterEach(function () {
190-
resetSystemCACache();
191-
});
192-
193193
it('can connect using CA as part of the agent options (no explicit CA set)', async function () {
194194
const res = await get(
195195
'https://example.com/hello',
@@ -362,4 +362,55 @@ q/I2+0j6dAkOGcK/68z7qQXByeGri3n28a1Kn6o=
362362
}
363363
});
364364
});
365+
366+
// This mirrors https://github.com/nodejs/node/blob/1b3420274ea8d8cca339a1f10301d2e80f577c4c/test/parallel/test-tls-client-allow-partial-trust-chain.js
367+
context(
368+
'TLS with partial trust chain in system certificate list',
369+
function () {
370+
const fixtures = path.resolve(
371+
__dirname,
372+
'..',
373+
'test',
374+
'fixtures',
375+
'partial-trust-chain'
376+
);
377+
let server: TLSServer;
378+
379+
beforeEach(async function () {
380+
server = createTLSServer(
381+
{
382+
ca: await fs.readFile(path.join(fixtures, 'ca.pem')),
383+
key: await fs.readFile(path.join(fixtures, 'key.pem')),
384+
cert: await fs.readFile(path.join(fixtures, 'cert.pem')),
385+
},
386+
(socket) => socket.end('HTTP/1.0 200 OK\r\n\r\nOK /hello')
387+
);
388+
server.listen(0);
389+
});
390+
391+
afterEach(function () {
392+
server?.close();
393+
});
394+
395+
it('can connect using partial trust chains in the system CA list', async function () {
396+
if (
397+
process.platform !== 'linux' ||
398+
!tlsSupportsAllowPartialTrustChainFlag()
399+
)
400+
return this.skip(); // only really mock-able on Linux
401+
resetSystemCACache({
402+
env: {
403+
SSL_CERT_FILE: path.join(fixtures, 'ca.pem'),
404+
SSL_CERT_DIR: '/nonexistent',
405+
},
406+
});
407+
408+
const res = await get(
409+
`https://localhost:${(server.address() as AddressInfo).port}/hello`,
410+
createAgent({})
411+
);
412+
expect(res.body).to.equal('OK /hello');
413+
});
414+
}
415+
);
365416
});

0 commit comments

Comments
 (0)