Skip to content

Commit 29b89ba

Browse files
sam-githubaddaleax
authored andcommitted
test: check for tls renegotiation errors
Check that the return value and callback error for tls.renegotiate() does not indicate a failure. Also, remove unnecessary line wrapping and indentation. PR-URL: #25437 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 26f2eb8 commit 29b89ba

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

test/parallel/test-tls-disable-renegotiation.js

+22-24
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const tls = require('tls');
1212

1313
const options = {
1414
key: fixtures.readKey('agent1-key.pem'),
15-
cert: fixtures.readKey('agent1-cert.pem')
15+
cert: fixtures.readKey('agent1-cert.pem'),
1616
};
1717

1818
const server = tls.Server(options, common.mustCall((socket) => {
@@ -45,28 +45,26 @@ server.listen(0, common.mustCall(() => {
4545
rejectUnauthorized: false,
4646
port
4747
};
48-
const client =
49-
tls.connect(options, common.mustCall(() => {
50-
client.write('');
51-
// Negotiation is still permitted for this first
52-
// attempt. This should succeed.
53-
client.renegotiate(
54-
{ rejectUnauthorized: false },
55-
common.mustCall(() => {
56-
// Once renegotiation completes, we write some
57-
// data to the socket, which triggers the on
58-
// data event on the server. After that data
59-
// is received, disableRenegotiation is called.
60-
client.write('data', common.mustCall(() => {
61-
client.write('');
62-
// This second renegotiation attempt should fail
63-
// and the callback should never be invoked. The
64-
// server will simply drop the connection after
65-
// emitting the error.
66-
client.renegotiate(
67-
{ rejectUnauthorized: false },
68-
common.mustNotCall());
69-
}));
70-
}));
48+
const client = tls.connect(options, common.mustCall(() => {
49+
client.write('');
50+
// Negotiation is still permitted for this first
51+
// attempt. This should succeed.
52+
let ok = client.renegotiate(options, common.mustCall((err) => {
53+
assert.ifError(err);
54+
// Once renegotiation completes, we write some
55+
// data to the socket, which triggers the on
56+
// data event on the server. After that data
57+
// is received, disableRenegotiation is called.
58+
client.write('data', common.mustCall(() => {
59+
client.write('');
60+
// This second renegotiation attempt should fail
61+
// and the callback should never be invoked. The
62+
// server will simply drop the connection after
63+
// emitting the error.
64+
ok = client.renegotiate(options, common.mustNotCall());
65+
assert.strictEqual(ok, true);
66+
}));
7167
}));
68+
assert.strictEqual(ok, true);
69+
}));
7270
}));

0 commit comments

Comments
 (0)