mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Cleanup ReDoS test.
This commit is contained in:
24
test/test.js
24
test/test.js
@@ -25359,21 +25359,21 @@
|
|||||||
assert.deepEqual(actual, [['a'], ['b'], ['c']]);
|
assert.deepEqual(actual, [['a'], ['b'], ['c']]);
|
||||||
});
|
});
|
||||||
|
|
||||||
var maxMs = 5;
|
QUnit.test('should prevent ReDoS', function(assert) {
|
||||||
QUnit.test(`should take less than ${maxMs} ms to prevent ReDoS`, function(assert) {
|
assert.expect(2);
|
||||||
assert.expect(3);
|
|
||||||
|
|
||||||
var hugeWordLen = 50000;
|
var largeWordLen = 50000,
|
||||||
var hugeWord = 'A'.repeat(hugeWordLen);
|
largeWord = 'A'.repeat(largeWordLen),
|
||||||
var startTime = Date.now();
|
maxMs = 1000,
|
||||||
assert.deepEqual(_.words(hugeWord+'AeiouAreVowels'), [hugeWord, 'Aeiou', 'Are', 'Vowels']);
|
startTime = lodashStable.now();
|
||||||
assert.deepEqual(_.words(hugeWord+'ÆiouAreVowels'), [hugeWord, 'Æiou', 'Are', 'Vowels']);
|
|
||||||
var endTime = Date.now();
|
|
||||||
var timeSpent = endTime - startTime;
|
|
||||||
|
|
||||||
assert.ok(timeSpent < maxMs, `operation took ${timeSpent} ms`);
|
assert.deepEqual(_.words(largeWord + 'ÆiouAreVowels'), [largeWord, 'Æiou', 'Are', 'Vowels']);
|
||||||
|
|
||||||
|
var endTime = lodashStable.now(),
|
||||||
|
timeSpent = endTime - startTime;
|
||||||
|
|
||||||
|
assert.ok(timeSpent < maxMs, 'operation took ' + timeSpent + 'ms');
|
||||||
});
|
});
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user