[java-identity-provider] branch main updated: IDP-1676 Extensive failFast/propagateResolution tests
Rod Widdowson
rdw at steadingsoftware.com
Tue Feb 16 13:14:03 UTC 2021
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=cf614c6561055eb5b2cd4a82faba3c8602eec4f4
The following commit(s) were added to refs/heads/main by this push:
new cf614c656 IDP-1676 Extensive failFast/propagateResolution tests
cf614c656 is described below
commit cf614c6561055eb5b2cd4a82faba3c8602eec4f4
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Feb 15 16:33:42 2021 +0000
IDP-1676 Extensive failFast/propagateResolution tests
https://issues.shibboleth.net/jira/browse/IDP-1676
---
.../resolver/spring/AttributeResolverTest.java | 23 +--
.../idp/attribute/resolver/spring/IdP1676Test.java | 222 +++++++++++++++++++++
.../resolver/spring/idp-1676-resolver.xml | 40 ++++
.../attribute/resolver/spring/idp-1676-service.xml | 49 +++++
4 files changed, 312 insertions(+), 22 deletions(-)
diff --git a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java
index f3fba33c8..c76c76521 100644
--- a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java
+++ b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java
@@ -20,7 +20,6 @@ package net.shibboleth.idp.attribute.resolver.spring;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
import java.util.Arrays;
import java.util.HashSet;
@@ -43,8 +42,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.context.support.ConversionServiceFactoryBean;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.io.ClassPathResource;
-import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -166,26 +165,6 @@ public class AttributeResolverTest extends OpenSAMLInitBaseTestCase {
helper(true);
}
- @Test public void serviceLDAPRecover() throws ComponentInitializationException, ServiceException, ResolutionException, LDAPException {
- teardownDataConnectors();
- boolean dataConnectorOff = true;
- try {
- try {
- helper(false);
- fail("Expected to throw an exception");
- } catch (final ResolutionException e) {
- log.debug("The expected exception");
- }
- setupDataConnectors();
- dataConnectorOff = false;
- helper(true);
- } finally {
- if (dataConnectorOff) {
- setupDataConnectors();
- }
- }
- }
-
/**
* Not actually a test, just a convenience method for encrypting a value to put into the test data.
* @throws DataSealerException from {@link DataSealer#wrap(String)}
diff --git a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/IdP1676Test.java b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/IdP1676Test.java
new file mode 100644
index 000000000..02bf2b425
--- /dev/null
+++ b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/IdP1676Test.java
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.idp.attribute.resolver.spring;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.fail;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+
+import org.opensaml.core.testing.OpenSAMLInitBaseTestCase;
+import org.springframework.context.support.ConversionServiceFactoryBean;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.env.MutablePropertySources;
+import org.springframework.core.env.StandardEnvironment;
+import org.springframework.mock.env.MockPropertySource;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+import com.unboundid.ldap.listener.InMemoryDirectoryServer;
+import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
+import com.unboundid.ldap.listener.InMemoryListenerConfig;
+import com.unboundid.ldap.sdk.LDAPException;
+
+import net.shibboleth.ext.spring.config.IdentifiableBeanPostProcessor;
+import net.shibboleth.ext.spring.config.StringToDurationConverter;
+import net.shibboleth.ext.spring.util.SchemaTypeAwareXMLBeanDefinitionReader;
+import net.shibboleth.idp.attribute.resolver.AttributeResolver;
+import net.shibboleth.idp.attribute.resolver.ResolutionException;
+import net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext;
+import net.shibboleth.idp.saml.impl.testing.TestSources;
+import net.shibboleth.utilities.java.support.collection.Pair;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.service.ReloadableService;
+import net.shibboleth.utilities.java.support.service.ServiceableComponent;
+
+ at SuppressWarnings("javadoc")
+public class IdP1676Test extends OpenSAMLInitBaseTestCase {
+
+ /* LDAP */
+ private InMemoryDirectoryServer directoryServer;
+
+ private static final String LDAP_INIT_FILE =
+ "src/test/resources/net/shibboleth/idp/attribute/resolver/spring/ldapDataConnectorTest.ldif";
+
+ private GenericApplicationContext pendingTeardownContext = null;
+
+ @AfterMethod public void tearDownTestContext() {
+ if (null == pendingTeardownContext ) {
+ return;
+ }
+ pendingTeardownContext.close();
+ pendingTeardownContext = null;
+ }
+
+ @AfterClass public void teardown() {
+ connectorOff();
+ }
+
+ protected void setTestContext(final GenericApplicationContext context) {
+ tearDownTestContext();
+ pendingTeardownContext = context;
+ }
+
+ protected synchronized void connectorOn() throws LDAPException {
+ if (directoryServer == null) {
+ // LDAP
+ final InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=shibboleth,dc=net");
+ config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", 10391));
+ config.addAdditionalBindCredentials("cn=Directory Manager", "password");
+ directoryServer = new InMemoryDirectoryServer(config);
+ directoryServer.importFromLDIF(true, LDAP_INIT_FILE);
+ directoryServer.startListening();
+ }
+ }
+
+ /**
+ * Shutdown the in-memory directory server.
+ */
+ public synchronized void connectorOff() {
+ if (directoryServer != null) {
+ directoryServer.shutDown(true);
+ }
+ directoryServer = null;
+ }
+
+ private ReloadableService<AttributeResolver> getResolver(final boolean failFast, final boolean propagateResolutionExceptions) throws ComponentInitializationException {
+ final GenericApplicationContext context = new GenericApplicationContext();
+ context.getBeanFactory().addBeanPostProcessor(new IdentifiableBeanPostProcessor());
+
+ final Pair<String, String> pRE = new Pair<>("propagateResolutionExceptions", propagateResolutionExceptions ? "true": "false");
+ final Pair<String, String> fF = new Pair<>("failfast", failFast ? "true": "false");
+ final List<Pair<String, String>> properties = List.of(pRE,fF);
+
+ final MutablePropertySources propertySources = context.getEnvironment().getPropertySources();
+ final MockPropertySource mockEnvVars = new MockPropertySource();
+ for (final Pair<String, String> p :properties) {
+ mockEnvVars.setProperty(p.getFirst(), p.getSecond());
+ }
+ propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockEnvVars);
+
+ setTestContext(context);
+ context.setDisplayName("ApplicationContext: " + IdP1676Test.class);
+
+ final ConversionServiceFactoryBean service = new ConversionServiceFactoryBean();
+ context.setDisplayName("ApplicationContext: ");
+ service.setConverters(new HashSet<>(Arrays.asList(new StringToDurationConverter())));
+ service.afterPropertiesSet();
+
+ context.getBeanFactory().setConversionService(service.getObject());
+
+ final SchemaTypeAwareXMLBeanDefinitionReader beanDefinitionReader =
+ new SchemaTypeAwareXMLBeanDefinitionReader(context);
+
+ beanDefinitionReader.loadBeanDefinitions("net/shibboleth/idp/attribute/resolver/spring/idp-1676-service.xml");
+ context.refresh();
+
+ final ReloadableService<AttributeResolver> result = context.getBean(ReloadableService.class);
+ result.initialize();
+ return result;
+ }
+
+ private void testResolve(ReloadableService<AttributeResolver> resolverService, int attributeCount) throws ResolutionException {
+ final AttributeResolutionContext resolutionContext =
+ TestSources.createResolutionContext("PETER_THE_PRINCIPAL", "issuer", "recipient");
+ ServiceableComponent<AttributeResolver> serviceableComponent = null;
+ try {
+ serviceableComponent = resolverService.getServiceableComponent();
+ serviceableComponent.getComponent().resolveAttributes(resolutionContext);
+ } finally {
+ if (null != serviceableComponent) {
+ serviceableComponent.unpinComponent();
+ }
+ }
+ assertEquals(resolutionContext.getResolvedIdPAttributes().size(), attributeCount);
+
+ }
+
+
+ @Test public void failFast() throws LDAPException, ComponentInitializationException, ResolutionException {
+ connectorOff();
+ ReloadableService<AttributeResolver> resolverService = getResolver(true, true);
+ assertNull(resolverService.getServiceableComponent());
+ connectorOn();
+ assertNull(resolverService.getServiceableComponent());
+ resolverService = getResolver(true, true);
+ testResolve(resolverService, 7);
+ connectorOff();
+ try {
+ testResolve(resolverService, 2);
+ fail("Expected an Exception");
+ } catch (final ResolutionException ex) {
+ //expected that
+ }
+ }
+
+ @Test public void failFastNoPE() throws LDAPException, ComponentInitializationException, ResolutionException {
+ connectorOff();
+ ReloadableService<AttributeResolver> resolverService = getResolver(true, false);
+ assertNull(resolverService.getServiceableComponent());
+ connectorOn();
+ assertNull(resolverService.getServiceableComponent());
+ resolverService = getResolver(true, false);
+ testResolve(resolverService, 7);
+ connectorOff();
+ testResolve(resolverService, 2);
+ connectorOff();
+ }
+
+ @Test public void normal() throws LDAPException, ComponentInitializationException, ResolutionException {
+ connectorOn();
+ ReloadableService<AttributeResolver> resolverService = getResolver(false, true);
+ testResolve(resolverService, 7);
+ connectorOff();
+ try {
+ testResolve(resolverService, 2);
+ fail("Expected an Exception");
+ } catch (final ResolutionException ex) {
+ //expected that
+ }
+ resolverService = getResolver(false, true);
+ try {
+ testResolve(resolverService, 2);
+ fail("Expected an Exception");
+ } catch (final ResolutionException ex) {
+ //expected that
+ }
+ connectorOn();
+ testResolve(resolverService, 7);
+ }
+
+ @Test public void normalNoPE() throws LDAPException, ComponentInitializationException, ResolutionException {
+ connectorOn();
+ ReloadableService<AttributeResolver> resolverService = getResolver(false, false);
+ testResolve(resolverService, 7);
+ connectorOff();
+ testResolve(resolverService, 2);
+ resolverService = getResolver(false, false);
+ testResolve(resolverService, 2);
+ connectorOn();
+ testResolve(resolverService, 7);
+ }
+
+}
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/idp-1676-resolver.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/idp-1676-resolver.xml
new file mode 100644
index 000000000..7b21deb61
--- /dev/null
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/idp-1676-resolver.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<AttributeResolver xmlns="urn:mace:shibboleth:2.0:resolver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd">
+
+
+ <!-- ========================================== -->
+ <!-- Data Connectors -->
+ <!-- ========================================== -->
+
+ <DataConnector id="static" xsi:type="Static" exportAttributes="one two">
+ <Attribute id="one">
+ <Value>Hello World</Value>
+ </Attribute>
+ <Attribute id="two">
+ <Value>Hello World</Value>
+ </Attribute>
+ </DataConnector>
+
+
+ <!-- Example LDAP Connector -->
+ <DataConnector id="myLDAP" xsi:type="LDAPDirectory"
+ exportAttributes="uid mail sn cn homephone"
+ ldapURL="ldap://localhost:10391"
+ baseDN="dc=shibboleth,dc=net"
+ failFastInitialize="%{failfast:false}"
+ propagateResolutionExceptions="%{propagateResolutionExceptions:true}"
+ connectTimeout="PT6S"
+ responseTimeout="PT6S"
+ principal="cn=Directory Manager"
+ principalCredential="password">
+ <FilterTemplate>
+ <![CDATA[
+ (uid=$resolutionContext.principal)
+ ]]>
+ </FilterTemplate>
+ </DataConnector>
+
+
+</AttributeResolver>
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/idp-1676-service.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/idp-1676-service.xml
new file mode 100644
index 000000000..1ae358fec
--- /dev/null
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/idp-1676-service.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:c="http://www.springframework.org/schema/c"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
+ default-init-method="initialize"
+ default-destroy-method="destroy">
+
+ <!-- This BeanPostProcessor auto-sets identifiable beans with the bean name (if not already set). -->
+ <bean id="shibboleth.IdentifiableBeanPostProcessor"
+ class="net.shibboleth.ext.spring.config.IdentifiableBeanPostProcessor" />
+
+
+ <bean id="shibboleth.VelocityEngine" class="net.shibboleth.ext.spring.velocity.VelocityEngineFactoryBean">
+ <property name="velocityProperties">
+ <props>
+ <prop key="resource.loaders">classpath, string</prop>
+ <prop key="resource.loader.classpath.class">
+ org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
+ </prop>
+ <prop key="resource.loader.string.class">
+ org.apache.velocity.runtime.resource.loader.StringResourceLoader
+ </prop>
+ </props>
+ </property>
+ </bean>
+ <bean id="shibboleth.AttributeResolverService" class="net.shibboleth.ext.spring.service.ReloadableSpringService"
+ depends-on="shibboleth.VelocityEngine"
+ p:beanPostProcessors-ref="shibboleth.IdentifiableBeanPostProcessor"
+ p:failFast="false" p:reloadCheckDelay="0">
+
+ <constructor-arg name="claz"
+ value="net.shibboleth.idp.attribute.resolver.AttributeResolver" />
+ <constructor-arg name="strategy">
+ <bean
+ class="net.shibboleth.idp.attribute.resolver.spring.impl.AttributeResolverServiceStrategy"
+ p:id="Shibboleth.Resolver" />
+ </constructor-arg>
+ <property name="serviceConfigurations">
+ <util:list>
+ <value>net/shibboleth/idp/attribute/resolver/spring/externalBeans.xml</value>
+ <value>net/shibboleth/idp/attribute/resolver/spring/storageService.xml</value>
+ <value>net/shibboleth/idp/attribute/resolver/spring/idp-1676-resolver.xml</value>
+ </util:list>
+ </property>
+ </bean>
+</beans>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list