[java-plugin-shibd] branch main updated: Reorganize test data to avoid stepping on real files.

Scott Cantor cantor.2 at osu.edu
Tue Jul 2 20:39:10 UTC 2024


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

scantor pushed a commit to branch main
in repository java-plugin-shibd.

View the commit online:
http://git.shibboleth.net/view/?p=java-plugin-shibd.git;a=commit;h=0a1fc2f167c3201698ed7717caa3091c09738ae3

The following commit(s) were added to refs/heads/main by this push:
     new 0a1fc2f  Reorganize test data to avoid stepping on real files.
0a1fc2f is described below

commit 0a1fc2f167c3201698ed7717caa3091c09738ae3
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Jul 2 16:39:07 2024 -0400

    Reorganize test data to avoid stepping on real files.
---
 .../net/shibboleth/idp/module/conf/sp/agents.xml   |  2 +-
 .../shibboleth/sp/flows/AbstractSPFlowTest.java    | 12 +++--
 ...SPEnvironmentApplicationContextInitializer.java | 52 ++++++++++++++++++++++
 .../shibboleth/idp/module/conf/sp/test-agents.xml  | 23 ++++++++++
 .../resources/net/shibboleth/sp/test-beans.xml     | 23 ++++++++++
 5 files changed, 108 insertions(+), 4 deletions(-)

diff --git a/sp-conf-impl/src/main/resources/net/shibboleth/idp/module/conf/sp/agents.xml b/sp-conf-impl/src/main/resources/net/shibboleth/idp/module/conf/sp/agents.xml
index 84972a1..cdf25ef 100644
--- a/sp-conf-impl/src/main/resources/net/shibboleth/idp/module/conf/sp/agents.xml
+++ b/sp-conf-impl/src/main/resources/net/shibboleth/idp/module/conf/sp/agents.xml
@@ -21,7 +21,7 @@
 
     <!-- ============ Agents and their Applications ============ -->
 
-    <bean id="sp.example.org" parent="shibboleth.Agent" p:sharedSecrets="foo">
+    <bean id="sp.example.org" parent="shibboleth.Agent">
         <property name="applications">
             <set>
                 <bean p:id="default" parent="shibboleth.Application" p:issuer="https://sp.example.org"/>
diff --git a/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/AbstractSPFlowTest.java b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/AbstractSPFlowTest.java
index 9829569..56c7e96 100644
--- a/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/AbstractSPFlowTest.java
+++ b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/AbstractSPFlowTest.java
@@ -44,8 +44,14 @@ import net.shibboleth.sp.ddf.DDF;
 /**
  * Abstract unit test class for SP flows.
  */
- at ContextConfiguration(locations = { "classpath*:/META-INF/net.shibboleth.idp/postconfig.xml",})
- at SuppressWarnings("null")
+ at ContextConfiguration(
+        locations = {
+                "classpath*:/META-INF/net.shibboleth.idp/postconfig.xml",
+                "classpath*:/net/shibboleth/sp/test-beans.xml", },
+        initializers = {
+                TestSPEnvironmentApplicationContextInitializer.class,
+                }
+        )
 public abstract class AbstractSPFlowTest extends AbstractFlowTest {
     
     /** End state ID. */
@@ -123,7 +129,7 @@ public abstract class AbstractSPFlowTest extends AbstractFlowTest {
     }
 
     protected void setDefaultAuth() {
-        setBasicAuth("sp.example.org", "foo");
+        setBasicAuth("testsp.example.org", "foo");
     }
 
     protected void setRequest(final String method, final String body, final String contentType) {
diff --git a/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/TestSPEnvironmentApplicationContextInitializer.java b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/TestSPEnvironmentApplicationContextInitializer.java
new file mode 100644
index 0000000..133dab1
--- /dev/null
+++ b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/TestSPEnvironmentApplicationContextInitializer.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed 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.sp.flows;
+
+import javax.annotation.Nonnull;
+
+import org.slf4j.Logger;
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.mock.env.MockPropertySource;
+
+import net.shibboleth.shared.primitive.LoggerFactory;
+
+/**
+ * An {@link ApplicationContextInitializer} which prepends properties.
+ *
+ * <p>This needs to include the original IdP-test-layer properties and has to be
+ * set to {@link Ordered#LOWEST_PRECEDENCE} or things blow up.</p>
+ */
+ at Order(Ordered.LOWEST_PRECEDENCE)
+public class TestSPEnvironmentApplicationContextInitializer
+        implements ApplicationContextInitializer<ConfigurableApplicationContext> {
+
+    /** Class logger. */
+    @Nonnull private final Logger log = LoggerFactory.getLogger(TestSPEnvironmentApplicationContextInitializer.class);
+
+    /** {@inheritDoc} */
+    @Override public void initialize(@Nonnull final ConfigurableApplicationContext applicationContext) {
+        final MockPropertySource mock = new MockPropertySource();
+        mock.setProperty("idp.home", "classpath:/net/shibboleth/idp/module");
+        mock.setProperty("idp.webflows", "classpath*:/flows");
+        mock.setProperty("idp.service.metadata.resources", "testbed.MetadataResolverResources");
+        mock.setProperty("sp.service.agents.resources", "test.sp.AgentResolverResources");
+        applicationContext.getEnvironment().getPropertySources().addFirst(mock);
+        log.info("Prepending properties '{}'", mock.getSource());
+    }
+    
+}
\ No newline at end of file
diff --git a/sp-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/test-agents.xml b/sp-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/test-agents.xml
new file mode 100644
index 0000000..18ac6c1
--- /dev/null
+++ b/sp-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/test-agents.xml
@@ -0,0 +1,23 @@
+<?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="testsp.example.org" parent="shibboleth.Agent" p:sharedSecrets="foo">
+        <property name="applications">
+            <set>
+                <bean p:id="default" parent="shibboleth.Application" p:issuer="https://testsp.example.org"/>
+            </set>
+        </property>
+    </bean>
+
+</beans>
diff --git a/sp-conf-impl/src/test/resources/net/shibboleth/sp/test-beans.xml b/sp-conf-impl/src/test/resources/net/shibboleth/sp/test-beans.xml
new file mode 100644
index 0000000..552dc1d
--- /dev/null
+++ b/sp-conf-impl/src/test/resources/net/shibboleth/sp/test-beans.xml
@@ -0,0 +1,23 @@
+<?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:jdbc="http://www.springframework.org/schema/jdbc"
+       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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
+                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
+                           
+       default-init-method="initialize"
+       default-destroy-method="destroy">
+
+      
+    <util:list id="test.sp.AgentResolverResources">
+        <value>%{idp.home}/conf/sp/agents.xml</value>
+        <value>%{idp.home}/conf/sp/test-agents.xml</value>
+    </util:list>
+
+</beans>

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


More information about the commits mailing list