You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2023/03/22 13:57:21 UTC
[camel] branch CAMEL-19184/use-http-context-with-httpcomponents-v5 created (now 6048147601e)
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a change to branch CAMEL-19184/use-http-context-with-httpcomponents-v5
in repository https://gitbox.apache.org/repos/asf/camel.git
at 6048147601e CAMEL-19184: camel-http - Add test to validate authentication with httpContext
This branch includes the following new commits:
new 6048147601e CAMEL-19184: camel-http - Add test to validate authentication with httpContext
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[camel] 01/01: CAMEL-19184: camel-http - Add test to validate authentication with httpContext
Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch CAMEL-19184/use-http-context-with-httpcomponents-v5
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6048147601eea7953a03eddf76e2e2f8d4c99d40
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Wed Mar 22 14:56:55 2023 +0100
CAMEL-19184: camel-http - Add test to validate authentication with httpContext
---
.../component/http/HttpsAuthenticationTest.java | 41 ++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpsAuthenticationTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpsAuthenticationTest.java
index 2ce323579d8..4dc5ba73df3 100644
--- a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpsAuthenticationTest.java
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpsAuthenticationTest.java
@@ -25,12 +25,20 @@ import org.apache.camel.component.http.handler.AuthenticationValidationHandler;
import org.apache.camel.component.http.interceptor.RequestBasicAuth;
import org.apache.camel.component.http.interceptor.ResponseBasicUnauthorized;
import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.hc.client5.http.auth.AuthScope;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
+import org.apache.hc.client5.http.impl.auth.BasicAuthCache;
+import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
+import org.apache.hc.client5.http.impl.auth.BasicScheme;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
+import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequestInterceptor;
import org.apache.hc.core5.http.HttpResponseInterceptor;
import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
+import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.http.protocol.ResponseContent;
import org.junit.jupiter.api.AfterEach;
@@ -50,6 +58,8 @@ public class HttpsAuthenticationTest extends BaseHttpsTest {
@BindToRegistry("sslContextParameters")
private SSLContextParameters sslContextParameters = new SSLContextParameters();
+ @BindToRegistry("basicAuthContext")
+ private HttpContext basicAuthContexts = basicAuthContext();
@BeforeEach
@Override
@@ -75,6 +85,26 @@ public class HttpsAuthenticationTest extends BaseHttpsTest {
}
}
+ HttpContext basicAuthContext() {
+
+ char[] chars = new char[7];
+ password.getChars(1, 7, chars, 0);
+
+ UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, password.toCharArray());
+ BasicCredentialsProvider provider = new BasicCredentialsProvider();
+ provider.setCredentials(new AuthScope(null, -1), credentials);
+
+ BasicAuthCache authCache = new BasicAuthCache();
+ BasicScheme basicAuth = new BasicScheme();
+ authCache.put(new HttpHost("localhost", 8083), basicAuth);
+
+ HttpClientContext context = HttpClientContext.create();
+ context.setAuthCache(authCache);
+ context.setCredentialsProvider(provider);
+
+ return context;
+ }
+
@Test
public void httpsGetWithAuthentication() throws Exception {
@@ -86,6 +116,17 @@ public class HttpsAuthenticationTest extends BaseHttpsTest {
assertExchange(exchange);
}
+ @Test
+ public void httpsGetWithHttpCache() throws Exception {
+
+ Exchange exchange = template.request("https://localhost:" + localServer.getLocalPort()
+ + "?throwExceptionOnFailure=false&httpContext=#basicAuthContext",
+ exchange1 -> {
+ });
+
+ assertExchange(exchange);
+ }
+
@Override
protected HttpProcessor getBasicHttpProcessor() {
List<HttpRequestInterceptor> requestInterceptors = new ArrayList<>();