[java-plugin-shibd] branch main updated: Implement property support in agent resolver tests.
Scott Cantor
cantor.2 at osu.edu
Wed Aug 20 23:30:55 UTC 2025
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=62a9eeb5bbc321a27da060d3c26c4b821db8d4be
The following commit(s) were added to refs/heads/main by this push:
new 62a9eeb Implement property support in agent resolver tests.
62a9eeb is described below
commit 62a9eeb5bbc321a27da060d3c26c4b821db8d4be
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Aug 20 19:30:50 2025 -0400
Implement property support in agent resolver tests.
---
.../shibboleth/sp/service/AgentResolverTest.java | 71 +++++++++++++++++++++-
.../net/shibboleth/sp/service/utility.xml | 6 +-
.../src/main/java/net/shibboleth/sp/Agent.java | 5 +-
.../java/net/shibboleth/sp/impl/BasicAgent.java | 3 -
4 files changed, 76 insertions(+), 9 deletions(-)
diff --git a/sp-conf-impl/src/test/java/net/shibboleth/sp/service/AgentResolverTest.java b/sp-conf-impl/src/test/java/net/shibboleth/sp/service/AgentResolverTest.java
index e92c3df..44c3568 100644
--- a/sp-conf-impl/src/test/java/net/shibboleth/sp/service/AgentResolverTest.java
+++ b/sp-conf-impl/src/test/java/net/shibboleth/sp/service/AgentResolverTest.java
@@ -14,13 +14,18 @@
package net.shibboleth.sp.service;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Properties;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import net.shibboleth.idp.test.PreferFileSystemContextLoader;
import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.net.IPRange;
import net.shibboleth.shared.resolver.CriteriaSet;
import net.shibboleth.shared.resolver.ResolverException;
import net.shibboleth.shared.service.ServiceableComponent;
@@ -30,9 +35,18 @@ import net.shibboleth.sp.Agent;
import net.shibboleth.sp.AgentCriterion;
import net.shibboleth.sp.AgentResolver;
import net.shibboleth.sp.Application;
+import net.shibboleth.sp.impl.BasicApplication;
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
+import org.springframework.mock.env.MockPropertySource;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
+import org.springframework.test.context.web.WebAppConfiguration;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -40,7 +54,16 @@ import org.testng.annotations.Test;
/**
* Unit tests for {@link Agent} and {@link Application} resolution and inheritance of settings.
*/
-public class AgentResolverTest {
+ at ContextConfiguration(
+ locations = {
+ "/net/shibboleth/sp/service/utility.xml",
+ },
+ initializers = {
+ AgentResolverTest.TestContextInitializer.class,
+ },
+ loader = PreferFileSystemContextLoader.class)
+ at WebAppConfiguration
+public class AgentResolverTest extends AbstractTestNGSpringContextTests {
private ReloadableSpringService<AgentResolver> resolver;
@@ -64,8 +87,12 @@ public class AgentResolverTest {
Assert.assertNull(resolveAgent("localhost"));
- Agent agent = resolveAgent("testsp.example.org");
+ final Agent agent = resolveAgent("testsp.example.org");
assert agent != null;
+ validateDefaults(agent);
+ Assert.assertEquals(agent.getSharedSecrets(), CollectionSupport.singletonList("foo"));
+
+
Assert.assertEquals(agent.getId(), "testsp.example.org");
}
@@ -85,6 +112,23 @@ public class AgentResolverTest {
}
}
+ private void validateDefaults(@Nonnull final Agent agent) {
+ Assert.assertEquals(agent.getApplications().size(), 1);
+ Assert.assertEquals(agent.getAllowedAddressRanges(),
+ CollectionSupport.setOf(IPRange.parseCIDRBlock("127.0.0.1/32"), IPRange.parseCIDRBlock("::1/128")));
+
+ final Application app = agent.getApplication(Agent.DEFAULT_APPLICATION_ID);
+ assert app != null;
+ Assert.assertEquals(app.getApplicationId(), Agent.DEFAULT_APPLICATION_ID);
+ Assert.assertNull(app.getAuthenticatingAuthority(null));
+ Assert.assertTrue(app.getSessionInitiators(null).isEmpty());
+ Assert.assertTrue(app.getTokenConsumers(null).isEmpty());
+
+ if (app instanceof BasicApplication basic) {
+ Assert.assertEquals(basic.getIssuer(null), "https://sp.example.org");
+ }
+ }
+
/**
* Instantiate the agent resolver service.
*
@@ -99,7 +143,6 @@ public class AgentResolverTest {
final ArrayList<Resource> springs = new ArrayList<>(resources.length);
springs.add(new ClassPathResource("/net/shibboleth/sp/conf/agents-system.xml"));
- springs.add(new ClassPathResource("/net/shibboleth/sp/service/utility.xml"));
for (final String s : resources) {
assert s != null;
springs.add(new ClassPathResource(s));
@@ -107,6 +150,7 @@ public class AgentResolverTest {
final ReloadableSpringService<AgentResolver> service = new ReloadableSpringService<AgentResolver>(AgentResolver.class);
service.setId("test");
+ service.setParentContext(applicationContext);
service.setFailFast(true);
service.setServiceConfigurations(springs);
service.setBeanPostProcessors(CollectionSupport.singletonList(new IdentifiableBeanPostProcessor()));
@@ -115,4 +159,25 @@ public class AgentResolverTest {
return service;
}
+ /**
+ * Loads SP properties for testing.
+ */
+ @Order(Ordered.HIGHEST_PRECEDENCE)
+ public static class TestContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
+
+ /** {@inheritDoc} */
+ @Override public void initialize(@Nonnull final ConfigurableApplicationContext applicationContext) {
+ final ClassPathResource resource = new ClassPathResource("/net/shibboleth/idp/module/conf/sp/sp.properties");
+ final Properties props = new Properties();
+ try (final InputStream in = resource.getInputStream()) {
+ props.load(in);
+ } catch (IOException e) {
+ Assert.fail(e.getMessage());
+ }
+ final MockPropertySource mock = new MockPropertySource(props);
+ applicationContext.getEnvironment().getPropertySources().addFirst(mock);
+ }
+
+ }
+
}
\ No newline at end of file
diff --git a/sp-conf-impl/src/test/resources/net/shibboleth/sp/service/utility.xml b/sp-conf-impl/src/test/resources/net/shibboleth/sp/service/utility.xml
index a7a6dbd..f5312f2 100644
--- a/sp-conf-impl/src/test/resources/net/shibboleth/sp/service/utility.xml
+++ b/sp-conf-impl/src/test/resources/net/shibboleth/sp/service/utility.xml
@@ -14,6 +14,9 @@
<!-- Low-level helpers and mocks. -->
+ <bean id="shibboleth.IdentifiableBeanPostProcessor"
+ class="net.shibboleth.shared.spring.config.IdentifiableBeanPostProcessor" />
+
<bean id="shibboleth.CommaDelimStringArray"
class="org.springframework.util.StringUtils" factory-method="commaDelimitedListToStringArray" abstract="true" />
@@ -23,7 +26,6 @@
<bean id="shibboleth.AttributeRegistryService" class="net.shibboleth.shared.testing.MockReloadableService" />
<bean id="shibboleth.StorageService"
- class="%{idp.storage.StorageService:org.opensaml.storage.impl.MemoryStorageService}"
- p:cleanupInterval="0" />
+ class="org.opensaml.storage.impl.MemoryStorageService" />
</beans>
diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/Agent.java b/sp-server-api/src/main/java/net/shibboleth/sp/Agent.java
index 0e834ab..a510c56 100644
--- a/sp-server-api/src/main/java/net/shibboleth/sp/Agent.java
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/Agent.java
@@ -37,8 +37,11 @@ import net.shibboleth.shared.net.IPRange;
@ThreadSafe
public interface Agent extends IdentifiedComponent {
+ /** ID of default {@link Application}. */
+ @Nonnull @NotEmpty public static String DEFAULT_APPLICATION_ID = "default";
+
/** Method constant for "basic". */
- @Nonnull @NotEmpty static String AUTH_METHOD_BASIC = "basic";
+ @Nonnull @NotEmpty public static String AUTH_METHOD_BASIC = "basic";
/**
* Get the network addresses or ranges of addresses from which requests from this agent may
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/impl/BasicAgent.java b/sp-server-impl/src/main/java/net/shibboleth/sp/impl/BasicAgent.java
index efa9dae..0612719 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/impl/BasicAgent.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/impl/BasicAgent.java
@@ -43,9 +43,6 @@ import net.shibboleth.sp.Application;
*/
public class BasicAgent extends BasicApplication implements Agent {
- /** ID of default {@link Application}. */
- @Nonnull @NotEmpty public static String DEFAULT_APPLICATION_ID = "default";
-
/** Whether cached authentication is supported. */
private boolean supportsCachedAuthentication;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list