Skip to content

Commit 96223a5

Browse files
committed
Add more tests
1 parent 6dde44b commit 96223a5

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

scrypt-async.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ function scrypt(password, salt, logN, r, dkLen, interruptStep, callback, encodin
377377
if (opts.N < 2 || opts.N > MAX_UINT)
378378
throw new Error('scrypt: N is out of range');
379379

380-
if (opts.N & (opts.N - 1) !== 0)
380+
if ((opts.N & (opts.N - 1)) !== 0)
381381
throw new Error('scrypt: N is not a power of 2');
382382

383383
logN = Math.log(opts.N) / Math.LN2;

test/unittests.js

+43
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,24 @@ describe('limits test', function() {
294294
}, Error);
295295
});
296296

297+
it('should throw with too big N', function() {
298+
assert.throws(function() {
299+
scrypt(v.password, v.salt, { N: ((-1)>>>0) + 1, r: v.r, dkLen: v.dkLen });
300+
}, Error);
301+
});
302+
303+
it('should throw with too small N', function() {
304+
assert.throws(function() {
305+
scrypt(v.password, v.salt, { N: 1, r: v.r, dkLen: v.dkLen });
306+
}, Error);
307+
});
308+
309+
it('should throw when N is not power of two', function() {
310+
assert.throws(function() {
311+
scrypt(v.password, v.salt, { N: 123, r: v.r, dkLen: v.dkLen });
312+
}, Error);
313+
});
314+
297315
it('should throw with too large parameters', function() {
298316
assert.throws(function() {
299317
scrypt(v.password, v.salt, v.logN, 1<<31, v.dkLen);
@@ -306,6 +324,12 @@ describe('limits test', function() {
306324
}, Error);
307325
});
308326

327+
it('should throw when p = 0', function() {
328+
assert.throws(function() {
329+
scrypt(v.password, v.salt, { logN: v.logN, r: v.r, p: 0, dkLen: v.dkLen});
330+
}, Error);
331+
});
332+
309333
});
310334

311335
describe('argument order test', function() {
@@ -341,6 +365,25 @@ describe('argument order test', function() {
341365
}, 'hex');
342366
});
343367

368+
});
369+
370+
describe('options test', function() {
371+
var v = shortInput;
372+
373+
it('should throw when given too many arguments', function() {
374+
assert.throws(function() {
375+
scrypt(v.password, v.salt, { logN: v.logN, r: 1, dkLen: v.dkLen }, 666, function(){});
376+
}, Error);
377+
});
378+
379+
it('should throw when there is no N or logN', function() {
380+
assert.throws(function() {
381+
scrypt(v.password, v.salt, { r: 1, dkLen: v.dkLen });
382+
}, Error);
383+
});
384+
385+
386+
344387
});
345388

346389
describe('encoding test', function() {

0 commit comments

Comments
 (0)