Skip to content

Commit

Permalink
Adding test for issue #40.
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Rohde committed Feb 19, 2018
1 parent a81c504 commit b2c771e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/delight/nashornsandbox/NashornSandboxes.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,25 @@
*/
@SuppressWarnings("all")
public class NashornSandboxes {


/**
* <p>Creates a new sandbox instance.
*
* @return The newly created sandbox instance.
*/
public static NashornSandbox create() {
return new NashornSandboxImpl();
}

/**
* <p>Create a sandbox while supplying arguments for the engine such as '--no-java'.
*
* @param args
* @return
* <p>More information on available parameters can be found in the following:
* <ul>
* <li><a href='http://hg.openjdk.java.net/jdk8/jdk8/nashorn/file/tip/docs/DEVELOPER_README'>Nashorn DEVELOPER README</a></li>
* <li><a href='https://github.com/JetBrains/jdk8u_nashorn/blob/master/src/jdk/nashorn/internal/runtime/resources/Options.properties'>Source Code Options.properties</a></li>
* <ul>
* @param args Options for initializing the Nashorn engine.
* @return A newly created sandbox instance.
*/
public static NashornSandbox create(String... args) {
return new NashornSandboxImpl(args);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package delight.nashornsandbox;

import java.io.File;

import javax.script.ScriptException;

import org.junit.Test;

import delight.nashornsandbox.exceptions.ScriptCPUAbuseException;

/**
* Test for <a href='https://github.com/javadelight/delight-nashorn-sandbox/issues/40'>issue 40</a>.
*
* @author Max Rohde
*
*/
public class TestIssue40_ScriptEngineParameters {

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

final NashornSandbox sandbox = NashornSandboxes.create("--no-java");
sandbox.allow(File.class);

// should throw an exception since 'Java' is not allowed.
sandbox.eval("var File = Java.type('java.io.File'); File;");

}

}

0 comments on commit b2c771e

Please sign in to comment.