Skip to content

Commit 59f6430

Browse 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 <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 503167b commit 59f6430

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ var crypto = require('crypto');
1313
//
1414
functiontestPBKDF2(password,salt,iterations,keylen,expected){
1515
varactual=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
varexpected=
4848
'64c486c55d30d4c5a079b8823b7d7cb37ff0556f537da8410233bcec330ed956';
4949
varkey=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
functionondone(err,key){
5454
if(err)throwerr;
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:Nocallbackprovidedtopbkdf2$/);
6262

6363
// Should not work with Infinity key length
6464
assert.throws(function(){
6565
crypto.pbkdf2('password','salt',1,Infinity,'sha256',common.fail);
66-
},/Badkeylength/);
66+
},/^TypeError:Badkeylength$/);
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-
},/Badkeylength/);
71+
},/^TypeError:Badkeylength$/);
7272

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

7878
// Should not work with negative key length
7979
assert.throws(function(){
8080
crypto.pbkdf2('password','salt',1,-1,'sha256',common.fail);
81-
},/Badkeylength/);
81+
},/^TypeError:Badkeylength$/);
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-
},/Badkeylength/);
86+
},/^TypeError:Badkeylength$/);
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)