0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-22 07:37:56 +01:00
nodejs/test/internet/test-https-issue-43963.js
Daeyeon Jeong 7f7a899fa5
net,tls: pass a valid socket on tlsClientError
On the 'tlsClientError' event, the `tlsSocket` instance is passed as
`closed` status. Thus, users can't get information such as `remote
address`, `remoteFamily`, and so on.

This adds a flag to close a socket after emitting an `error` event.

Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
PR-URL: https://github.com/nodejs/node/pull/44021
Fixes: https://github.com/nodejs/node/issues/43963
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2022-08-01 07:37:45 +01:00

32 lines
930 B
JavaScript

'use strict';
const common = require('../common');
const https = require('node:https');
const assert = require('node:assert');
const server = https.createServer();
server.on(
'tlsClientError',
common.mustCall((exception, tlsSocket) => {
assert.strictEqual(exception !== undefined, true);
assert.strictEqual(Object.keys(tlsSocket.address()).length !== 0, true);
assert.strictEqual(tlsSocket.localAddress !== undefined, true);
assert.strictEqual(tlsSocket.localPort !== undefined, true);
assert.strictEqual(tlsSocket.remoteAddress !== undefined, true);
assert.strictEqual(tlsSocket.remoteFamily !== undefined, true);
assert.strictEqual(tlsSocket.remotePort !== undefined, true);
}),
);
server.listen(0, () => {
const req = https.request({
hostname: '127.0.0.1',
port: server.address().port,
});
req.on(
'error',
common.mustCall(() => server.close()),
);
req.end();
});