From 1b4bb8991bfdd747dcb37fe28bf852d3c254f992 Mon Sep 17 00:00:00 2001 From: Nhoel S Date: Fri, 6 Oct 2017 11:20:18 -0700 Subject: [PATCH 1/3] test: replace assert messages with template strings Specifically for the test-crypto-hash.js test file. --- test/parallel/test-crypto-hash.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index 82a76131fb9ba5..9c98bb96d98d86 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -9,6 +9,9 @@ const fs = require('fs'); const fixtures = require('../common/fixtures'); +let cryptoType; +let digest; + // Test hashing const a1 = crypto.createHash('sha1').update('Test123').digest('hex'); const a2 = crypto.createHash('sha256').update('Test123').digest('base64'); @@ -37,16 +40,22 @@ a8.end(); a8 = a8.read(); if (!common.hasFipsCrypto) { - const a0 = crypto.createHash('md5').update('Test123').digest('latin1'); + cryptoType = 'md5'; + digest = 'latin1' + const a0 = crypto.createHash(cryptoType).update('Test123').digest(digest); assert.strictEqual( a0, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca\u00bd\u008c', - 'Test MD5 as latin1' + `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.` ); } -assert.strictEqual(a1, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1'); +cryptoType = 'md5'; digest = 'hex'; +assert.strictEqual(a1, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', + `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.`); +cryptoType = 'sha256';digest = 'base64'; assert.strictEqual(a2, '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=', - 'Test SHA256 as base64'); + `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.`); +cryptoType = 'sha512'; digest = 'latin1'; assert.deepStrictEqual( a3, Buffer.from( @@ -56,11 +65,12 @@ assert.deepStrictEqual( '\u00d7\u00d6\u00a2\u00a8\u0085\u00e3<\u0083\u009c\u0093' + '\u00c2\u0006\u00da0\u00a1\u00879(G\u00ed\'', 'latin1'), - 'Test SHA512 as assumed buffer'); + `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.`); +cryptoType = 'sha1'; digest = 'hex'; assert.deepStrictEqual( a4, Buffer.from('8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'hex'), - 'Test SHA1' + `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.` ); // stream interface should produce the same result. From 22f9e2fd22045a52d07b9bdbd94865f6a5ef3dd0 Mon Sep 17 00:00:00 2001 From: nhoel Date: Thu, 19 Oct 2017 07:22:21 -0700 Subject: [PATCH 2/3] Update test-crypto-hash.js --- test/parallel/test-crypto-hash.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index 9c98bb96d98d86..76df87965bd899 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -49,13 +49,16 @@ if (!common.hasFipsCrypto) { `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.` ); } -cryptoType = 'md5'; digest = 'hex'; +cryptoType = 'md5'; +digest = 'hex'; assert.strictEqual(a1, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.`); -cryptoType = 'sha256';digest = 'base64'; +cryptoType = 'sha256'; +digest = 'base64'; assert.strictEqual(a2, '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=', `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.`); -cryptoType = 'sha512'; digest = 'latin1'; +cryptoType = 'sha512'; +digest = 'latin1'; assert.deepStrictEqual( a3, Buffer.from( @@ -66,7 +69,8 @@ assert.deepStrictEqual( '\u00c2\u0006\u00da0\u00a1\u00879(G\u00ed\'', 'latin1'), `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.`); -cryptoType = 'sha1'; digest = 'hex'; +cryptoType = 'sha1'; +digest = 'hex'; assert.deepStrictEqual( a4, Buffer.from('8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'hex'), From 072086ce2a32fc7325939e1b951099e1c07a4279 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 27 Oct 2017 09:35:16 -0700 Subject: [PATCH 3/3] squash --- test/parallel/test-crypto-hash.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index 76df87965bd899..f55a6768900e65 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -41,22 +41,26 @@ a8 = a8.read(); if (!common.hasFipsCrypto) { cryptoType = 'md5'; - digest = 'latin1' + digest = 'latin1'; const a0 = crypto.createHash(cryptoType).update('Test123').digest(digest); assert.strictEqual( a0, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca\u00bd\u008c', - `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.` + `${cryptoType} with ${digest} digest failed to evaluate to expected hash` ); } cryptoType = 'md5'; digest = 'hex'; -assert.strictEqual(a1, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', - `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.`); +assert.strictEqual( + a1, + '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', + `${cryptoType} with ${digest} digest failed to evaluate to expected hash`); cryptoType = 'sha256'; digest = 'base64'; -assert.strictEqual(a2, '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=', - `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.`); +assert.strictEqual( + a2, + '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=', + `${cryptoType} with ${digest} digest failed to evaluate to expected hash`); cryptoType = 'sha512'; digest = 'latin1'; assert.deepStrictEqual( @@ -68,13 +72,13 @@ assert.deepStrictEqual( '\u00d7\u00d6\u00a2\u00a8\u0085\u00e3<\u0083\u009c\u0093' + '\u00c2\u0006\u00da0\u00a1\u00879(G\u00ed\'', 'latin1'), - `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.`); + `${cryptoType} with ${digest} digest failed to evaluate to expected hash`); cryptoType = 'sha1'; digest = 'hex'; assert.deepStrictEqual( a4, Buffer.from('8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'hex'), - `${cryptoType} with ${digest} digest failed to evaluate to expected hash value.` + `${cryptoType} with ${digest} digest failed to evaluate to expected hash` ); // stream interface should produce the same result.