Cleanup ReDoS test.

This commit is contained in:
John-David Dalton
2018-08-30 22:33:55 -07:00
parent 5c08f18d36
commit 6e62e1e8df

View File

@@ -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');
}); });
}()); }());
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/