[java-identity-provider] 01/04: IDP-1181 Test FastFail behavior - Metadata Service + HTTPMetadataResolver

Rod Widdowson rdw at steadingsoftware.com
Fri Sep 6 06:20:17 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=13075421987f4e2616722f834ddd7574a68847b6

commit 13075421987f4e2616722f834ddd7574a68847b6
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Sep 3 09:32:23 2019 +0100

    IDP-1181 Test FastFail behavior - Metadata Service + HTTPMetadataResolver
    
    https://issues.shibboleth.net/jira/browse/IDP-1181
---
 .../spring/failfast/AbstractFailFastTest.java      | 31 ++++++----
 .../spring/failfast/MetadataFailFastTest.java      | 71 ++++++++++++++++++----
 .../idp/profile/spring/failfast/httpMetadata.xml   | 12 ++++
 3 files changed, 90 insertions(+), 24 deletions(-)

diff --git a/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/failfast/AbstractFailFastTest.java b/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/failfast/AbstractFailFastTest.java
index a6f6140d..e099796 100644
--- a/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/failfast/AbstractFailFastTest.java
+++ b/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/failfast/AbstractFailFastTest.java
@@ -26,7 +26,6 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.opensaml.core.OpenSAMLInitBaseTestCase;
-import org.opensaml.core.criterion.EntityIdCriterion;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.GenericApplicationContext;
 import org.springframework.core.io.ClassPathResource;
@@ -38,7 +37,7 @@ import org.testng.annotations.BeforeSuite;
 import net.shibboleth.ext.spring.util.ApplicationContextBuilder;
 import net.shibboleth.ext.spring.util.SpringSupport;
 import net.shibboleth.utilities.java.support.collection.Pair;
-import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
+import net.shibboleth.utilities.java.support.repository.RepositorySupport;
 import net.shibboleth.utilities.java.support.service.ReloadableService;
 
 /**
@@ -47,7 +46,7 @@ import net.shibboleth.utilities.java.support.service.ReloadableService;
 public class AbstractFailFastTest extends OpenSAMLInitBaseTestCase {
 
     private static final String PATH = "/net/shibboleth/idp/profile/spring/failfast/";
-    
+
     static private String workspaceDirName;
 
     static List<GenericApplicationContext> contexts;
@@ -65,9 +64,8 @@ public class AbstractFailFastTest extends OpenSAMLInitBaseTestCase {
         contexts = new ArrayList<>();
     }
 
-
     @SuppressWarnings("resource")
-    @AfterSuite public void tearDownContexts() {
+    @AfterSuite public void afterSuite() {
         final Iterator<GenericApplicationContext> contextIterator = contexts.iterator(); 
         while (contextIterator.hasNext()) {
             final GenericApplicationContext context;
@@ -100,7 +98,7 @@ public class AbstractFailFastTest extends OpenSAMLInitBaseTestCase {
         
         return context;
     }
-    
+
     protected ApplicationContext getApplicationContext(final String contextName, final String... files) throws IOException {
         return getApplicationContext(contextName, null, files);
     }
@@ -108,6 +106,7 @@ public class AbstractFailFastTest extends OpenSAMLInitBaseTestCase {
     protected Object getBean(final MockPropertySource propSource, final String... files) throws IOException {
         return getBean(propSource, true, files);
     }
+
     protected Object getBean(final MockPropertySource propSource, Boolean failFast, final String... files) throws IOException {
         @SuppressWarnings("rawtypes") final Class<ReloadableService> claz = ReloadableService.class;
         
@@ -126,17 +125,17 @@ public class AbstractFailFastTest extends OpenSAMLInitBaseTestCase {
             return null;
         }
     }
-    
+
     protected Object getBean(final String... files) throws IOException {
         return getBean(null, files);
     }
-        
+
     protected MockPropertySource propertySource(final String name, final String value) {
         MockPropertySource propSource = new MockPropertySource("localProperties");
         propSource.setProperty(name, value);
         return propSource;
     }
-    
+
     protected MockPropertySource propertySource(final Collection<Pair<String,String>> values) {
         MockPropertySource propSource = new MockPropertySource("localProperties");
         for (final Pair<String, String> value: values) {
@@ -144,12 +143,18 @@ public class AbstractFailFastTest extends OpenSAMLInitBaseTestCase {
         }
         return propSource;
     }
-    static public CriteriaSet criteriaFor(final String entityId) {
-        final EntityIdCriterion criterion = new EntityIdCriterion(entityId);
-        return new CriteriaSet(criterion);
-    }
 
     protected String makePath(final String filePart) {
         return workspaceDirName +  filePart;
     }
+
+    protected String makeTempPath(final String filePart) {
+        return workspaceDirName +  filePart;
+    }
+
+    protected String makeURLPath(final String filePart) {
+        return RepositorySupport.buildHTTPResourceURL("java-identity-provider", 
+                "idp-profile-spring/src/test/resources" + PATH + filePart,
+                false);
+    }
 }
diff --git a/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/failfast/MetadataFailFastTest.java b/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/failfast/MetadataFailFastTest.java
index cb2032d..a8cef01 100644
--- a/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/failfast/MetadataFailFastTest.java
+++ b/idp-profile-spring/src/test/java/net/shibboleth/idp/profile/spring/failfast/MetadataFailFastTest.java
@@ -31,11 +31,9 @@ import net.shibboleth.utilities.java.support.collection.Pair;
 import net.shibboleth.utilities.java.support.service.ReloadableService;
 import net.shibboleth.utilities.java.support.service.ServiceableComponent;
 
-/**
- *
- */
 @SuppressWarnings("unchecked")
 public class MetadataFailFastTest extends AbstractFailFastTest {
+    private static int uniquifier;
 
     @Test public void workingInline() throws IOException {
         
@@ -45,11 +43,11 @@ public class MetadataFailFastTest extends AbstractFailFastTest {
         final MetadataResolver resolver = service.getServiceableComponent().getComponent();
         assertNotNull(resolver);
     }
-    
+
     private void nonWorkingInline(final Boolean failFast) throws IOException {
         nonWorkingMetadata(failFast, propertySource("ServiceConfiguration", makePath("inLineMetadataBad.xml")));
     }
-    
+
     private void nonWorkingMetadata(final Boolean failFast,
                                     final MockPropertySource propertySource) throws IOException {
         final String beanPath;
@@ -73,7 +71,7 @@ public class MetadataFailFastTest extends AbstractFailFastTest {
     @Test public void nonWorkingInlineFailFast() throws IOException {
         nonWorkingInline(true);
     }
-    
+
     @Test public void nonWorkingInline() throws IOException {
         nonWorkingInline(false);
     }
@@ -98,11 +96,11 @@ public class MetadataFailFastTest extends AbstractFailFastTest {
                 new Pair<>("File", makePath("metadataFileBad.xml")));
         nonWorkingMetadata(failFast, propertySource(prop));
     }
-    
+
     @Test public void badFileFailFast() throws IOException {
         badFile(true);
     }
-    
+
     @Test public void badFile() throws IOException {
         badFile(false);
     }
@@ -110,7 +108,6 @@ public class MetadataFailFastTest extends AbstractFailFastTest {
     @Test public void badFileDefault() throws IOException {
         badFile(null);
     }
-    
 
     private void nonExistingFile(final Boolean failFast) throws IOException {
         final List<Pair<String, String>> prop = List.of(new Pair<>("ServiceConfiguration", makePath("fileMetadata.xml")),
@@ -121,7 +118,7 @@ public class MetadataFailFastTest extends AbstractFailFastTest {
     @Test public void notThereFileFailFast() throws IOException {
         nonExistingFile(true);
     }
-    
+
     @Test public void notThereFile() throws IOException {
         nonExistingFile(false);
     }
@@ -129,5 +126,57 @@ public class MetadataFailFastTest extends AbstractFailFastTest {
     @Test public void notThereFileDefault() throws IOException {
         nonExistingFile(null);
     }
-    
+
+    @Test public void workingHttp() throws IOException {
+        final List<Pair<String, String>> prop = List.of(
+                new Pair<>("ServiceConfiguration", makePath("httpMetadata.xml")),
+                new Pair<>("Backing", makeTempPath("workingHttpTmp" + uniquifier++ + ".xml")),
+                new Pair<>("metadataURL", makeURLPath("metadataFileGood.xml")));
+
+        final Object bean = getBean(propertySource(prop), "metadataBeansDefaultFF.xml");
+        final ReloadableService<MetadataResolver > service = (ReloadableService<MetadataResolver>) bean;
+        assertNotNull(service);
+        final MetadataResolver resolver = service.getServiceableComponent().getComponent();
+        assertNotNull(resolver);
+    }
+
+    private void badHttp(final Boolean failFast) throws IOException {
+        final List<Pair<String, String>> prop = List.of(
+                new Pair<>("ServiceConfiguration", makePath("httpMetadata.xml")),
+                new Pair<>("Backing", makeTempPath("badHttpTmp" + uniquifier++ + ".xml")),
+                new Pair<>("metadataURL", makeURLPath("metadataFileBad.xml")));
+        nonWorkingMetadata(failFast, propertySource(prop));
+    }
+
+    @Test public void badHttpFailFast() throws IOException {
+        badHttp(true);
+    }
+
+    @Test public void badHttp() throws IOException {
+        badHttp(false);
+    }
+
+    @Test public void badHttpDefault() throws IOException {
+        badHttp(null);
+    }
+
+    private void nonExistingHttp(final Boolean failFast) throws IOException {
+        final List<Pair<String, String>> prop = List.of(
+                new Pair<>("ServiceConfiguration", makePath("httpMetadata.xml")),
+                new Pair<>("Backing", makeTempPath("badHttpTmp" + uniquifier++ + ".xml")),
+                new Pair<>("metadataURL", makeURLPath("ItsNotThere.xml")));
+        nonWorkingMetadata(failFast, propertySource(prop));
+    }
+
+    @Test public void notThereHttpFailFast() throws IOException {
+        nonExistingHttp(true);
+    }
+
+    @Test public void notThereHttp() throws IOException {
+        nonExistingHttp(false);
+    }
+
+    @Test public void notThereHttpDefault() throws IOException {
+        nonExistingHttp(null);
+    }
 }
diff --git a/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/httpMetadata.xml b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/httpMetadata.xml
new file mode 100644
index 0000000..34c50e1
--- /dev/null
+++ b/idp-profile-spring/src/test/resources/net/shibboleth/idp/profile/spring/failfast/httpMetadata.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata:MetadataProvider xmlns="urn:oasis:names:tc:SAML:2.0:metadata"
+    xmlns:metadata="urn:mace:shibboleth:2.0:metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="urn:mace:shibboleth:2.0:metadata http://shibboleth.net/schema/idp/shibboleth-metadata.xsd
+                       urn:oasis:names:tc:SAML:2.0:metadata http://docs.oasis-open.org/security/saml/v2.0/saml-schema-metadata-2.0.xsd"
+
+    parserPoolRef="myParserPool" refreshDelayFactor="0.5" maxRefreshDelay="PT55M" minRefreshDelay="PT15M"
+    id="fileEntity" xsi:type="metadata:FileBackedHTTPMetadataProvider"
+    backingFile="%{Backing}"
+    metadataURL="%{metadataURL}">
+
+</metadata:MetadataProvider>
\ 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