[java-identity-provider] 01/04: IDP-1450 TDD: Tests for various nasty attribute value cases

Rod Widdowson rdw at steadingsoftware.com
Thu Jun 20 08:40:52 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=0de5d1a41a28e9036a6c6e3f8573ef4a3c412ede

commit 0de5d1a41a28e9036a6c6e3f8573ef4a3c412ede
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Jun 18 16:22:27 2019 +0100

    IDP-1450 TDD: Tests for various nasty attribute value cases
    
    https://issues.shibboleth.net/jira/browse/IDP-1450
    
    failing tests currently check for explicit failure (since in one
    future case we will create a different failure)
---
 .../spring/BaseAttributeFilterParserTest.java      |  9 ++-
 .../matcher/AttributeValueMatcherParserTest.java   | 67 ++++++++++++++++++++++
 .../matcher/attributeValueEmptyCaseSensitive.xml   |  7 +++
 .../attributeValuePropertyCaseSensitive.xml        |  6 ++
 4 files changed, 87 insertions(+), 2 deletions(-)

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 e779563..92f4f46 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
@@ -123,9 +123,8 @@ public class BaseAttributeFilterParserTest extends XMLObjectBaseTestCase {
         return policy.getPolicyRequirementRule();
     }
 
-    protected Matcher getMatcher(String fileName) throws ComponentInitializationException {
+    protected Matcher getMatcher(final String fileName, final GenericApplicationContext context) throws ComponentInitializationException {
 
-        GenericApplicationContext context = new FilesystemGenericApplicationContext();
         context.setDisplayName("ApplicationContext: Matcher");
         setTestContext(context);
         
@@ -135,7 +134,13 @@ public class BaseAttributeFilterParserTest extends XMLObjectBaseTestCase {
 
         rule.initialize();
         return rule.getMatcher();
+    }
+    
+    protected Matcher getMatcher(final String fileName) throws ComponentInitializationException {
 
+        GenericApplicationContext context = new FilesystemGenericApplicationContext();
+        context.setDisplayName("ApplicationContext: Matcher");
+        return getMatcher(fileName, 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 53d2d3b..dbfc1e5 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
@@ -20,13 +20,22 @@ package net.shibboleth.idp.attribute.filter.spring.matcher;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
 
 import java.util.Map;
 import java.util.Set;
 
+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;
@@ -147,4 +156,62 @@ public class AttributeValueMatcherParserTest extends BaseAttributeFilterParserTe
         result = matcher.getMatchingValues(uidEpaJS.get("uid"), filterContext);
         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 (BeanCreationException e) {
+            Assert.assertEquals(rootCause(e), IllegalArgumentException.class);
+        }
+    }
+    
+    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); 
+               
+        assertEquals(result, match.isCaseSensitive());
+    }
+    
+    @Test public void propertyTrueCaseSensitive() throws ComponentInitializationException {
+        propertyCaseSensitive("true", true);
+    }
+    
+    @Test public void propertyFalseCaseSensitive() throws ComponentInitializationException {
+        propertyCaseSensitive("false", false);
+    }
+
+    @Test public void propertyEmptyCaseSensitive() throws ComponentInitializationException {
+        try {
+            propertyCaseSensitive("", false);
+        } catch (BeanCreationException e) {
+            Assert.assertEquals(rootCause(e), IllegalArgumentException.class);
+        }
+    }
+
 }
diff --git a/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeValueEmptyCaseSensitive.xml b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeValueEmptyCaseSensitive.xml
new file mode 100644
index 0000000..2187e9e
--- /dev/null
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeValueEmptyCaseSensitive.xml
@@ -0,0 +1,7 @@
+<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="Value" value="jsmith" attributeID="uid"
+        caseSensitive="" />
+</AttributeRule>
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
new file mode 100644
index 0000000..b20376b
--- /dev/null
+++ b/idp-attribute-filter-spring/src/test/resources/net/shibboleth/idp/attribute/filter/matcher/attributeValuePropertyCaseSensitive.xml
@@ -0,0 +1,6 @@
+<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="Value" value="jsmith" caseSensitive="%{case}" />
+</AttributeRule>

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


More information about the commits mailing list