Skip to content

Commit

Permalink
Ensuring test for #117 works with new limits
Browse files Browse the repository at this point in the history
  • Loading branch information
mxro committed Jul 27, 2024
1 parent a4849ea commit 46928cd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/test/java/delight/nashornsandbox/TestIssue117.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@ public static String getMatchStr(String regex, int repl) {
return sb.toString();
}

@Test
@Test(expected = ScriptCPUAbuseException.class)
public void test() throws ScriptCPUAbuseException, ScriptException, NoSuchMethodException {

NashornSandbox sandbox = NashornSandboxes.create();

for (int i = 480; i <= 500; i++) {
for (int i = 4800; i <= 4820; i++) {
long startTime = System.currentTimeMillis();
String js_script = getMatchStr("(([^;]+;){9}[^;]+)", i);
try {
sandbox.eval(js_script);
} catch (Exception e) {
throw e;
}
long endTime = System.currentTimeMillis();
long costTime = endTime - startTime;
Assert.assertTrue("RegEx attack successful. Took longer than 5000 ms to resolve script. Time required: "+costTime, costTime <= 5000);
Assert.assertTrue("RegEx attack successful. Script ran for longer 120000 ms. Time required: "+costTime, costTime <= 120000);
}
}
}

0 comments on commit 46928cd

Please sign in to comment.