From d75e47b7ddff18c6c5819d931e6a3abc93a82e0e Mon Sep 17 00:00:00 2001 From: joyeecheung Date: Thu, 1 Dec 2016 10:00:10 -0600 Subject: [PATCH 1/2] test: improve test for crypto pbkdf2 - use assert.strictEqual instead of assert.equal - add regexp for assert.throws --- test/parallel/test-crypto-pbkdf2.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-crypto-pbkdf2.js b/test/parallel/test-crypto-pbkdf2.js index f9fa7aa486318d..55018babc855b1 100644 --- a/test/parallel/test-crypto-pbkdf2.js +++ b/test/parallel/test-crypto-pbkdf2.js @@ -13,10 +13,10 @@ var crypto = require('crypto'); // function testPBKDF2(password, salt, iterations, keylen, expected) { var actual = crypto.pbkdf2Sync(password, salt, iterations, keylen, 'sha256'); - assert.equal(actual.toString('latin1'), expected); + assert.strictEqual(actual.toString('latin1'), expected); crypto.pbkdf2(password, salt, iterations, keylen, 'sha256', (err, actual) => { - assert.equal(actual.toString('latin1'), expected); + assert.strictEqual(actual.toString('latin1'), expected); }); } @@ -47,18 +47,18 @@ testPBKDF2('pass\0word', 'sa\0lt', 4096, 16, var expected = '64c486c55d30d4c5a079b8823b7d7cb37ff0556f537da8410233bcec330ed956'; var key = crypto.pbkdf2Sync('password', 'salt', 32, 32, 'sha256'); -assert.equal(key.toString('hex'), expected); +assert.strictEqual(key.toString('hex'), expected); crypto.pbkdf2('password', 'salt', 32, 32, 'sha256', common.mustCall(ondone)); function ondone(err, key) { if (err) throw err; - assert.equal(key.toString('hex'), expected); + assert.strictEqual(key.toString('hex'), expected); } // Error path should not leak memory (check with valgrind). assert.throws(function() { crypto.pbkdf2('password', 'salt', 1, 20, null); -}); +}, /No callback/); // Should not work with Infinity key length assert.throws(function() { From 71ba2dfc00b77fe907666288aa1b9b6c69ad67a9 Mon Sep 17 00:00:00 2001 From: joyeecheung Date: Fri, 2 Dec 2016 05:26:59 -0600 Subject: [PATCH 2/2] test: improve pbkdf2 test error message regexp Test for full error message with `^` and `$` --- test/parallel/test-crypto-pbkdf2.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-crypto-pbkdf2.js b/test/parallel/test-crypto-pbkdf2.js index 55018babc855b1..af72dc7f3067dd 100644 --- a/test/parallel/test-crypto-pbkdf2.js +++ b/test/parallel/test-crypto-pbkdf2.js @@ -58,32 +58,32 @@ function ondone(err, key) { // Error path should not leak memory (check with valgrind). assert.throws(function() { crypto.pbkdf2('password', 'salt', 1, 20, null); -}, /No callback/); +}, /^Error: No callback provided to pbkdf2$/); // Should not work with Infinity key length assert.throws(function() { crypto.pbkdf2('password', 'salt', 1, Infinity, 'sha256', common.fail); -}, /Bad key length/); +}, /^TypeError: Bad key length$/); // Should not work with negative Infinity key length assert.throws(function() { crypto.pbkdf2('password', 'salt', 1, -Infinity, 'sha256', common.fail); -}, /Bad key length/); +}, /^TypeError: Bad key length$/); // Should not work with NaN key length assert.throws(function() { crypto.pbkdf2('password', 'salt', 1, NaN, 'sha256', common.fail); -}, /Bad key length/); +}, /^TypeError: Bad key length$/); // Should not work with negative key length assert.throws(function() { crypto.pbkdf2('password', 'salt', 1, -1, 'sha256', common.fail); -}, /Bad key length/); +}, /^TypeError: Bad key length$/); // Should not work with key length that does not fit into 32 signed bits assert.throws(function() { crypto.pbkdf2('password', 'salt', 1, 4073741824, 'sha256', common.fail); -}, /Bad key length/); +}, /^TypeError: Bad key length$/); // Should not get FATAL ERROR with empty password and salt // https://github.com/nodejs/node/issues/8571