test: use ES6 to update let & const
Also updating assertStrict and moving the assert required. PR-URL: https://github.com/nodejs/node/pull/9917 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This commit is contained in:
parent
a3a3937d76
commit
a1bd070f87
@ -1,23 +1,23 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var common = require('../common');
|
const common = require('../common');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
// if child process output to console and exit
|
// if child process output to console and exit
|
||||||
if (process.argv[2] === 'child') {
|
if (process.argv[2] === 'child') {
|
||||||
console.log('hello');
|
console.log('hello');
|
||||||
for (var i = 0; i < 200; i++) {
|
for (let i = 0; i < 200; i++) {
|
||||||
console.log('filler');
|
console.log('filler');
|
||||||
}
|
}
|
||||||
console.log('goodbye');
|
console.log('goodbye');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} else {
|
} else {
|
||||||
// parent process
|
// parent process
|
||||||
var spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
|
|
||||||
// spawn self as child
|
// spawn self as child
|
||||||
var child = spawn(process.argv[0], [process.argv[1], 'child']);
|
const child = spawn(process.argv[0], [process.argv[1], 'child']);
|
||||||
|
|
||||||
var stdout = '';
|
let stdout = '';
|
||||||
|
|
||||||
child.stderr.setEncoding('utf8');
|
child.stderr.setEncoding('utf8');
|
||||||
child.stderr.on('data', function(data) {
|
child.stderr.on('data', function(data) {
|
||||||
@ -32,7 +32,7 @@ if (process.argv[2] === 'child') {
|
|||||||
});
|
});
|
||||||
|
|
||||||
child.on('close', common.mustCall(function() {
|
child.on('close', common.mustCall(function() {
|
||||||
assert.equal(stdout.slice(0, 6), 'hello\n');
|
assert.strictEqual(stdout.slice(0, 6), 'hello\n');
|
||||||
assert.equal(stdout.slice(stdout.length - 8), 'goodbye\n');
|
assert.strictEqual(stdout.slice(stdout.length - 8), 'goodbye\n');
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var common = require('../common');
|
const common = require('../common');
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
if (!common.hasCrypto) {
|
if (!common.hasCrypto) {
|
||||||
common.skip('missing crypto');
|
common.skip('missing crypto');
|
||||||
@ -10,21 +9,22 @@ if (common.hasFipsCrypto) {
|
|||||||
common.skip('not supported in FIPS mode');
|
common.skip('not supported in FIPS mode');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
function testCipher1(key) {
|
function testCipher1(key) {
|
||||||
// Test encryption and decryption
|
// Test encryption and decryption
|
||||||
var plaintext = 'Keep this a secret? No! Tell everyone about node.js!';
|
const plaintext = 'Keep this a secret? No! Tell everyone about node.js!';
|
||||||
var cipher = crypto.createCipher('aes192', key);
|
const cipher = crypto.createCipher('aes192', key);
|
||||||
|
|
||||||
// encrypt plaintext which is in utf8 format
|
// encrypt plaintext which is in utf8 format
|
||||||
// to a ciphertext which will be in hex
|
// to a ciphertext which will be in hex
|
||||||
var ciph = cipher.update(plaintext, 'utf8', 'hex');
|
let ciph = cipher.update(plaintext, 'utf8', 'hex');
|
||||||
// Only use binary or hex, not base64.
|
// Only use binary or hex, not base64.
|
||||||
ciph += cipher.final('hex');
|
ciph += cipher.final('hex');
|
||||||
|
|
||||||
var decipher = crypto.createDecipher('aes192', key);
|
const decipher = crypto.createDecipher('aes192', key);
|
||||||
var txt = decipher.update(ciph, 'hex', 'utf8');
|
let txt = decipher.update(ciph, 'hex', 'utf8');
|
||||||
txt += decipher.final('utf8');
|
txt += decipher.final('utf8');
|
||||||
|
|
||||||
assert.strictEqual(txt, plaintext, 'encryption and decryption');
|
assert.strictEqual(txt, plaintext, 'encryption and decryption');
|
||||||
@ -33,11 +33,11 @@ function testCipher1(key) {
|
|||||||
// NB: In real life, it's not guaranteed that you can get all of it
|
// NB: In real life, it's not guaranteed that you can get all of it
|
||||||
// in a single read() like this. But in this case, we know it's
|
// in a single read() like this. But in this case, we know it's
|
||||||
// quite small, so there's no harm.
|
// quite small, so there's no harm.
|
||||||
var cStream = crypto.createCipher('aes192', key);
|
const cStream = crypto.createCipher('aes192', key);
|
||||||
cStream.end(plaintext);
|
cStream.end(plaintext);
|
||||||
ciph = cStream.read();
|
ciph = cStream.read();
|
||||||
|
|
||||||
var dStream = crypto.createDecipher('aes192', key);
|
const dStream = crypto.createDecipher('aes192', key);
|
||||||
dStream.end(ciph);
|
dStream.end(ciph);
|
||||||
txt = dStream.read().toString('utf8');
|
txt = dStream.read().toString('utf8');
|
||||||
|
|
||||||
@ -48,19 +48,19 @@ function testCipher1(key) {
|
|||||||
function testCipher2(key) {
|
function testCipher2(key) {
|
||||||
// encryption and decryption with Base64
|
// encryption and decryption with Base64
|
||||||
// reported in https://github.com/joyent/node/issues/738
|
// reported in https://github.com/joyent/node/issues/738
|
||||||
var plaintext =
|
const plaintext =
|
||||||
'32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
|
'32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
|
||||||
'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
|
'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
|
||||||
'jAfaFg**';
|
'jAfaFg**';
|
||||||
var cipher = crypto.createCipher('aes256', key);
|
const cipher = crypto.createCipher('aes256', key);
|
||||||
|
|
||||||
// encrypt plaintext which is in utf8 format
|
// encrypt plaintext which is in utf8 format
|
||||||
// to a ciphertext which will be in Base64
|
// to a ciphertext which will be in Base64
|
||||||
var ciph = cipher.update(plaintext, 'utf8', 'base64');
|
let ciph = cipher.update(plaintext, 'utf8', 'base64');
|
||||||
ciph += cipher.final('base64');
|
ciph += cipher.final('base64');
|
||||||
|
|
||||||
var decipher = crypto.createDecipher('aes256', key);
|
const decipher = crypto.createDecipher('aes256', key);
|
||||||
var txt = decipher.update(ciph, 'base64', 'utf8');
|
let txt = decipher.update(ciph, 'base64', 'utf8');
|
||||||
txt += decipher.final('utf8');
|
txt += decipher.final('utf8');
|
||||||
|
|
||||||
assert.strictEqual(txt, plaintext, 'encryption and decryption with Base64');
|
assert.strictEqual(txt, plaintext, 'encryption and decryption with Base64');
|
||||||
@ -119,12 +119,12 @@ testCipher2(Buffer.from('0123456789abcdef'));
|
|||||||
const key = '0123456789abcdef';
|
const key = '0123456789abcdef';
|
||||||
const plaintext = 'Top secret!!!';
|
const plaintext = 'Top secret!!!';
|
||||||
const c = crypto.createCipher('aes192', key);
|
const c = crypto.createCipher('aes192', key);
|
||||||
var ciph = c.update(plaintext, 'utf16le', 'base64');
|
let ciph = c.update(plaintext, 'utf16le', 'base64');
|
||||||
ciph += c.final('base64');
|
ciph += c.final('base64');
|
||||||
|
|
||||||
var decipher = crypto.createDecipher('aes192', key);
|
let decipher = crypto.createDecipher('aes192', key);
|
||||||
|
|
||||||
var txt;
|
let txt;
|
||||||
assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'ucs2'));
|
assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'ucs2'));
|
||||||
assert.doesNotThrow(() => txt += decipher.final('ucs2'));
|
assert.doesNotThrow(() => txt += decipher.final('ucs2'));
|
||||||
assert.strictEqual(txt, plaintext, 'decrypted result in ucs2');
|
assert.strictEqual(txt, plaintext, 'decrypted result in ucs2');
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var common = require('../common');
|
const common = require('../common');
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
if (!common.hasCrypto) {
|
if (!common.hasCrypto) {
|
||||||
common.skip('missing crypto');
|
common.skip('missing crypto');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var https = require('https');
|
const assert = require('assert');
|
||||||
|
const https = require('https');
|
||||||
|
|
||||||
var net = require('net');
|
const net = require('net');
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
var options = {
|
const options = {
|
||||||
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
||||||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'),
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'),
|
||||||
handshakeTimeout: 50
|
handshakeTimeout: 50
|
||||||
};
|
};
|
||||||
|
|
||||||
var server = https.createServer(options, common.fail);
|
const server = https.createServer(options, common.fail);
|
||||||
|
|
||||||
server.on('clientError', common.mustCall(function(err, conn) {
|
server.on('clientError', common.mustCall(function(err, conn) {
|
||||||
// Don't hesitate to update the asserts if the internal structure of
|
// Don't hesitate to update the asserts if the internal structure of
|
||||||
// the cleartext object ever changes. We're checking that the https.Server
|
// the cleartext object ever changes. We're checking that the https.Server
|
||||||
// has closed the client connection.
|
// has closed the client connection.
|
||||||
assert.equal(conn._secureEstablished, false);
|
assert.strictEqual(conn._secureEstablished, false);
|
||||||
server.close();
|
server.close();
|
||||||
conn.destroy();
|
conn.destroy();
|
||||||
}));
|
}));
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var common = require('../common');
|
const common = require('../common');
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
if (!common.hasCrypto) {
|
if (!common.hasCrypto) {
|
||||||
common.skip('missing crypto');
|
common.skip('missing crypto');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var tls = require('tls');
|
const assert = require('assert');
|
||||||
|
const tls = require('tls');
|
||||||
|
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var net = require('net');
|
const net = require('net');
|
||||||
|
|
||||||
var out = '';
|
let out = '';
|
||||||
|
|
||||||
var server = tls.createServer({
|
const server = tls.createServer({
|
||||||
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
||||||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
||||||
}, function(c) {
|
}, function(c) {
|
||||||
c.end('hello');
|
c.end('hello');
|
||||||
}).listen(0, function() {
|
}).listen(0, function() {
|
||||||
var socket = new net.Socket();
|
const socket = new net.Socket();
|
||||||
|
|
||||||
var s = tls.connect({
|
const s = tls.connect({
|
||||||
socket: socket,
|
socket: socket,
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
}, function() {
|
}, function() {
|
||||||
@ -38,5 +38,5 @@ var server = tls.createServer({
|
|||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
assert.equal(out, 'hello');
|
assert.strictEqual(out, 'hello');
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user