Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2e889cf

Browse filesBrowse files
joyeecheungaddaleax
authored andcommitted
test: improve test for crypto pbkdf2
- use assert.strictEqual instead of assert.equal - add regexp for assert.throws PR-URL: #9883 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d226418 commit 2e889cf
Copy full SHA for 2e889cf

File tree

Expand file treeCollapse file tree

1 file changed

+10
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-10
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-crypto-pbkdf2.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-pbkdf2.js
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ var crypto = require('crypto');
1313
//
1414
function testPBKDF2(password, salt, iterations, keylen, expected) {
1515
var actual = crypto.pbkdf2Sync(password, salt, iterations, keylen, 'sha256');
16-
assert.equal(actual.toString('latin1'), expected);
16+
assert.strictEqual(actual.toString('latin1'), expected);
1717

1818
crypto.pbkdf2(password, salt, iterations, keylen, 'sha256', (err, actual) => {
19-
assert.equal(actual.toString('latin1'), expected);
19+
assert.strictEqual(actual.toString('latin1'), expected);
2020
});
2121
}
2222

@@ -47,43 +47,43 @@ testPBKDF2('pass\0word', 'sa\0lt', 4096, 16,
4747
var expected =
4848
'64c486c55d30d4c5a079b8823b7d7cb37ff0556f537da8410233bcec330ed956';
4949
var key = crypto.pbkdf2Sync('password', 'salt', 32, 32, 'sha256');
50-
assert.equal(key.toString('hex'), expected);
50+
assert.strictEqual(key.toString('hex'), expected);
5151

5252
crypto.pbkdf2('password', 'salt', 32, 32, 'sha256', common.mustCall(ondone));
5353
function ondone(err, key) {
5454
if (err) throw err;
55-
assert.equal(key.toString('hex'), expected);
55+
assert.strictEqual(key.toString('hex'), expected);
5656
}
5757

5858
// Error path should not leak memory (check with valgrind).
5959
assert.throws(function() {
6060
crypto.pbkdf2('password', 'salt', 1, 20, null);
61-
});
61+
}, /^Error: No callback provided to pbkdf2$/);
6262

6363
// Should not work with Infinity key length
6464
assert.throws(function() {
6565
crypto.pbkdf2('password', 'salt', 1, Infinity, 'sha256', common.fail);
66-
}, /Bad key length/);
66+
}, /^TypeError: Bad key length$/);
6767

6868
// Should not work with negative Infinity key length
6969
assert.throws(function() {
7070
crypto.pbkdf2('password', 'salt', 1, -Infinity, 'sha256', common.fail);
71-
}, /Bad key length/);
71+
}, /^TypeError: Bad key length$/);
7272

7373
// Should not work with NaN key length
7474
assert.throws(function() {
7575
crypto.pbkdf2('password', 'salt', 1, NaN, 'sha256', common.fail);
76-
}, /Bad key length/);
76+
}, /^TypeError: Bad key length$/);
7777

7878
// Should not work with negative key length
7979
assert.throws(function() {
8080
crypto.pbkdf2('password', 'salt', 1, -1, 'sha256', common.fail);
81-
}, /Bad key length/);
81+
}, /^TypeError: Bad key length$/);
8282

8383
// Should not work with key length that does not fit into 32 signed bits
8484
assert.throws(function() {
8585
crypto.pbkdf2('password', 'salt', 1, 4073741824, 'sha256', common.fail);
86-
}, /Bad key length/);
86+
}, /^TypeError: Bad key length$/);
8787

8888
// Should not get FATAL ERROR with empty password and salt
8989
// https://github.com/nodejs/node/issues/8571

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.