[java-identity-provider] 02/03: JSPT-95 Throw some Rhino script tests back into the IdP

Rod Widdowson rdw at steadingsoftware.com
Mon May 4 14:38:45 UTC 2020


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

rdw pushed a commit to branch dev/JSPT-95
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=06fd0f07f3d7da56061afcc3f2231b0d9ca93c8c

commit 06fd0f07f3d7da56061afcc3f2231b0d9ca93c8c
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Apr 8 16:20:25 2020 +0100

    JSPT-95 Throw some Rhino script tests back into the IdP
    
    https://issues.shibboleth.net/jira/browse/JSPT-95
---
 .../filter/spring/basic/ScriptedTest.java          | 35 +++++++++++++++++-----
 .../attribute/filter/matcher/#scripted-rhino.xml#  | 17 +++++++++++
 .../attribute/filter/matcher/scripted-rhino.xml    | 15 ++++++++++
 .../attribute/filter/policyrule/file.script.rhino  |  1 +
 .../attribute/filter/policyrule/scripted-rhino.xml |  7 +++++
 5 files changed, 68 insertions(+), 7 deletions(-)

diff --git a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/basic/ScriptedTest.java b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/basic/ScriptedTest.java
index e08903949..bc1f4bafc 100644
--- a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/basic/ScriptedTest.java
+++ b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/basic/ScriptedTest.java
@@ -47,9 +47,10 @@ public class ScriptedTest extends BaseAttributeFilterParserTest {
 
     private Map<String, IdPAttribute> epaUid;
     
-    private String getScript() {
-        return "scripted.xml";
-    }
+    private final String NASHORN_SCRIPT = "scripted.xml";
+
+    private final String RHINO_SCRIPT = "scripted-rhino.xml";
+
 
     @BeforeClass public void setupAttributes() throws ComponentInitializationException, ResolutionException {
 
@@ -57,12 +58,21 @@ public class ScriptedTest extends BaseAttributeFilterParserTest {
     }
 
     @Test public void policy() throws ComponentInitializationException {
-        final ScriptedPolicyRule rule = (ScriptedPolicyRule) getPolicyRule(getScript());
+        final ScriptedPolicyRule rule = (ScriptedPolicyRule) getPolicyRule(NASHORN_SCRIPT);
+
+        AttributeFilterContext filterContext = new AttributeFilterContext();
+        filterContext.setPrefilteredIdPAttributes(epaUid.values());
+        assertEquals(rule.matches(filterContext), Tristate.FALSE);
+    }
+    
+    @Test public void policyRhino() throws ComponentInitializationException {
+        final ScriptedPolicyRule rule = (ScriptedPolicyRule) getPolicyRule(RHINO_SCRIPT);
 
         AttributeFilterContext filterContext = new AttributeFilterContext();
         filterContext.setPrefilteredIdPAttributes(epaUid.values());
         assertEquals(rule.matches(filterContext), Tristate.FALSE);
     }
+
     
     @Test(expectedExceptions={BeanCreationException.class,}) public void policyNotFound() throws ComponentInitializationException {
 
@@ -70,7 +80,7 @@ public class ScriptedTest extends BaseAttributeFilterParserTest {
     }
     
     @Test public void matcher()  throws ComponentInitializationException {
-        final ScriptedMatcher matcher = (ScriptedMatcher) getMatcher(getScript());
+        final ScriptedMatcher matcher = (ScriptedMatcher) getMatcher(NASHORN_SCRIPT);
         
         AttributeFilterContext filterContext = new AttributeFilterContext();
         filterContext.setPrefilteredIdPAttributes(epaUid.values());
@@ -78,12 +88,23 @@ public class ScriptedTest extends BaseAttributeFilterParserTest {
         assertEquals(x.size(), 1);
         String val = ((StringAttributeValue) x.iterator().next()).getValue();
         assertTrue(val.equals("jsmith") || val.equals("daffyDuck"));
+    }
+    
+    @Test public void matcherRhino()  throws ComponentInitializationException {
+        final ScriptedMatcher matcher = (ScriptedMatcher) getMatcher(RHINO_SCRIPT);
         
+        AttributeFilterContext filterContext = new AttributeFilterContext();
+        filterContext.setPrefilteredIdPAttributes(epaUid.values());
+        Set<IdPAttributeValue> x = matcher.getMatchingValues(epaUid.get("uid"), filterContext);
+        assertEquals(x.size(), 1);
+        String val = ((StringAttributeValue) x.iterator().next()).getValue();
+        assertTrue(val.equals("jsmith") || val.equals("daffyDuck"));
     }
+
     
     @Test public void customMatcher() throws ComponentInitializationException {
         
-        final ScriptedMatcher what = (ScriptedMatcher) getMatcher(getScript());
+        final ScriptedMatcher what = (ScriptedMatcher) getMatcher(NASHORN_SCRIPT);
         
         assertNull(what.getCustomObject());
         
@@ -91,7 +112,7 @@ public class ScriptedTest extends BaseAttributeFilterParserTest {
 
     @Test public void customPolicy() throws ComponentInitializationException {
         
-        final ScriptedPolicyRule what = (ScriptedPolicyRule) getPolicyRule(getScript());
+        final ScriptedPolicyRule what = (ScriptedPolicyRule) getPolicyRule(NASHORN_SCRIPT);
         
         final Map<?,?> custom = (Map<?,?>) what.getCustomObject();
      
diff --git a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/#scripted-rhino.xml# b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/#scripted-rhino.xml#
new file mode 100644
index 000000000..715aecd56
--- /dev/null
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/#scripted-rhino.xml#
@@ -0,0 +1,17 @@
+<AttributeRule attributeID="email"
+    	xmlns="urn:mace:shibboleth:2.0:afp"
+    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="urn:mace:shibboleth:2.0:afp http://shibboleth.net/schema/idp/shibboleth-afp.xsd">
+	<PermitValueRule xsi:type="Script" language="rhino" >
+		<Script>
+        <![CDATA[
+            org.mozilla.javascript.EcmaError: ReferenceError: "importPackage" is not defined. (Script#2)
+	at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4236)
+importPackage(Packages.java.util);
+            x = new HashSet();
+            x.add(attribute.getValues().iterator().next());
+            x;
+        ]]>
+		</Script>
+	</PermitValueRule>
+</AttributeRule>
diff --git a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/scripted-rhino.xml b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/scripted-rhino.xml
new file mode 100644
index 000000000..262a9d298
--- /dev/null
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/scripted-rhino.xml
@@ -0,0 +1,15 @@
+<AttributeRule attributeID="email"
+    	xmlns="urn:mace:shibboleth:2.0:afp"
+    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="urn:mace:shibboleth:2.0:afp http://shibboleth.net/schema/idp/shibboleth-afp.xsd">
+	<PermitValueRule xsi:type="Script" language="rhino" >
+		<Script>
+        <![CDATA[
+            importPackage(Packages.java.util);
+            x = new HashSet();
+            x.add(attribute.getValues().iterator().next());
+            x;
+        ]]>
+		</Script>
+	</PermitValueRule>
+</AttributeRule>
diff --git a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/file.script.rhino b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/file.script.rhino
new file mode 100644
index 000000000..44f4cd4a5
--- /dev/null
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/file.script.rhino
@@ -0,0 +1 @@
+new java.lang.Boolean(false);
\ No newline at end of file
diff --git a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/scripted-rhino.xml b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/scripted-rhino.xml
new file mode 100644
index 000000000..bbffc6fda
--- /dev/null
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/scripted-rhino.xml
@@ -0,0 +1,7 @@
+<AttributeFilterPolicy id="MostBasicExample" xmlns="urn:mace:shibboleth:2.0:afp"
+    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="urn:mace:shibboleth:2.0:afp http://shibboleth.net/schema/idp/shibboleth-afp.xsd">
+	<PolicyRequirementRule xsi:type="Script" language="rhino"  customObjectRef="other.CustomScriptObject">
+		<ScriptFile>src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/file.script.rhino</ScriptFile>
+	</PolicyRequirementRule>
+</AttributeFilterPolicy>
\ No newline at end of file

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


More information about the commits mailing list