Skip to content

Commit

Permalink
fixup! tls: allow client-side sockets to be half-opened
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Aug 15, 2019
1 parent 087e4c3 commit 3e89ac1
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions test/parallel/test-tls-connect-allow-half-open-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,27 @@ const tls = require('tls');
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', common.mustCall((chunk) => {
if (chunk === 'Hello') {
socket.end(chunk);
} else {
assert.strictEqual(chunk, 'Bye');
assert(!socket.writable);
socket.on('data', (chunk) => {
message += chunk;

if (message === 'Hello') {
socket.end(message);
message = '';
}
}, 2));
});

socket.on('end', common.mustCall(() => {
assert.strictEqual(message, 'Bye');
}));
}));

server.listen(0, common.mustCall(() => {
Expand All @@ -45,10 +50,15 @@ server.listen(0, common.mustCall(() => {
rejectUnauthorized: false,
allowHalfOpen: true,
}, common.mustCall(() => {
socket.on('data', common.mustCall((chunk) => {
assert.strictEqual(chunk, 'Hello');
}));
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'));
Expand Down

0 comments on commit 3e89ac1

Please sign in to comment.