[java-idp-plugin-duo] branch dev/JDUO-82 updated: Add shibboleth.InternalHttpClient bean to tests
Phil Smart
philip.smart at jisc.ac.uk
Mon Jan 8 11:06:44 UTC 2024
This is an automated email from the git hooks/post-receive script.
philsmart pushed a commit to branch dev/JDUO-82
in repository java-idp-plugin-duo.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-duo.git;a=commit;h=118dea587e35a68868de28f15140aeef3db06a2f
The following commit(s) were added to refs/heads/dev/JDUO-82 by this push:
new 118dea58 Add shibboleth.InternalHttpClient bean to tests
118dea58 is described below
commit 118dea587e35a68868de28f15140aeef3db06a2f
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Mon Jan 8 11:06:42 2024 +0000
Add shibboleth.InternalHttpClient bean to tests
- It is not used by any of the integration tests at present, but could
be if we include a SWF for the passwordless flow.
---
.../impl/AbstractAuthnXmlFlowExecutionTests.java | 59 +++++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)
diff --git a/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/duo/impl/AbstractAuthnXmlFlowExecutionTests.java b/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/duo/impl/AbstractAuthnXmlFlowExecutionTests.java
index d43d3172..8398e4c3 100644
--- a/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/duo/impl/AbstractAuthnXmlFlowExecutionTests.java
+++ b/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/duo/impl/AbstractAuthnXmlFlowExecutionTests.java
@@ -25,7 +25,15 @@ import java.util.function.Consumer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import javax.net.ssl.SSLContext;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
+import org.apache.hc.client5.http.io.HttpClientConnectionManager;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
+import org.apache.hc.client5.http.ssl.TrustAllStrategy;
+import org.apache.hc.core5.ssl.SSLContexts;
import org.mockito.Mockito;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
@@ -72,6 +80,7 @@ import net.shibboleth.idp.ui.context.RelyingPartyUIContext;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.collection.CollectionSupport;
+import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.logic.FunctionSupport;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.security.impl.SecureRandomIdentifierGenerationStrategy;
@@ -465,10 +474,58 @@ public abstract class AbstractAuthnXmlFlowExecutionTests extends CustomAbstractX
addBeanDefinition(builderContext, "shibboleth.ChildLookup.AuthenticationContext",BeanDefinitionBuilder.
genericBeanDefinition(org.opensaml.messaging.context.navigate.ChildContextLookup.class)
- .addConstructorArgValue(net.shibboleth.idp.authn.context.AuthenticationContext.class).getBeanDefinition());
+ .addConstructorArgValue(net.shibboleth.idp.authn.context.AuthenticationContext.class)
+ .getBeanDefinition());
+
+ try {
+ // Create a HttpClient which turns off hostname verification and trusts all certificates (for TESTS!)
+ // Would be use either by non-browser or admin API lookups
+ final SSLContext sslcontext = SSLContexts.custom()
+ .loadTrustMaterial(null, new TrustAllStrategy())
+ .build();
+ final SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create()
+ .setSslContext(sslcontext)
+ .build();
+ final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
+ .setSSLSocketFactory(sslSocketFactory)
+ .build();
+ addBeanSingleton(builderContext, "shibboleth.InternalHttpClient",
+ Constraint.isNotNull(HttpClients.custom()
+ .setConnectionManager(cm)
+ .evictExpiredConnections()
+ .build(),"HttpClient can not be null"));
+
+ } catch (final Exception e) {
+ log.error("Could not mock HTTP response",e);
+ }
}
+ /**
+ * Adds a singleton bean to the {@link StaticApplicationContext} contained in the builder context.
+ *
+ * @param builderContext to add the bean to.
+ * @param beanName the name of the bean.
+ * @param bean the bean.
+ */
+ protected void addBeanSingleton(@Nonnull final MockFlowBuilderContext builderContext,
+ @Nonnull final String beanName, @Nonnull final Object bean) {
+
+ assertNotNull(builderContext);
+ assertNotNull(beanName);
+ assertNotNull(bean);
+ assertTrue( builderContext.getApplicationContext() instanceof ConfigurableApplicationContext);
+
+ final BeanFactory factory = ((ConfigurableApplicationContext) builderContext.
+ getApplicationContext()).getBeanFactory();
+
+ assertNotNull(factory);
+ assertTrue(factory instanceof DefaultListableBeanFactory);
+
+ ((DefaultListableBeanFactory)factory).registerSingleton(beanName, bean);
+
+ }
+
/**
* Adds the bean to the {@link StaticApplicationContext} contained in the builder context.
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list