mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 14:25:18 +00:00

Previously Node.js would handle empty `net.connect()` and `socket.connect()` call as if the user passed empty options object which doesn't really make sense. This was due to the fact that it uses the same `normalizeArgs` function as `.listen()` call where such call is perfectly fine. This will make it clear what is the problem with such call and how it can be resolved. It now throws `ERR_MISSING_ARGS` if no arguments were passed or neither `path` nor `port` is specified. Fixes: https://github.com/nodejs/node/issues/33930 PR-URL: https://github.com/nodejs/node/pull/34022 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com>
74 lines
1.6 KiB
JavaScript
74 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
// This test verifies that `tls.connect()` honors the `allowHalfOpen` option.
|
|
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const fixtures = require('../common/fixtures');
|
|
const tls = require('tls');
|
|
|
|
{
|
|
const socket = tls.connect({ port: 42, lookup() {} });
|
|
assert.strictEqual(socket.allowHalfOpen, false);
|
|
}
|
|
|
|
{
|
|
const socket = tls.connect({ port: 42, allowHalfOpen: false, lookup() {} });
|
|
assert.strictEqual(socket.allowHalfOpen, false);
|
|
}
|
|
|
|
const server = tls.createServer({
|
|
key: fixtures.readKey('agent1-key.pem'),
|
|
cert: fixtures.readKey('agent1-cert.pem'),
|
|
}, common.mustCall((socket) => {
|
|
server.close();
|
|
|
|
let message = '';
|
|
|
|
socket.setEncoding('utf8');
|
|
socket.on('data', (chunk) => {
|
|
message += chunk;
|
|
|
|
if (message === 'Hello') {
|
|
socket.end(message);
|
|
message = '';
|
|
}
|
|
});
|
|
|
|
socket.on('end', common.mustCall(() => {
|
|
assert.strictEqual(message, 'Bye');
|
|
}));
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const socket = tls.connect({
|
|
port: server.address().port,
|
|
rejectUnauthorized: false,
|
|
allowHalfOpen: true,
|
|
}, common.mustCall(() => {
|
|
let message = '';
|
|
|
|
socket.on('data', (chunk) => {
|
|
message += chunk;
|
|
});
|
|
|
|
socket.on('end', common.mustCall(() => {
|
|
assert.strictEqual(message, 'Hello');
|
|
|
|
setTimeout(() => {
|
|
assert(socket.writable);
|
|
assert(socket.write('Bye'));
|
|
socket.end();
|
|
}, 50);
|
|
}));
|
|
|
|
socket.write('Hello');
|
|
}));
|
|
|
|
socket.setEncoding('utf8');
|
|
}));
|