[java-shib-attribute] branch main updated: Flesh out tests, fix some logging.

Scott Cantor cantor.2 at osu.edu
Fri Mar 3 19:20:01 UTC 2023


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

scantor pushed a commit to branch main
in repository java-shib-attribute.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-attribute.git;a=commit;h=a774358dd2d217d572f52273a6ae2d64f931e635

The following commit(s) were added to refs/heads/main by this push:
     new a774358dd Flesh out tests, fix some logging.
a774358dd is described below

commit a774358dd2d217d572f52273a6ae2d64f931e635
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Fri Mar 3 14:19:58 2023 -0500

    Flesh out tests, fix some logging.
---
 .../config/SetConfigurationLookupStrategy.java     |   4 +-
 .../spring/MetadataDrivenConfigurationTest.java    | 143 ++++++++++++++++++++-
 .../src/test/resources/logback-test.xml            |   1 +
 .../idp/saml/attribute/impl/metadata.xml           |  26 +++-
 4 files changed, 168 insertions(+), 6 deletions(-)

diff --git a/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/SetConfigurationLookupStrategy.java b/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/SetConfigurationLookupStrategy.java
index efcc1b6c5..d8e423299 100644
--- a/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/SetConfigurationLookupStrategy.java
+++ b/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/SetConfigurationLookupStrategy.java
@@ -51,7 +51,7 @@ public class SetConfigurationLookupStrategy<T> extends AbstractCollectionConfigu
     @Override
     @Nullable protected Set<T> doTranslate(@Nonnull final IdPAttribute tag) {
 
-        log.debug("Converting tag '{}' to List<{}> property", tag.getId(), getPropertyType().getSimpleName());
+        log.debug("Converting tag '{}' to Set<{}> property", tag.getId(), getPropertyType().getSimpleName());
         
         final List<IdPAttributeValue> values = tag.getValues();
         final Set<T> result = new HashSet<>(values.size());
@@ -75,7 +75,7 @@ public class SetConfigurationLookupStrategy<T> extends AbstractCollectionConfigu
     @Override
     @Nullable protected Set<T> doTranslate(@Nonnull final Attribute tag) {
         
-        log.debug("Converting tag '{}' to Set<String> property", tag.getName());
+        log.debug("Converting tag '{}' to Set<> property", tag.getName());
         
         final List<XMLObject> values = tag.getAttributeValues();
         final Set<T> result = new HashSet<>(values.size());
diff --git a/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/MetadataDrivenConfigurationTest.java b/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/MetadataDrivenConfigurationTest.java
index b19a2faeb..06ce39e66 100644
--- a/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/MetadataDrivenConfigurationTest.java
+++ b/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/MetadataDrivenConfigurationTest.java
@@ -21,6 +21,7 @@ import static org.testng.Assert.*;
 
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.List;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -29,7 +30,9 @@ import org.opensaml.core.testing.XMLObjectBaseTestCase;
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.opensaml.profile.testing.RequestContextBuilder;
 import org.opensaml.saml.metadata.resolver.filter.FilterException;
+import org.opensaml.saml.saml2.core.Attribute;
 import org.opensaml.saml.saml2.metadata.EntityDescriptor;
+import org.opensaml.saml.saml2.metadata.RequestedAttribute;
 import org.springframework.context.support.ConversionServiceFactoryBean;
 import org.springframework.context.support.GenericApplicationContext;
 import org.testng.Assert;
@@ -40,12 +43,16 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import net.shibboleth.idp.attribute.config.BooleanConfigurationLookupStrategy;
+import net.shibboleth.idp.attribute.config.ListConfigurationLookupStrategy;
+import net.shibboleth.idp.attribute.config.LongConfigurationLookupStrategy;
+import net.shibboleth.idp.attribute.config.SetConfigurationLookupStrategy;
 import net.shibboleth.idp.attribute.config.StringConfigurationLookupStrategy;
 import net.shibboleth.idp.attribute.transcoding.AttributeTranscoderRegistry;
 import net.shibboleth.idp.saml.attribute.impl.AttributeMappingNodeProcessor;
 import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.FunctionSupport;
+import net.shibboleth.shared.primitive.DeprecationSupport;
 import net.shibboleth.shared.service.ReloadableService;
 import net.shibboleth.shared.spring.config.StringToDurationConverter;
 import net.shibboleth.shared.spring.custom.SchemaTypeAwareXMLBeanDefinitionReader;
@@ -122,7 +129,7 @@ public class MetadataDrivenConfigurationTest extends XMLObjectBaseTestCase {
         final BooleanConfigurationLookupStrategy fn = new BooleanConfigurationLookupStrategy();
         fn.setProfileMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
         fn.setMessageMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
-        fn.setPropertyName("encryptAssertions");
+        fn.setPropertyName("boolean");
         fn.setEnableCaching(false);
         fn.initialize();
         
@@ -143,7 +150,7 @@ public class MetadataDrivenConfigurationTest extends XMLObjectBaseTestCase {
         final BooleanConfigurationLookupStrategy fn = new BooleanConfigurationLookupStrategy();
         fn.setProfileMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
         fn.setMessageMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
-        fn.setPropertyName("encryptAssertions");
+        fn.setPropertyName("boolean");
         fn.setEnableCaching(false);
         fn.setProfileAliases(CollectionSupport.singletonList("http://shibboleth.net/ns/profiles"));
         fn.initialize();
@@ -160,4 +167,136 @@ public class MetadataDrivenConfigurationTest extends XMLObjectBaseTestCase {
         Assert.assertEquals(fn.apply(prc), true);
     }
 
+    @Test public void testBooleanLegacyTag() throws ComponentInitializationException, FilterException {
+
+        final BooleanConfigurationLookupStrategy fn = new BooleanConfigurationLookupStrategy();
+        fn.setProfileMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
+        fn.setMessageMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
+        fn.setPropertyName("booleanNew");
+        fn.setLegacyPropertyName("boolean");
+        fn.setEnableCaching(false);
+        fn.initialize();
+        
+        prc.setProfileId("http://shibboleth.net/ns/profiles/saml2/sso/browser");
+
+        // Unmapped.
+        Assert.assertEquals(fn.apply(prc), true);
+        
+        DeprecationSupport.clearWarningState();
+
+        assert processor != null;
+        processor.process(entityDescriptor);
+
+        // Mapped.
+        Assert.assertEquals(fn.apply(prc), true);
+    }
+    
+    @Test public void testStringProfileTag() throws ComponentInitializationException, FilterException {
+
+        final StringConfigurationLookupStrategy fn = new StringConfigurationLookupStrategy();
+        fn.setProfileMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
+        fn.setMessageMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
+        fn.setPropertyName("string");
+        fn.setEnableCaching(false);
+        fn.initialize();
+        
+        prc.setProfileId("http://shibboleth.net/ns/profiles/saml2/sso/browser");
+
+        // Unmapped.
+        Assert.assertEquals(fn.apply(prc), "foo");
+
+        assert processor != null;
+        processor.process(entityDescriptor);
+
+        // Mapped.
+        Assert.assertEquals(fn.apply(prc), "foo");
+    }
+    
+    @Test public void testLongProfileTag() throws ComponentInitializationException, FilterException {
+
+        final LongConfigurationLookupStrategy fn = new LongConfigurationLookupStrategy();
+        fn.setProfileMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
+        fn.setMessageMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
+        fn.setPropertyName("long");
+        fn.setEnableCaching(false);
+        fn.initialize();
+        
+        prc.setProfileId("http://shibboleth.net/ns/profiles/saml2/sso/browser");
+
+        // Unmapped.
+        Assert.assertEquals(fn.apply(prc), 42);
+
+        assert processor != null;
+        processor.process(entityDescriptor);
+
+        // Mapped.
+        Assert.assertEquals(fn.apply(prc), 42);
+    }
+
+    @Test public void testListProfileTag() throws ComponentInitializationException, FilterException {
+
+        final ListConfigurationLookupStrategy<String> fn = new ListConfigurationLookupStrategy<>();
+        fn.setProfileMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
+        fn.setMessageMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
+        fn.setPropertyName("list");
+        fn.setEnableCaching(false);
+        fn.setPropertyType(String.class);
+        fn.initialize();
+        
+        prc.setProfileId("http://shibboleth.net/ns/profiles/saml2/sso/browser");
+
+        // Unmapped.
+        Assert.assertEquals(fn.apply(prc), CollectionSupport.listOf("foo", "bar"));
+
+        assert processor != null;
+        processor.process(entityDescriptor);
+
+        // Mapped.
+        Assert.assertEquals(fn.apply(prc), CollectionSupport.listOf("foo", "bar"));
+    }
+
+    @Test public void testSetProfileTag() throws ComponentInitializationException, FilterException {
+
+        final SetConfigurationLookupStrategy<String> fn = new SetConfigurationLookupStrategy<>();
+        fn.setProfileMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
+        fn.setMessageMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
+        fn.setPropertyName("list");
+        fn.setEnableCaching(false);
+        fn.setPropertyType(String.class);
+        fn.initialize();
+        
+        prc.setProfileId("http://shibboleth.net/ns/profiles/saml2/sso/browser");
+
+        // Unmapped.
+        Assert.assertEquals(fn.apply(prc), CollectionSupport.setOf("foo", "bar"));
+
+        assert processor != null;
+        processor.process(entityDescriptor);
+
+        // Mapped.
+        Assert.assertEquals(fn.apply(prc), CollectionSupport.setOf("foo", "bar"));
+    }
+
+    @Test public void testComplexListProfileTag() throws ComponentInitializationException, FilterException {
+
+        final ListConfigurationLookupStrategy<RequestedAttribute> fn = new ListConfigurationLookupStrategy<>();
+        fn.setProfileMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
+        fn.setMessageMetadataLookupStrategy(FunctionSupport.constant(entityDescriptor));
+        fn.setPropertyName("complex");
+        fn.setEnableCaching(false);
+        fn.setPropertyType(RequestedAttribute.class);
+        fn.initialize();
+        
+        prc.setProfileId("http://shibboleth.net/ns/profiles/saml2/sso/browser");
+
+        // Unmapped.
+        
+        final List<RequestedAttribute> attrs = fn.apply(prc);
+        assert attrs != null; 
+        Assert.assertEquals(attrs.size(), 2);
+        Assert.assertTrue("foo".equals(attrs.get(0).getName()));
+        Assert.assertTrue(Attribute.URI_REFERENCE.equals(attrs.get(0).getNameFormat()));
+        Assert.assertTrue("bar".equals(attrs.get(1).getName()));
+        Assert.assertTrue(Attribute.BASIC.equals(attrs.get(1).getNameFormat()));
+    }
 }
\ No newline at end of file
diff --git a/shib-attribute-resolver-spring/src/test/resources/logback-test.xml b/shib-attribute-resolver-spring/src/test/resources/logback-test.xml
index 144e1c2a6..6fc5883d1 100644
--- a/shib-attribute-resolver-spring/src/test/resources/logback-test.xml
+++ b/shib-attribute-resolver-spring/src/test/resources/logback-test.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <configuration>
+    <logger name="net.shibboleth.idp.attribute.config" level="DEBUG"/>
     <logger name="net.shibboleth.idp.attribute.resolver.spring" level="DEBUG"/>
     <logger name="net.shibboleth.idp.attribute.transcoding.spring" level="DEBUG"/>
     <logger name="net.shibboleth.idp.attribute.resolver" level="DEBUG"/>
diff --git a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/saml/attribute/impl/metadata.xml b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/saml/attribute/impl/metadata.xml
index 65a6788d4..980aa3aef 100644
--- a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/saml/attribute/impl/metadata.xml
+++ b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/saml/attribute/impl/metadata.xml
@@ -8,13 +8,35 @@
 				</saml:AttributeValue>
 			</saml:Attribute>
             <!-- For testing metadata driven config, -->
-            <saml:Attribute Name="http://shibboleth.net/ns/profiles/saml2/sso/browser/encryptAssertions"
+            <saml:Attribute Name="http://shibboleth.net/ns/profiles/saml2/sso/browser/boolean"
                 NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
                 <saml:AttributeValue>true</saml:AttributeValue>
             </saml:Attribute>
-            <saml:Attribute Name="http://shibboleth.net/ns/profiles/encryptAssertions"
+            <saml:Attribute Name="http://shibboleth.net/ns/profiles/boolean"
                 NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
                 <saml:AttributeValue>true</saml:AttributeValue>
+            </saml:Attribute>
+            <saml:Attribute Name="http://shibboleth.net/ns/profiles/saml2/sso/browser/string"
+                NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
+                <saml:AttributeValue>foo</saml:AttributeValue>
+            </saml:Attribute>
+            <saml:Attribute Name="http://shibboleth.net/ns/profiles/saml2/sso/browser/long"
+                NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
+                <saml:AttributeValue>42</saml:AttributeValue>
+            </saml:Attribute>
+            <saml:Attribute Name="http://shibboleth.net/ns/profiles/saml2/sso/browser/list"
+                NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
+                <saml:AttributeValue>foo</saml:AttributeValue>
+                <saml:AttributeValue>bar</saml:AttributeValue>
+            </saml:Attribute>
+            <saml:Attribute Name="http://shibboleth.net/ns/profiles/saml2/sso/browser/complex"
+                NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
+                <saml:AttributeValue>
+                    <RequestedAttribute Name="foo" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" />
+                </saml:AttributeValue>
+                <saml:AttributeValue>
+                    <RequestedAttribute Name="bar" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" />
+                </saml:AttributeValue>
             </saml:Attribute>
 		</mdattr:EntityAttributes>
 	</Extensions>

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


More information about the commits mailing list