[java-identity-provider] 03/04: IDP-1450 TDD: Further empty attribute Attribute Filter Tests

Rod Widdowson rdw at steadingsoftware.com
Thu Jun 20 08:40:54 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=6204395984290a1780ad5c658ba39e3b164deec7

commit 6204395984290a1780ad5c658ba39e3b164deec7
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Jun 19 15:46:02 2019 +0100

    IDP-1450 TDD: Further empty attribute Attribute Filter Tests
    
    https://issues.shibboleth.net/jira/browse/IDP-1450
    
    Matchers
---
 .../AttributeRequesterInEntityGroupPolicyRule.java | 13 ++++++++
 .../spring/BaseAttributeFilterParserTest.java      | 37 ++++++++++++++++++--
 .../matcher/AttributeValueMatcherParserTest.java   | 39 +++-------------------
 ...ributeRequesterInEntityGroupRuleParserTest.java | 25 ++++++++++++--
 .../MappedAttributeInMetadataRuleParserTest.java   | 36 +++++++++++++++-----
 .../attributeValuePropertyCaseSensitive.xml        |  2 +-
 .../attribute/filter/matcher/mappedInMetadata.xml  |  4 +--
 .../attribute/filter/policyrule/requesterEG2.xml   |  2 +-
 idp-conf/src/main/resources/conf/logback.xml       |  4 +--
 9 files changed, 107 insertions(+), 55 deletions(-)

diff --git a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/policyrule/saml/impl/AttributeRequesterInEntityGroupPolicyRule.java b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/policyrule/saml/impl/AttributeRequesterInEntityGroupPolicyRule.java
index 320c90d..2fba263 100644
--- a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/policyrule/saml/impl/AttributeRequesterInEntityGroupPolicyRule.java
+++ b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/policyrule/saml/impl/AttributeRequesterInEntityGroupPolicyRule.java
@@ -90,6 +90,19 @@ public class AttributeRequesterInEntityGroupPolicyRule extends AbstractPolicyRul
         checkAffiliations = flag;
     }
 
+    /**
+     * Returns whether we check a supplied {@link org.opensaml.saml.metadata.resolver.MetadataResolver}
+     * for membership in an AffiliationDescriptor
+     * as a form of group policy.
+     *
+     * @return the value of {@link #checkAffiliations}
+     *
+     * @since 4.0.0
+     */
+    public boolean isCheckAffiliations() {
+        return checkAffiliations;
+    }
+
     /** {@inheritDoc} */
     @Override
     protected void doInitialize() throws ComponentInitializationException {
diff --git a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/BaseAttributeFilterParserTest.java b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/BaseAttributeFilterParserTest.java
index 92f4f46..55dde20 100644
--- a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/BaseAttributeFilterParserTest.java
+++ b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/BaseAttributeFilterParserTest.java
@@ -25,6 +25,10 @@ import java.util.Map;
 import org.opensaml.core.xml.XMLObjectBaseTestCase;
 import org.opensaml.saml.ext.saml2mdattr.EntityAttributes;
 import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
+import org.springframework.core.env.MutablePropertySources;
+import org.springframework.core.env.StandardEnvironment;
+import org.springframework.mock.env.MockPropertySource;
 import org.testng.annotations.AfterMethod;
 
 import net.shibboleth.ext.spring.context.FilesystemGenericApplicationContext;
@@ -109,9 +113,8 @@ public class BaseAttributeFilterParserTest extends XMLObjectBaseTestCase {
         return getBean(claz, context);
     }
 
-    protected PolicyRequirementRule getPolicyRule(String fileName) throws ComponentInitializationException {
+    protected PolicyRequirementRule getPolicyRule(final String fileName, final GenericApplicationContext context) throws ComponentInitializationException {
 
-        GenericApplicationContext context = new FilesystemGenericApplicationContext();
         context.setDisplayName("ApplicationContext: Policy Rule");
 
         setTestContext(context);
@@ -123,6 +126,10 @@ public class BaseAttributeFilterParserTest extends XMLObjectBaseTestCase {
         return policy.getPolicyRequirementRule();
     }
 
+    protected PolicyRequirementRule getPolicyRule(String fileName) throws ComponentInitializationException {
+        return getPolicyRule(fileName, new FilesystemGenericApplicationContext());
+    }
+
     protected Matcher getMatcher(final String fileName, final GenericApplicationContext context) throws ComponentInitializationException {
 
         context.setDisplayName("ApplicationContext: Matcher");
@@ -143,4 +150,30 @@ public class BaseAttributeFilterParserTest extends XMLObjectBaseTestCase {
         return getMatcher(fileName, context);
     }
 
+    protected Class rootCause(Throwable what) {
+        Throwable preLast = what;
+        do {
+            final Throwable next = preLast.getCause();
+            if (next == null) {
+                return preLast.getClass();
+            }
+            preLast = next;
+        } while (true);
+    }
+    
+    protected GenericApplicationContext contextWithPropertyValue(final String propValue) {
+        final GenericApplicationContext context = new FilesystemGenericApplicationContext();
+        final MutablePropertySources propertySources = context.getEnvironment().getPropertySources();
+        final MockPropertySource mockEnvVars = new MockPropertySource();
+        mockEnvVars.setProperty("prop", propValue);
+        propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockEnvVars);
+
+        final PropertySourcesPlaceholderConfigurer placeholderConfig = new PropertySourcesPlaceholderConfigurer();
+        placeholderConfig.setPlaceholderPrefix("%{");
+        placeholderConfig.setPlaceholderSuffix("}");
+        placeholderConfig.setPropertySources(propertySources);
+        context.addBeanFactoryPostProcessor(placeholderConfig);
+        return context;
+
+    }
 }
diff --git a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/matcher/AttributeValueMatcherParserTest.java b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/matcher/AttributeValueMatcherParserTest.java
index 5118194..6fce7dc 100644
--- a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/matcher/AttributeValueMatcherParserTest.java
+++ b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/matcher/AttributeValueMatcherParserTest.java
@@ -27,16 +27,9 @@ import java.util.Set;
 
 import org.springframework.beans.FatalBeanException;
 import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.context.support.GenericApplicationContext;
-import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
-import org.springframework.core.env.MutablePropertySources;
-import org.springframework.core.env.StandardEnvironment;
-import org.springframework.mock.env.MockPropertySource;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-import junit.framework.Assert;
-import net.shibboleth.ext.spring.context.FilesystemGenericApplicationContext;
 import net.shibboleth.idp.attribute.IdPAttribute;
 import net.shibboleth.idp.attribute.IdPAttributeValue;
 import net.shibboleth.idp.attribute.filter.Matcher;
@@ -158,44 +151,20 @@ public class AttributeValueMatcherParserTest extends BaseAttributeFilterParserTe
         assertTrue(result.isEmpty());
     }
     
-    private Class rootCause(Throwable what) {
-        Throwable preLast = what;
-        do {
-            final Throwable next = preLast.getCause();
-            if (next == null) {
-                return preLast.getClass();
-            }
-            preLast = next;
-        } while (true);
-    }
-    
     @Test public void emptyCaseSensitive() throws ComponentInitializationException {
 
         try {
             getMatcher("attributeValueEmptyCaseSensitive.xml");
             fail("should have thrown an exception");
         } catch (FatalBeanException e) {
-            Assert.assertEquals(org.xml.sax.SAXParseException.class, rootCause(e));
+            assertEquals(org.xml.sax.SAXParseException.class, rootCause(e));
         } 
     }
     
     private void propertyCaseSensitive(final String propValue, final boolean result) throws ComponentInitializationException {
-    
-        final GenericApplicationContext context = new FilesystemGenericApplicationContext();
-        final MutablePropertySources propertySources = context.getEnvironment().getPropertySources();
-        final MockPropertySource mockEnvVars = new MockPropertySource();
-        mockEnvVars.setProperty("case", propValue);
-        propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockEnvVars);
-
-        final PropertySourcesPlaceholderConfigurer placeholderConfig = new PropertySourcesPlaceholderConfigurer();
-        placeholderConfig.setPlaceholderPrefix("%{");
-        placeholderConfig.setPlaceholderSuffix("}");
-        placeholderConfig.setPropertySources(propertySources);
-        context.addBeanFactoryPostProcessor(placeholderConfig);
-
         final AttributeValueStringMatcher match = (AttributeValueStringMatcher )
-            getMatcher("attributeValuePropertyCaseSensitive.xml", context); 
-               
+            getMatcher("attributeValuePropertyCaseSensitive.xml", contextWithPropertyValue(propValue)); 
+
         assertEquals(result, match.isCaseSensitive());
     }
     
@@ -211,7 +180,7 @@ public class AttributeValueMatcherParserTest extends BaseAttributeFilterParserTe
         try {
             propertyCaseSensitive("", false);
         } catch (BeanCreationException e) {
-            Assert.assertEquals(IllegalArgumentException.class, rootCause(e));
+            assertEquals(IllegalArgumentException.class, rootCause(e));
         }
     }
 
diff --git a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/saml/AttributeRequesterInEntityGroupRuleParserTest.java b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/saml/AttributeRequesterInEntityGroupRuleParserTest.java
index 9ee9f38..fd859a8 100644
--- a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/saml/AttributeRequesterInEntityGroupRuleParserTest.java
+++ b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/saml/AttributeRequesterInEntityGroupRuleParserTest.java
@@ -18,7 +18,9 @@
 package net.shibboleth.idp.attribute.filter.spring.saml;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.fail;
 
+import org.springframework.beans.factory.BeanCreationException;
 import org.testng.annotations.Test;
 
 import net.shibboleth.idp.attribute.filter.policyrule.saml.impl.AttributeRequesterInEntityGroupPolicyRule;
@@ -31,10 +33,27 @@ import net.shibboleth.utilities.java.support.component.ComponentInitializationEx
  */
 public class AttributeRequesterInEntityGroupRuleParserTest extends  BaseAttributeFilterParserTest {
 
-    @Test public void basic() throws ComponentInitializationException {
-        final AttributeRequesterInEntityGroupPolicyRule rule = (AttributeRequesterInEntityGroupPolicyRule) getPolicyRule("requesterEG2.xml");
-     
+    private void testRule(final String propValue, final boolean result) throws ComponentInitializationException {
+        final AttributeRequesterInEntityGroupPolicyRule rule = (AttributeRequesterInEntityGroupPolicyRule) getPolicyRule("requesterEG2.xml", contextWithPropertyValue(propValue));
+
         assertEquals(rule.getEntityGroup(), "urn:example.org");
+        assertEquals(rule.isCheckAffiliations(), result);
+    }
+
+    @Test public void basic() throws ComponentInitializationException {
+        try {
+            testRule("", false);
+            fail("should fail");
+        } catch (BeanCreationException e) {
+            assertEquals(IllegalArgumentException.class, rootCause(e));
+        }
+    }
+
+    @Test public void egTrue() throws ComponentInitializationException {
+        testRule("true", true);
+    }
 
+    @Test public void egFalse() throws ComponentInitializationException {
+        testRule("false", false);
     }
 }
diff --git a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/saml/MappedAttributeInMetadataRuleParserTest.java b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/saml/MappedAttributeInMetadataRuleParserTest.java
index e0d83f2..cabd10e 100644
--- a/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/saml/MappedAttributeInMetadataRuleParserTest.java
+++ b/idp-attribute-filter-spring/src/test/java/net/shibboleth/idp/attribute/filter/spring/saml/MappedAttributeInMetadataRuleParserTest.java
@@ -17,12 +17,14 @@
 
 package net.shibboleth.idp.attribute.filter.spring.saml;
 
+import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
 
+import org.springframework.beans.factory.BeanCreationException;
 import org.springframework.context.support.GenericApplicationContext;
 import org.testng.annotations.Test;
 
-import net.shibboleth.ext.spring.context.FilesystemGenericApplicationContext;
 import net.shibboleth.idp.attribute.filter.AttributeRule;
 import net.shibboleth.idp.attribute.filter.PolicyFromMatcher;
 import net.shibboleth.idp.attribute.filter.PolicyRequirementRule;
@@ -36,24 +38,40 @@ import net.shibboleth.utilities.java.support.component.ComponentInitializationEx
  */
 public class MappedAttributeInMetadataRuleParserTest extends  BaseAttributeFilterParserTest {
 
-    @Test public void mapped() throws ComponentInitializationException {
-        GenericApplicationContext context = new FilesystemGenericApplicationContext();
+     public void test(final String propValue, final boolean result) throws ComponentInitializationException {
+        GenericApplicationContext context = contextWithPropertyValue(propValue);
         setTestContext(context);
         context.setDisplayName("ApplicationContext: Matcher");
-        
+
         final AttributeRule rule = getBean(MATCHER_PATH + "mappedInMetadata.xml", AttributeRule.class, context);
         rule.initialize();
         AttributeInMetadataMatcher matcher = (AttributeInMetadataMatcher) rule.getMatcher();
-     
-        assertTrue(matcher.getMatchIfMetadataSilent());
+
+        assertEquals(matcher.getMatchIfMetadataSilent(), result);
         assertTrue(matcher.getOnlyIfRequired());
         assertTrue(matcher.getId().endsWith(":PermitRule"));
-    
+
         final PolicyFromMatcher policyRule = (PolicyFromMatcher) getBean(PolicyRequirementRule.class, context);
         matcher = (AttributeInMetadataMatcher) policyRule.getMatcher();
         assertTrue(matcher.getMatchIfMetadataSilent());
-        assertTrue(matcher.getOnlyIfRequired());
+        assertEquals(matcher.getOnlyIfRequired(), result);
         assertTrue(matcher.getId().endsWith(":PRR"));
     }
-    
+
+     @Test public void testTrue() throws ComponentInitializationException {
+         test("true", true);
+     }
+
+     @Test public void testFalse() throws ComponentInitializationException {
+         test("false", false);
+     }
+
+     @Test public void testEmpty() throws ComponentInitializationException {
+         try {
+             test("", false);
+             fail("should fail");
+         } catch (BeanCreationException e) {
+             assertEquals(IllegalArgumentException.class, rootCause(e));
+         }
+     }
 }
diff --git a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeValuePropertyCaseSensitive.xml b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeValuePropertyCaseSensitive.xml
index b20376b..b4abe3d 100644
--- a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeValuePropertyCaseSensitive.xml
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeValuePropertyCaseSensitive.xml
@@ -2,5 +2,5 @@
     	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="Value" value="jsmith" caseSensitive="%{case}" />
+    <PermitValueRule xsi:type="Value" value="jsmith" caseSensitive="%{prop}" />
 </AttributeRule>
diff --git a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/mappedInMetadata.xml b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/mappedInMetadata.xml
index 60c6ce0..82e4642 100644
--- a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/mappedInMetadata.xml
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/mappedInMetadata.xml
@@ -3,7 +3,7 @@
         xsi:schemaLocation="urn:mace:shibboleth:2.0:afp http://shibboleth.net/schema/idp/shibboleth-afp.xsd">                            
     <PolicyRequirementRule xsi:type="MappedAttributeInMetadata"
                            id="PRR"
-                           onlyIfRequired="true"
+                           onlyIfRequired="%{prop}"
                            matchIfMetadataSilent="true"/>
                             
     <AttributeRule attributeID="email">
@@ -11,7 +11,7 @@
 		<PermitValueRule xsi:type="MappedAttributeInMetadata"
                      	     id="PermitRule"
 	                         onlyIfRequired="true"
-	                         matchIfMetadataSilent="true"
+	                         matchIfMetadataSilent="%{prop}"
 	                        />
     </AttributeRule>
 </AttributeFilterPolicy>
\ No newline at end of file
diff --git a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/requesterEG2.xml b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/requesterEG2.xml
index f23729c..c92e1a8 100644
--- a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/requesterEG2.xml
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/policyrule/requesterEG2.xml
@@ -1,5 +1,5 @@
 <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="InEntityGroup" groupID="urn:example.org" />
+	<PolicyRequirementRule xsi:type="InEntityGroup" groupID="urn:example.org" checkAffiliations="%{prop}"/>
 </AttributeFilterPolicy>
diff --git a/idp-conf/src/main/resources/conf/logback.xml b/idp-conf/src/main/resources/conf/logback.xml
index cda207e..e8f2f17 100644
--- a/idp-conf/src/main/resources/conf/logback.xml
+++ b/idp-conf/src/main/resources/conf/logback.xml
@@ -14,7 +14,7 @@
 
     <!-- Location and retention. -->
     
-    <variable name="idp.logfiles" value="${idp.logfiles:-${idp.home}/logs}" />
+    <variable name="idp.logfiles" value="H:/Perforce/Juno/New/java-identity-provider/logs}" />
     <variable name="idp.loghistory" value="${idp.loghistory:-180}" />
     
     <!-- Much higher performance if you operate on DEBUG. -->
@@ -82,7 +82,7 @@
 
         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
             <charset>UTF-8</charset>
-            <Pattern>%date{ISO8601} - %mdc{idp.remote_addr} - %level [%logger:%line] - %msg%n%ex{short}</Pattern>
+            <Pattern>%date{ISO8601} - %mdc{idp.remote_addr} - %level [%logger:%line] - %msg%n%ex{full}</Pattern>
         </encoder>
 
         <!-- Ignore Velocity status page error. -->

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


More information about the commits mailing list