Skip to content

Commit 0ace5a1

Browse files
nhoelMylesBorins
authored andcommitted
test: include values in assertion messages
Specifically for the test-crypto-hash.js test file. PR-URL: #15996 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent a8d7f5f commit 0ace5a1

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

test/parallel/test-crypto-hash.js

+25-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const fs = require('fs');
88
const crypto = require('crypto');
99
const fixtures = require('../common/fixtures');
1010

11+
let cryptoType;
12+
let digest;
13+
1114
// Test hashing
1215
const a1 = crypto.createHash('sha1').update('Test123').digest('hex');
1316
const a2 = crypto.createHash('sha256').update('Test123').digest('base64');
@@ -36,16 +39,29 @@ a8.end();
3639
a8 = a8.read();
3740

3841
if (!common.hasFipsCrypto) {
39-
const a0 = crypto.createHash('md5').update('Test123').digest('latin1');
42+
cryptoType = 'md5';
43+
digest = 'latin1';
44+
const a0 = crypto.createHash(cryptoType).update('Test123').digest(digest);
4045
assert.strictEqual(
4146
a0,
4247
'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca\u00bd\u008c',
43-
'Test MD5 as latin1'
48+
`${cryptoType} with ${digest} digest failed to evaluate to expected hash`
4449
);
4550
}
46-
assert.strictEqual(a1, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1');
47-
assert.strictEqual(a2, '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=',
48-
'Test SHA256 as base64');
51+
cryptoType = 'md5';
52+
digest = 'hex';
53+
assert.strictEqual(
54+
a1,
55+
'8308651804facb7b9af8ffc53a33a22d6a1c8ac2',
56+
`${cryptoType} with ${digest} digest failed to evaluate to expected hash`);
57+
cryptoType = 'sha256';
58+
digest = 'base64';
59+
assert.strictEqual(
60+
a2,
61+
'2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=',
62+
`${cryptoType} with ${digest} digest failed to evaluate to expected hash`);
63+
cryptoType = 'sha512';
64+
digest = 'latin1';
4965
assert.deepStrictEqual(
5066
a3,
5167
Buffer.from(
@@ -55,11 +71,13 @@ assert.deepStrictEqual(
5571
'\u00d7\u00d6\u00a2\u00a8\u0085\u00e3<\u0083\u009c\u0093' +
5672
'\u00c2\u0006\u00da0\u00a1\u00879(G\u00ed\'',
5773
'latin1'),
58-
'Test SHA512 as assumed buffer');
74+
`${cryptoType} with ${digest} digest failed to evaluate to expected hash`);
75+
cryptoType = 'sha1';
76+
digest = 'hex';
5977
assert.deepStrictEqual(
6078
a4,
6179
Buffer.from('8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'hex'),
62-
'Test SHA1'
80+
`${cryptoType} with ${digest} digest failed to evaluate to expected hash`
6381
);
6482

6583
// stream interface should produce the same result.

0 commit comments

Comments
 (0)