Skip to content
Closed
Changes from 1 commit
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
Next Next commit
test: replace assert messages with template strings
Specifically for the test-crypto-hash.js test file.
  • Loading branch information
Nhoel S authored and Trott committed Oct 27, 2017
commit 1b4bb8991bfdd747dcb37fe28bf852d3c254f992
22 changes: 16 additions & 6 deletions test/parallel/test-crypto-hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always use a new line for these assignments.

assert.strictEqual(a1, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2',
`${cryptoType} with ${digest} digest failed to evaluate to expected hash value.`);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line length exceeds 80 characters.

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(
Expand All @@ -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.
Expand Down