doc,test: mention Duplex support for TLS · nodejs/node@e021fb7 · GitHub
Skip to content

Commit e021fb7

Browse files
addaleaxMylesBorins
authored andcommitted
doc,test: mention Duplex support for TLS
Document and test the existing support for generic Duplex streams in the TLS module. PR-URL: #17599 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 8e7ac25 commit e021fb7

3 files changed

Lines changed: 49 additions & 5 deletions

File tree

doc/api/tls.md

Lines changed: 10 additions & 5 deletions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto)
4+
common.skip('missing crypto');
5+
6+
const fixtures = require('../common/fixtures');
7+
const makeDuplexPair = require('../common/duplexpair');
8+
const assert = require('assert');
9+
const { TLSSocket, connect } = require('tls');
10+
11+
const key = fixtures.readKey('agent1-key.pem');
12+
const cert = fixtures.readKey('agent1-cert.pem');
13+
const ca = fixtures.readKey('ca1-cert.pem');
14+
15+
const { clientSide, serverSide } = makeDuplexPair();
16+
17+
const clientTLS = connect({
18+
socket: clientSide,
19+
ca,
20+
host: 'agent1' // Hostname from certificate
21+
});
22+
const serverTLS = new TLSSocket(serverSide, {
23+
isServer: true,
24+
key,
25+
cert,
26+
ca
27+
});
28+
29+
assert.strictEqual(clientTLS.connecting, false);
30+
assert.strictEqual(serverTLS.connecting, false);
31+
32+
clientTLS.on('secureConnect', common.mustCall(() => {
33+
clientTLS.write('foobar', common.mustCall(() => {
34+
assert.strictEqual(serverTLS.read().toString(), 'foobar');
35+
assert.strictEqual(clientTLS._handle.writeQueueSize, 0);
36+
}));
37+
assert.ok(clientTLS._handle.writeQueueSize > 0);
38+
}));

tools/doc/type-parser.js

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)