test: refactor test-tls-alert-handling
* process.on('exit',...) checks -> common.mustCall() * remove unused function parameters * var -> const/let PR-URL: https://github.com/nodejs/node/pull/10482 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Italo A. Casas <me@italoacasas.com>
This commit is contained in:
parent
0b33ef80f1
commit
a6ca94a5f5
@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var common = require('../common');
|
const common = require('../common');
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
if (!common.opensslCli) {
|
if (!common.opensslCli) {
|
||||||
common.skip('node compiled without OpenSSL CLI.');
|
common.skip('node compiled without OpenSSL CLI.');
|
||||||
@ -12,11 +11,9 @@ if (!common.hasCrypto) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tls = require('tls');
|
const tls = require('tls');
|
||||||
var net = require('net');
|
const net = require('net');
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
var success = false;
|
|
||||||
|
|
||||||
function filenamePEM(n) {
|
function filenamePEM(n) {
|
||||||
return require('path').join(common.fixturesDir, 'keys', n + '.pem');
|
return require('path').join(common.fixturesDir, 'keys', n + '.pem');
|
||||||
@ -26,17 +23,16 @@ function loadPEM(n) {
|
|||||||
return fs.readFileSync(filenamePEM(n));
|
return fs.readFileSync(filenamePEM(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
var opts = {
|
const opts = {
|
||||||
key: loadPEM('agent2-key'),
|
key: loadPEM('agent2-key'),
|
||||||
cert: loadPEM('agent2-cert')
|
cert: loadPEM('agent2-cert')
|
||||||
};
|
};
|
||||||
|
const max_iter = 20;
|
||||||
|
let iter = 0;
|
||||||
|
|
||||||
var max_iter = 20;
|
const server = tls.createServer(opts, function(s) {
|
||||||
var iter = 0;
|
|
||||||
|
|
||||||
var server = tls.createServer(opts, function(s) {
|
|
||||||
s.pipe(s);
|
s.pipe(s);
|
||||||
s.on('error', function(e) {
|
s.on('error', function() {
|
||||||
// ignore error
|
// ignore error
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -47,10 +43,10 @@ server.listen(0, function() {
|
|||||||
|
|
||||||
|
|
||||||
function sendClient() {
|
function sendClient() {
|
||||||
var client = tls.connect(server.address().port, {
|
const client = tls.connect(server.address().port, {
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
});
|
});
|
||||||
client.on('data', function(chunk) {
|
client.on('data', common.mustCall(function() {
|
||||||
if (iter++ === 2) sendBADTLSRecord();
|
if (iter++ === 2) sendBADTLSRecord();
|
||||||
if (iter < max_iter) {
|
if (iter < max_iter) {
|
||||||
client.write('a');
|
client.write('a');
|
||||||
@ -58,10 +54,9 @@ function sendClient() {
|
|||||||
}
|
}
|
||||||
client.end();
|
client.end();
|
||||||
server.close();
|
server.close();
|
||||||
success = true;
|
}, max_iter));
|
||||||
});
|
|
||||||
client.write('a');
|
client.write('a');
|
||||||
client.on('error', function(e) {
|
client.on('error', function() {
|
||||||
// ignore error
|
// ignore error
|
||||||
});
|
});
|
||||||
client.on('close', function() {
|
client.on('close', function() {
|
||||||
@ -71,21 +66,16 @@ function sendClient() {
|
|||||||
|
|
||||||
|
|
||||||
function sendBADTLSRecord() {
|
function sendBADTLSRecord() {
|
||||||
var BAD_RECORD = Buffer.from([0xff, 0xff, 0xff, 0xff, 0xff, 0xff]);
|
const BAD_RECORD = Buffer.from([0xff, 0xff, 0xff, 0xff, 0xff, 0xff]);
|
||||||
var socket = net.connect(server.address().port);
|
const socket = net.connect(server.address().port);
|
||||||
var client = tls.connect({
|
const client = tls.connect({
|
||||||
socket: socket,
|
socket: socket,
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
}, function() {
|
}, function() {
|
||||||
socket.write(BAD_RECORD);
|
socket.write(BAD_RECORD);
|
||||||
socket.end();
|
socket.end();
|
||||||
});
|
});
|
||||||
client.on('error', function(e) {
|
client.on('error', function() {
|
||||||
// ignore error
|
// ignore error
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on('exit', function() {
|
|
||||||
assert.strictEqual(iter, max_iter);
|
|
||||||
assert(success);
|
|
||||||
});
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user