Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Refactors variables to ES6 compatible and newer assertions #10023

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions test/parallel/test-tls-ticket-cluster.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
var tls = require('tls');
const tls = require('tls');

var cluster = require('cluster');
var fs = require('fs');
var join = require('path').join;
const cluster = require('cluster');
const fs = require('fs');
const join = require('path').join;

var workerCount = 4;
var expectedReqCount = 16;
const workerCount = 4;
const expectedReqCount = 16;

if (cluster.isMaster) {
var reusedCount = 0;
var reqCount = 0;
var lastSession = null;
var shootOnce = false;
let reusedCount = 0;
let reqCount = 0;
let lastSession = null;
let shootOnce = false;

function shoot() {
console.error('[master] connecting');
var c = tls.connect(common.PORT, {
const c = tls.connect(common.PORT, {
session: lastSession,
rejectUnauthorized: false
}, function() {
Expand All @@ -41,7 +41,7 @@ if (cluster.isMaster) {
}

function fork() {
var worker = cluster.fork();
const worker = cluster.fork();
worker.on('message', function(msg) {
console.error('[master] got %j', msg);
if (msg === 'reused') {
Expand All @@ -56,27 +56,27 @@ if (cluster.isMaster) {
console.error('[master] worker died');
});
}
for (var i = 0; i < workerCount; i++) {
for (let i = 0; i < workerCount; i++) {
fork();
}

process.on('exit', function() {
assert.equal(reqCount, expectedReqCount);
assert.equal(reusedCount + 1, reqCount);
assert.strictEqual(reqCount, expectedReqCount);
assert.strictEqual(reusedCount + 1, reqCount);
});
return;
}

var keyFile = join(common.fixturesDir, 'agent.key');
var certFile = join(common.fixturesDir, 'agent.crt');
var key = fs.readFileSync(keyFile);
var cert = fs.readFileSync(certFile);
var options = {
const keyFile = join(common.fixturesDir, 'agent.key');
const certFile = join(common.fixturesDir, 'agent.crt');
const key = fs.readFileSync(keyFile);
const cert = fs.readFileSync(certFile);
const options = {
key: key,
cert: cert
};

var server = tls.createServer(options, function(c) {
const server = tls.createServer(options, function(c) {
if (c.isSessionReused()) {
process.send('reused');
} else {
Expand Down
52 changes: 26 additions & 26 deletions test/parallel/test-tls-ticket.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
var tls = require('tls');
const tls = require('tls');

var fs = require('fs');
var net = require('net');
var crypto = require('crypto');
const fs = require('fs');
const net = require('net');
const crypto = require('crypto');

var keys = crypto.randomBytes(48);
var serverLog = [];
var ticketLog = [];
const keys = crypto.randomBytes(48);
const serverLog = [];
const ticketLog = [];

var serverCount = 0;
let serverCount = 0;
function createServer() {
var id = serverCount++;
const id = serverCount++;

var counter = 0;
var previousKey = null;
let counter = 0;
let previousKey = null;

var server = tls.createServer({
const server = tls.createServer({
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'),
ticketKeys: keys
Expand All @@ -49,13 +49,13 @@ function createServer() {
return server;
}

var naturalServers = [ createServer(), createServer(), createServer() ];
const naturalServers = [ createServer(), createServer(), createServer() ];

// 3x servers
var servers = naturalServers.concat(naturalServers).concat(naturalServers);
const servers = naturalServers.concat(naturalServers).concat(naturalServers);

// Create one TCP server and balance sockets to multiple TLS server instances
var shared = net.createServer(function(c) {
const shared = net.createServer(function(c) {
servers.shift().emit('connection', c);
}).listen(0, function() {
start(function() {
Expand All @@ -64,11 +64,11 @@ var shared = net.createServer(function(c) {
});

function start(callback) {
var sess = null;
var left = servers.length;
let sess = null;
let left = servers.length;

function connect() {
var s = tls.connect(shared.address().port, {
const s = tls.connect(shared.address().port, {
session: sess,
rejectUnauthorized: false
}, function() {
Expand All @@ -87,15 +87,15 @@ function start(callback) {
}

process.on('exit', function() {
assert.equal(ticketLog.length, serverLog.length);
for (var i = 0; i < naturalServers.length - 1; i++) {
assert.notEqual(serverLog[i], serverLog[i + 1]);
assert.equal(ticketLog[i], ticketLog[i + 1]);
assert.strictEqual(ticketLog.length, serverLog.length);
for (let i = 0; i < naturalServers.length - 1; i++) {
assert.notStrictEqual(serverLog[i], serverLog[i + 1]);
assert.strictEqual(ticketLog[i], ticketLog[i + 1]);

// 2nd connection should have different ticket
assert.notEqual(ticketLog[i], ticketLog[i + naturalServers.length]);
assert.notStrictEqual(ticketLog[i], ticketLog[i + naturalServers.length]);

// 3rd connection should have the same ticket
assert.equal(ticketLog[i], ticketLog[i + naturalServers.length * 2]);
assert.strictEqual(ticketLog[i], ticketLog[i + naturalServers.length * 2]);
}
});