Skip to content

Commit 5f501b4

Browse files
committed
fixup! fixup! tls: add allowPartialTrustChain flag
1 parent d488340 commit 5f501b4

1 file changed

Lines changed: 43 additions & 32 deletions

File tree

test/parallel/test-tls-client-allow-partial-trust-chain.js

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,46 @@ const tls = require('tls');
1010
const fixtures = require('../common/fixtures');
1111

1212
// agent6-cert.pem is signed by intermediate cert of ca3.
13-
// The server has a cert chain of agent6->ca3->ca1(root) but
14-
15-
async function test() {
16-
const server = tls.createServer({
17-
ca: fixtures.readKey('ca3-cert.pem'),
18-
key: fixtures.readKey('agent6-key.pem'),
19-
cert: fixtures.readKey('agent6-cert.pem'),
20-
}, (socket) => socket.resume());
21-
server.listen(0);
22-
await once(server, 'listening');
23-
24-
const opts = {
25-
port: server.address().port,
26-
ca: fixtures.readKey('ca3-cert.pem'),
27-
checkServerIdentity() {}
28-
};
29-
30-
// Connecting succeeds with allowPartialTrustChain: true
31-
const client = tls.connect({ ...opts, allowPartialTrustChain: true });
32-
await once(client, 'secureConnect');
33-
client.destroy();
34-
35-
// Consistency check: Connecting fails without allowPartialTrustChain: true
36-
await assert.rejects(async () => {
37-
const client = tls.connect(opts);
38-
await once(client, 'secureConnect');
39-
}, { code: 'UNABLE_TO_GET_ISSUER_CERT' });
40-
41-
server.close();
42-
}
43-
44-
test().catch((err) => process.nextTick(() => { throw err; }));
13+
// The server has a cert chain of agent6->ca3->ca1(root).
14+
15+
const { it, beforeEach, afterEach, describe } = require('node:test');
16+
17+
describe('allowPartialTrustChain', function() {
18+
let server;
19+
let client;
20+
let opts;
21+
22+
beforeEach(async function() {
23+
server = tls.createServer({
24+
ca: fixtures.readKey('ca3-cert.pem'),
25+
key: fixtures.readKey('agent6-key.pem'),
26+
cert: fixtures.readKey('agent6-cert.pem'),
27+
}, (socket) => socket.resume());
28+
server.listen(0);
29+
await once(server, 'listening');
30+
31+
opts = {
32+
port: server.address().port,
33+
ca: fixtures.readKey('ca3-cert.pem'),
34+
checkServerIdentity() {}
35+
};
36+
});
37+
38+
afterEach(async function() {
39+
client?.destroy();
40+
server?.close();
41+
});
42+
43+
it('can connect successfully with allowPartialTrustChain: true', async function() {
44+
client = tls.connect({ ...opts, allowPartialTrustChain: true });
45+
await once(client, 'secureConnect'); // Should not throw
46+
});
47+
48+
it('fails without with allowPartialTrustChain: true for an intermediate cert in the CA', async function() {
49+
// Consistency check: Connecting fails without allowPartialTrustChain: true
50+
await assert.rejects(async () => {
51+
const client = tls.connect(opts);
52+
await once(client, 'secureConnect');
53+
}, { code: 'UNABLE_TO_GET_ISSUER_CERT' });
54+
});
55+
});

0 commit comments

Comments
 (0)