-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
3 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const fixtures = require('../common/fixtures'); | ||
const makeDuplexPair = require('../common/duplexpair'); | ||
const assert = require('assert'); | ||
const { TLSSocket, connect } = require('tls'); | ||
|
||
const key = fixtures.readKey('agent1-key.pem'); | ||
const cert = fixtures.readKey('agent1-cert.pem'); | ||
const ca = fixtures.readKey('ca1-cert.pem'); | ||
|
||
const { clientSide, serverSide } = makeDuplexPair(); | ||
|
||
const clientTLS = connect({ | ||
socket: clientSide, | ||
ca, | ||
host: 'agent1' // Hostname from certificate | ||
}); | ||
const serverTLS = new TLSSocket(serverSide, { | ||
isServer: true, | ||
key, | ||
cert, | ||
ca | ||
}); | ||
|
||
assert.strictEqual(clientTLS.connecting, false); | ||
assert.strictEqual(serverTLS.connecting, false); | ||
|
||
clientTLS.on('secureConnect', common.mustCall(() => { | ||
clientTLS.write('foobar', common.mustCall(() => { | ||
assert.strictEqual(serverTLS.read().toString(), 'foobar'); | ||
assert.strictEqual(clientTLS._handle.writeQueueSize, 0); | ||
})); | ||
assert.ok(clientTLS._handle.writeQueueSize > 0); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters