[java-identity-provider] 02/04: IDP-1181 Test FastFail behavior - AttributeFilterService

Rod Widdowson rdw at steadingsoftware.com
Fri Sep 6 06:20:18 EDT 2019


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

rdw pushed a commit to branch master
in repository java-identity-provider.

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

commit d27869c7983315aa1553891e1eed338d2e4137ee
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Sep 3 13:35:13 2019 +0100

    IDP-1181 Test FastFail behavior - AttributeFilterService
    
    https://issues.shibboleth.net/jira/browse/IDP-1181
---
 idp-profile-spring/pom.xml                         | 10 ++-
 .../spring/failfast/FilterFailFastTest.java        | 92 ++++++++++++++++++++++
 .../profile/spring/failfast/attributeFilterBad.xml | 15 ++++
 .../spring/failfast/attributeFilterBadScript.xml   | 19 +++++
 .../spring/failfast/attributeFilterGood.xml        | 15 ++++
 .../idp/profile/spring/failfast/filterBeans.xml    | 51 ++++++++++++
 .../spring/failfast/filterBeansDefaultFF.xml       | 50 ++++++++++++
 7 files changed, 251 insertions(+), 1 deletion(-)

diff --git a/idp-profile-spring/pom.xml b/idp-profile-spring/pom.xml
index 7ee5c1b..8aa21c9 100644
--- a/idp-profile-spring/pom.xml
+++ b/idp-profile-spring/pom.xml
@@ -143,6 +143,7 @@
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
+        
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>idp-profile-api</artifactId>
@@ -150,7 +151,14 @@
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
-
+        
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>idp-attribute-filter-spring</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        
         <dependency>
             <groupId>net.shibboleth.ext</groupId>
             <artifactId>spring-extensions</artifactId>
diff --git a/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/failfast/FilterFailFastTest.java b/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/failfast/FilterFailFastTest.java
new file mode 100644
index 0000000..00a3075
--- /dev/null
+++ b/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/failfast/FilterFailFastTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.profile.spring.failfast;
+
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+
+import java.io.IOException;
+
+import org.testng.annotations.Test;
+
+import net.shibboleth.idp.attribute.filter.AttributeFilter;
+import net.shibboleth.utilities.java.support.service.ReloadableService;
+import net.shibboleth.utilities.java.support.service.ServiceableComponent;
+
+ at SuppressWarnings("unchecked")
+public class FilterFailFastTest extends AbstractFailFastTest {
+    @Test public void workingFilter() throws IOException {
+        
+        final Object bean = getBean(propertySource("ServiceConfiguration", makePath("attributeFilterGood.xml")), "filterBeansDefaultFF.xml");
+        final ReloadableService<AttributeFilter > service = (ReloadableService<AttributeFilter>) bean;
+        assertNotNull(service);
+        final AttributeFilter resolver = service.getServiceableComponent().getComponent();
+        assertNotNull(resolver);
+    }
+
+    private void badFilter(final Boolean failFast, String filterFile) throws IOException {
+        final String beanPath;
+        if (failFast == null) {
+            beanPath = "filterBeansDefaultFF.xml";
+        } else {
+            beanPath = "filterBeans.xml";
+        }
+
+        final Object bean = getBean(propertySource("ServiceConfiguration", makePath(filterFile)), failFast, beanPath);
+        final ReloadableService<AttributeFilter > service = (ReloadableService<AttributeFilter>) bean;
+        if (null != failFast && failFast) {
+            assertNull(service);
+            return;
+        }
+        assertNotNull(service);
+        final ServiceableComponent<AttributeFilter> component = service.getServiceableComponent();
+        assertNull(component);
+    }
+    private void badFilter(final Boolean failFast) throws IOException {
+        badFilter(failFast, "attributeFilterBad.xml");
+    }
+    
+    @Test public void badFilterFailFast() throws IOException {
+        badFilter(true);
+    }
+
+    @Test public void badFilterNoFailFast() throws IOException {
+        badFilter(false);
+    }
+
+    @Test public void badFilterDefaultFailFast() throws IOException {
+        badFilter(null);
+    }
+
+    private void badScript(final Boolean failFast) throws IOException {
+        badFilter(failFast, "attributeFilterBadScript.xml");
+    }
+    
+    @Test public void badScriptFailFast() throws IOException {
+        badScript(true);
+    }
+
+    @Test public void badScriptNoFailFast() throws IOException {
+        badScript(false);
+    }
+
+    @Test public void badScriptDefaultFailFast() throws IOException {
+        badScript(null);
+    }
+
+}
diff --git a/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/attributeFilterBad.xml b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/attributeFilterBad.xml
new file mode 100644
index 0000000..b8aa67d
--- /dev/null
+++ b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/attributeFilterBad.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<AttributeFilterPolicyGroup id="PolicyExample3"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+        xmlns="urn:mace:shibboleth:2.0:afp"
+        xsi:schemaLocation="urn:mace:shibboleth:2.0:afp http://shibboleth.net/schema/idp/shibboleth-afp.xsd">
+
+    <AttributeFilterPolicy id="MostBasicExample">
+        <PolicyRequirementRule xsi:type="ANY"/>
+        
+        <AttributeRule attributeID="email">
+            <PermitValueRule xsi:type="Elephant"/>
+        </AttributeRule>
+    </AttributeFilterPolicy>
+    
+</AttributeFilterPolicyGroup>
diff --git a/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/attributeFilterBadScript.xml b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/attributeFilterBadScript.xml
new file mode 100644
index 0000000..1af943a
--- /dev/null
+++ b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/attributeFilterBadScript.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<AttributeFilterPolicyGroup id="PolicyExample3"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+        xmlns="urn:mace:shibboleth:2.0:afp"
+        xsi:schemaLocation="urn:mace:shibboleth:2.0:afp http://shibboleth.net/schema/idp/shibboleth-afp.xsd">
+
+    <AttributeFilterPolicy id="MostBasicExample">
+        <PolicyRequirementRule xsi:type="ANY"/>
+        
+        <AttributeRule attributeID="email">
+    <PermitValueRule xsi:type="Script">
+        <Script>
+        <![CDATA[@@@!@"%£^$*I!P£_XJDU£K]]>
+        </Script>
+    </PermitValueRule>
+        </AttributeRule>
+    </AttributeFilterPolicy>
+    
+</AttributeFilterPolicyGroup>
diff --git a/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/attributeFilterGood.xml b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/attributeFilterGood.xml
new file mode 100644
index 0000000..4441bca
--- /dev/null
+++ b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/attributeFilterGood.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<AttributeFilterPolicyGroup id="PolicyExample3"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+        xmlns="urn:mace:shibboleth:2.0:afp"
+        xsi:schemaLocation="urn:mace:shibboleth:2.0:afp http://shibboleth.net/schema/idp/shibboleth-afp.xsd">
+
+    <AttributeFilterPolicy id="MostBasicExample">
+        <PolicyRequirementRule xsi:type="ANY"/>
+        
+        <AttributeRule attributeID="email">
+            <PermitValueRule xsi:type="ANY"/>
+        </AttributeRule>
+    </AttributeFilterPolicy>
+    
+</AttributeFilterPolicyGroup>
diff --git a/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/filterBeans.xml b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/filterBeans.xml
new file mode 100644
index 0000000..e066061
--- /dev/null
+++ b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/filterBeans.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:context="http://www.springframework.org/schema/context"
+	xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p"
+	xmlns:c="http://www.springframework.org/schema/c" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
+
+	default-init-method="initialize" default-destroy-method="destroy">
+
+    <bean id="shibboleth.PropertySourcesPlaceholderConfigurer"
+        class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"
+        p:placeholderPrefix="%{" p:placeholderSuffix="}" />
+
+   <bean id="shibboleth.IdentifiableBeanPostProcessor" class="net.shibboleth.ext.spring.config.IdentifiableBeanPostProcessor" />
+
+    <!-- This bean MUST be called "conversionService" to work properly. -->
+    <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
+        <property name="converters">
+            <set>
+                <bean class="net.shibboleth.ext.spring.config.StringToIPRangeConverter" />
+                <bean class="net.shibboleth.ext.spring.config.BooleanToPredicateConverter" />
+                <bean class="net.shibboleth.ext.spring.config.StringBooleanToPredicateConverter" />
+                <bean class="net.shibboleth.ext.spring.config.StringToResourceConverter" />
+                <bean class="net.shibboleth.ext.spring.config.FunctionToFunctionConverter" />
+                <bean class="net.shibboleth.ext.spring.config.PredicateToPredicateConverter" />
+                <bean class="net.shibboleth.ext.spring.config.StringToDurationConverter" />
+            </set>
+        </property>
+    </bean>
+
+    <bean id="myParserPool"
+        class="net.shibboleth.utilities.java.support.xml.BasicParserPool"
+        p:maxPoolSize="1000"
+        p:coalescing="true" p:ignoreComments="true"
+        p:ignoreElementContentWhitespace="true" p:namespaceAware="true" />
+        
+    <bean id="shibboleth.AttributeFilterService" class="net.shibboleth.ext.spring.service.ReloadableSpringService"
+        p:serviceConfigurations="%{ServiceConfiguration}"
+        p:beanFactoryPostProcessors-ref="shibboleth.PropertySourcesPlaceholderConfigurer"
+        p:beanPostProcessors-ref="shibboleth.IdentifiableBeanPostProcessor"
+        p:reloadCheckDelay="0"
+        p:failFast="%{failFast}">
+        <constructor-arg name="claz" value="net.shibboleth.idp.attribute.filter.AttributeFilter" />
+        <constructor-arg name="strategy">
+            <bean class="net.shibboleth.idp.attribute.filter.spring.impl.AttributeFilterServiceStrategy"
+                id="ShibbolethAttributeFilter"/>
+        </constructor-arg>
+    </bean>
+</beans>
\ No newline at end of file
diff --git a/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/filterBeansDefaultFF.xml b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/filterBeansDefaultFF.xml
new file mode 100644
index 0000000..aa46828
--- /dev/null
+++ b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/filterBeansDefaultFF.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:context="http://www.springframework.org/schema/context"
+	xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p"
+	xmlns:c="http://www.springframework.org/schema/c" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
+
+	default-init-method="initialize" default-destroy-method="destroy">
+
+    <bean id="shibboleth.PropertySourcesPlaceholderConfigurer"
+        class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"
+        p:placeholderPrefix="%{" p:placeholderSuffix="}" />
+
+   <bean id="shibboleth.IdentifiableBeanPostProcessor" class="net.shibboleth.ext.spring.config.IdentifiableBeanPostProcessor" />
+
+    <!-- This bean MUST be called "conversionService" to work properly. -->
+    <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
+        <property name="converters">
+            <set>
+                <bean class="net.shibboleth.ext.spring.config.StringToIPRangeConverter" />
+                <bean class="net.shibboleth.ext.spring.config.BooleanToPredicateConverter" />
+                <bean class="net.shibboleth.ext.spring.config.StringBooleanToPredicateConverter" />
+                <bean class="net.shibboleth.ext.spring.config.StringToResourceConverter" />
+                <bean class="net.shibboleth.ext.spring.config.FunctionToFunctionConverter" />
+                <bean class="net.shibboleth.ext.spring.config.PredicateToPredicateConverter" />
+                <bean class="net.shibboleth.ext.spring.config.StringToDurationConverter" />
+            </set>
+        </property>
+    </bean>
+
+    <bean id="myParserPool"
+        class="net.shibboleth.utilities.java.support.xml.BasicParserPool"
+        p:maxPoolSize="1000"
+        p:coalescing="true" p:ignoreComments="true"
+        p:ignoreElementContentWhitespace="true" p:namespaceAware="true" />
+        
+    <bean id="shibboleth.AttributeFilterService" class="net.shibboleth.ext.spring.service.ReloadableSpringService"
+        p:serviceConfigurations="%{ServiceConfiguration}"
+        p:beanFactoryPostProcessors-ref="shibboleth.PropertySourcesPlaceholderConfigurer"
+        p:beanPostProcessors-ref="shibboleth.IdentifiableBeanPostProcessor"
+        p:reloadCheckDelay="0">
+        <constructor-arg name="claz" value="net.shibboleth.idp.attribute.filter.AttributeFilter" />
+        <constructor-arg name="strategy">
+            <bean class="net.shibboleth.idp.attribute.filter.spring.impl.AttributeFilterServiceStrategy"
+                id="ShibbolethAttributeFilter"/>
+        </constructor-arg>
+    </bean>
+</beans>
\ 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