[java-plugin-shibd] branch main updated: Framework for testing AgentResolver configurations.
Scott Cantor
cantor.2 at osu.edu
Wed Aug 20 12:22:42 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=e460cf4e2e7f682361e6036e3acb395cb69b7972
The following commit(s) were added to refs/heads/main by this push:
new e460cf4 Framework for testing AgentResolver configurations.
e460cf4 is described below
commit e460cf4e2e7f682361e6036e3acb395cb69b7972
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Aug 20 08:22:40 2025 -0400
Framework for testing AgentResolver configurations.
---
.../shibboleth/sp/service/AgentResolverTest.java | 118 +++++++++++++++++++++
.../net/shibboleth/sp/service/utility.xml | 29 +++++
.../java/net/shibboleth/sp/AgentCriterion.java | 6 +-
3 files changed, 150 insertions(+), 3 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
new file mode 100644
index 0000000..e92c3df
--- /dev/null
+++ b/sp-conf-impl/src/test/java/net/shibboleth/sp/service/AgentResolverTest.java
@@ -0,0 +1,118 @@
+/*
+ * 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.service;
+
+import java.util.ArrayList;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import net.shibboleth.shared.collection.CollectionSupport;
+import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.resolver.CriteriaSet;
+import net.shibboleth.shared.resolver.ResolverException;
+import net.shibboleth.shared.service.ServiceableComponent;
+import net.shibboleth.shared.spring.config.IdentifiableBeanPostProcessor;
+import net.shibboleth.shared.spring.service.ReloadableSpringService;
+import net.shibboleth.sp.Agent;
+import net.shibboleth.sp.AgentCriterion;
+import net.shibboleth.sp.AgentResolver;
+import net.shibboleth.sp.Application;
+
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Unit tests for {@link Agent} and {@link Application} resolution and inheritance of settings.
+ */
+public class AgentResolverTest {
+
+ private ReloadableSpringService<AgentResolver> resolver;
+
+ /**
+ * Shutdown.
+ */
+ @AfterMethod
+ public void tearDown() {
+ resolver.destroy();
+ }
+
+ /**
+ * Test the default unit test configuration as a basic check.
+ *
+ * @throws ComponentInitializationException
+ * @throws ResolverException
+ */
+ @Test public void testBasic() throws ComponentInitializationException, ResolverException {
+
+ resolver = getResolver("/net/shibboleth/idp/module/conf/sp/agents.xml");
+
+ Assert.assertNull(resolveAgent("localhost"));
+
+ Agent agent = resolveAgent("testsp.example.org");
+ assert agent != null;
+
+ Assert.assertEquals(agent.getId(), "testsp.example.org");
+ }
+
+ /**
+ * Attempt to resolve an agent.
+ *
+ * @param agentId the agent to resolve
+ *
+ * @return the resolution result
+ *
+ * @throws ResolverException
+ */
+ @Nullable private Agent resolveAgent(@Nonnull final String agentId) throws ResolverException {
+ try (final ServiceableComponent<AgentResolver> component = resolver.getServiceableComponent()) {
+ return component.getComponent().resolveSingle(new CriteriaSet(new AgentCriterion(agentId)));
+ }
+ }
+
+ /**
+ * Instantiate the agent resolver service.
+ *
+ * @param resources Spring files to load into service
+ *
+ * @return the service
+ *
+ * @throws ComponentInitializationException
+ */
+ @Nonnull private ReloadableSpringService<AgentResolver> getResolver(@Nonnull final String...resources)
+ throws ComponentInitializationException {
+
+ 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));
+ }
+
+ final ReloadableSpringService<AgentResolver> service = new ReloadableSpringService<AgentResolver>(AgentResolver.class);
+ service.setId("test");
+ service.setFailFast(true);
+ service.setServiceConfigurations(springs);
+ service.setBeanPostProcessors(CollectionSupport.singletonList(new IdentifiableBeanPostProcessor()));
+ service.initialize();
+
+ return service;
+ }
+
+}
\ 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
new file mode 100644
index 0000000..a7a6dbd
--- /dev/null
+++ b/sp-conf-impl/src/test/resources/net/shibboleth/sp/service/utility.xml
@@ -0,0 +1,29 @@
+<?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">
+
+ <!-- Low-level helpers and mocks. -->
+
+ <bean id="shibboleth.CommaDelimStringArray"
+ class="org.springframework.util.StringUtils" factory-method="commaDelimitedListToStringArray" abstract="true" />
+
+ <bean id="shibboleth.MetadataResolverService" class="net.shibboleth.shared.testing.MockReloadableService" />
+ <bean id="shibboleth.AttributeResolverService" class="net.shibboleth.shared.testing.MockReloadableService" />
+ <bean id="shibboleth.AttributeFilterService" class="net.shibboleth.shared.testing.MockReloadableService" />
+ <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" />
+
+</beans>
diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/AgentCriterion.java b/sp-server-api/src/main/java/net/shibboleth/sp/AgentCriterion.java
index 554fec8..56e70f0 100644
--- a/sp-server-api/src/main/java/net/shibboleth/sp/AgentCriterion.java
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/AgentCriterion.java
@@ -32,16 +32,16 @@ public class AgentCriterion implements Criterion {
/**
* Constructor.
*
- * @param id application ID
+ * @param id agent ID
*/
public AgentCriterion(@Nonnull @NotEmpty final String id) {
agentId = Constraint.isNotNull(StringSupport.trimOrNull(id), "Agent ID cannot be null or empty");
}
/**
- * Get the application ID specified.
+ * Get the agent ID specified.
*
- * @return application ID
+ * @return agent ID
*/
@Nonnull @NotEmpty public String getId() {
return agentId;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list