[java-idp-plugin-scripting] branch main updated: JSCRIPTING-19 Nashorn does not load when nashorn.args property is set

Rod Widdowson rdw at steadingsoftware.com
Wed Feb 21 10:56:02 UTC 2024


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch main
in repository java-idp-plugin-scripting.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-scripting.git;a=commit;h=24349bf17bec9cf54af5df83df6006dca41860dd

The following commit(s) were added to refs/heads/main by this push:
     new 24349bf  JSCRIPTING-19 Nashorn does not load when nashorn.args property is set
24349bf is described below

commit 24349bf17bec9cf54af5df83df6006dca41860dd
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Feb 21 10:55:10 2024 +0000

    JSCRIPTING-19 Nashorn does not load when nashorn.args property is set
    
    https://shibboleth.atlassian.net/browse/JSCRIPTING-19
    
    Add property testing code.
---
 nashorn-jdk-impl/pom.xml                           | 10 ++++
 .../idp/plugin/scripting/nashorn/EngineTests.java  | 59 ++++++++++++++++++++++
 2 files changed, 69 insertions(+)

diff --git a/nashorn-jdk-impl/pom.xml b/nashorn-jdk-impl/pom.xml
index a64eb32..10db16b 100644
--- a/nashorn-jdk-impl/pom.xml
+++ b/nashorn-jdk-impl/pom.xml
@@ -83,6 +83,16 @@
         </dependency>
         
         <!-- Test -->
+        <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+            <scope>test</scope>
+        </dependency>        
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/nashorn-jdk-impl/src/test/java/net/shibboleth/idp/plugin/scripting/nashorn/EngineTests.java b/nashorn-jdk-impl/src/test/java/net/shibboleth/idp/plugin/scripting/nashorn/EngineTests.java
new file mode 100644
index 0000000..abab340
--- /dev/null
+++ b/nashorn-jdk-impl/src/test/java/net/shibboleth/idp/plugin/scripting/nashorn/EngineTests.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.plugin.scripting.nashorn;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Map;
+
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import javax.script.SimpleScriptContext;
+
+import org.testng.annotations.Test;
+
+/** Minimal tests for our two JSR-223 engine plug ins. */
+ at SuppressWarnings({"javadoc", "rawtypes", })
+public class EngineTests {
+    
+    private void testNashornInternal() throws ScriptException {
+        final ScriptEngineManager engineManager = new ScriptEngineManager();
+        final ScriptEngine scriptEngine = engineManager.getEngineByName("javascript");
+        final ScriptContext ctx = new SimpleScriptContext();
+        final String script = "var s = new java.util.HashMap(2); s.put('a',b); s";
+
+        ctx.setAttribute("b", this, ScriptContext.ENGINE_SCOPE);
+        
+        final Object o = scriptEngine.eval(script, ctx);
+        
+        assertTrue(o instanceof Map);
+        final Map map = (Map) o;
+        assertEquals(map.size(), 1);
+        assertEquals(map.get("a"), this);
+    }
+    @Test public void testNashorn() throws ScriptException {
+        testNashornInternal();
+    }
+
+    @Test public void testNashornProps() throws ScriptException {
+        System.setProperty("nashorn.debug", "true");
+        System.setProperty("nashorn.args", "-D--no-deprecation-warning");
+        testNashornInternal();
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list