Skip to content

Commit

Permalink
Merge pull request #1 from UziTech/pr/1460
Browse files Browse the repository at this point in the history
create dynamic redos specs
  • Loading branch information
andersk committed Apr 4, 2019
2 parents bd789b3 + bcb51f9 commit 830413b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
1 change: 0 additions & 1 deletion test/redos/quadratic_br.html

This file was deleted.

4 changes: 4 additions & 0 deletions test/redos/quadratic_br.js
@@ -0,0 +1,4 @@
module.exports = {
markdown: `a${' '.repeat(50000)}`,
html: `<p>a${' '.repeat(50000)}</p>`
};
1 change: 0 additions & 1 deletion test/redos/quadratic_br.md

This file was deleted.

1 change: 0 additions & 1 deletion test/redos/quadratic_email.html

This file was deleted.

4 changes: 4 additions & 0 deletions test/redos/quadratic_email.js
@@ -0,0 +1,4 @@
module.exports = {
markdown: 'a'.repeat(50000),
html: `<p>${'a'.repeat(50000)}</p>`
};
1 change: 0 additions & 1 deletion test/redos/quadratic_email.md

This file was deleted.

22 changes: 22 additions & 0 deletions test/specs/redos-spec.js
@@ -0,0 +1,22 @@
const path = require('path');
const fs = require('fs');

describe('ReDOS tests', () => {
const files = fs.readdirSync(path.resolve(__dirname, '../redos/'));
files.forEach(file => {
if (!file.match(/\.js$/)) {
return;
}

it(file, () => {
const spec = require(path.resolve(__dirname, '../redos', file));
const before = process.hrtime();
expect(spec).toRender(spec.html);
const elapsed = process.hrtime(before);
if (elapsed[0] > 0) {
const s = (elapsed[0] + elapsed[1] * 1e-9).toFixed(3);
fail(`took too long: ${s}s`);
}
});
});
});

0 comments on commit 830413b

Please sign in to comment.