Skip to content

Commit 5757219

Browse files
committed
[Tests] refactor so tests are not recursive
1 parent e592c95 commit 5757219

File tree

4 files changed

+21
-51
lines changed

4 files changed

+21
-51
lines changed

test/aes.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ var bcCrypto = require('browserify-cipher/browser');
55
var bcCyphers = bcCrypto.getCiphers();
66
var randomBytes = require('pseudorandombytes');
77

8-
function runIt(i) {
8+
for (var i = 0; i < 4; i += 1) {
99
bcCrypto.listCiphers().forEach(function (cipher) {
1010
test('run: ' + i, function (t) {
11+
/* eslint no-loop-func: 0 */
1112
t.test('ciphers: ' + cipher, function (st) {
1213
st.plan(1);
1314
var data = randomBytes(562);
@@ -26,13 +27,8 @@ function runIt(i) {
2627
});
2728
});
2829
});
29-
if (i < 4) {
30-
setTimeout(runIt, 0, i + 1);
31-
}
3230
}
3331

34-
runIt(1);
35-
3632
test('getCiphers', function (t) {
3733
t.plan(1);
3834
t.ok(bcCyphers.length, 'get ciphers returns an array');

test/create-hash.js

+6-19
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,27 @@ var vectors = require('hash-test-vectors');
88

99
function runTest(name, createHash, algorithm) {
1010
test(name + ' test ' + algorithm + ' against test vectors', function (t) {
11-
function run(i) {
12-
if (i >= vectors.length) {
13-
t.end();
14-
return;
15-
}
16-
var obj = vectors[i];
17-
11+
vectors.forEach(function (obj, i) {
1812
var input = new Buffer(obj.input, 'base64');
1913
var node = obj[algorithm];
2014
var js = createHash(algorithm).update(input).digest('hex');
21-
if (js !== node) {
22-
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node);
23-
}
15+
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node);
2416

2517
encodings.forEach(function (encoding) {
2618
var eInput = new Buffer(obj.input, 'base64').toString(encoding);
2719
var eNode = obj[algorithm];
2820
var eJS = createHash(algorithm).update(eInput, encoding).digest('hex');
29-
if (eJS !== eNode) {
30-
t.equal(eJS, eNode, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + eNode);
31-
}
21+
t.equal(eJS, eNode, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + eNode);
3222
});
3323
input = new Buffer(obj.input, 'base64');
3424
node = obj[algorithm];
3525
var hash = createHash(algorithm);
3626
hash.end(input);
3727
js = hash.read().toString('hex');
38-
if (js !== node) {
39-
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node);
40-
}
41-
setTimeout(run, 0, i + 1);
42-
}
28+
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node);
29+
});
4330

44-
run(0);
31+
t.end();
4532
});
4633
}
4734

test/create-hmac.js

+8-24
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,31 @@ var vectors = require('hash-test-vectors/hmac');
88
function testLib(name, createHmac) {
99
algorithms.forEach(function (alg) {
1010
test(name + ' hmac(' + alg + ')', function (t) {
11-
function run(i) {
12-
if (i >= vectors.length) {
13-
t.end();
14-
return;
15-
}
16-
var input = vectors[i];
11+
vectors.forEach(function (input) {
1712
var output = createHmac(alg, new Buffer(input.key, 'hex'))
1813
.update(input.data, 'hex').digest();
1914

2015
output = input.truncate ? output.slice(0, input.truncate) : output;
2116
output = output.toString('hex');
22-
if (output !== input[alg]) {
23-
t.equal(output, input[alg]);
24-
}
25-
setTimeout(run, 0, i + 1);
26-
}
17+
t.equal(output, input[alg]);
18+
});
2719

28-
run(0);
20+
t.end();
2921
});
3022

3123
test('hmac(' + alg + ')', function (t) {
32-
function run(i) {
33-
if (i >= vectors.length) {
34-
t.end();
35-
return;
36-
}
37-
var input = vectors[i];
24+
vectors.forEach(function (input) {
3825
var hmac = createHmac(alg, new Buffer(input.key, 'hex'));
3926

4027
hmac.end(input.data, 'hex');
4128
var output = hmac.read();
4229

4330
output = input.truncate ? output.slice(0, input.truncate) : output;
4431
output = output.toString('hex');
45-
if (output !== input[alg]) {
46-
t.equal(output, input[alg]);
47-
}
48-
setTimeout(run, 0, i + 1);
49-
}
32+
t.equal(output, input[alg]);
33+
});
5034

51-
run(0);
35+
t.end();
5236
});
5337
});
5438
}

test/node/dh.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ test('diffie-hellman mod groups', function (t) {
3737

3838
test('diffie-hellman key lengths', function (t) {
3939
[
40-
64, 65, 192
40+
64,
41+
65,
42+
192
4143
].forEach(function (len) {
4244
t.test(String(len), function (st) {
43-
t.plan(3);
45+
st.plan(3);
46+
4447
var dh2 = cryptoB.createDiffieHellman(len);
4548
var prime2 = dh2.getPrime();
4649
var p2 = prime2.toString('hex');

0 commit comments

Comments
 (0)