This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-starter.git


The following commit(s) were added to refs/heads/master by this push:
     new f476bd1  SLING-8015 - SmokeIT should use preemptive Basic Auth
f476bd1 is described below

commit f476bd1387faad2b09b314256552bf17eda434df
Author: Robert Munteanu <[email protected]>
AuthorDate: Mon Oct 15 16:55:38 2018 +0200

    SLING-8015 - SmokeIT should use preemptive Basic Auth
---
 .../java/org/apache/sling/launchpad/SmokeIT.java   | 28 +++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/test/java/org/apache/sling/launchpad/SmokeIT.java 
b/src/test/java/org/apache/sling/launchpad/SmokeIT.java
index ad4d9ee..71676dc 100644
--- a/src/test/java/org/apache/sling/launchpad/SmokeIT.java
+++ b/src/test/java/org/apache/sling/launchpad/SmokeIT.java
@@ -29,15 +29,20 @@ import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.felix.utils.json.JSONParser;
 import org.apache.http.Header;
+import org.apache.http.HttpHost;
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.impl.client.BasicAuthCache;
 import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.hamcrest.CoreMatchers;
+import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.w3c.dom.Document;
@@ -52,14 +57,29 @@ public class SmokeIT {
 
     @ClassRule
     public static LaunchpadReadyRule LAUNCHPAD = new 
LaunchpadReadyRule(LAUNCHPAD_PORT);
+    private HttpClientContext httpClientContext;
 
-    private CloseableHttpClient newClient() {
+    @Before
+    public void prepareHttpContext() {
 
         CredentialsProvider credsProvider = new BasicCredentialsProvider();
         UsernamePasswordCredentials creds = new 
UsernamePasswordCredentials("admin", "admin");
         credsProvider.setCredentials(new AuthScope("localhost", 
LAUNCHPAD_PORT), creds);
 
-        return 
HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
+        BasicAuthCache authCache = new BasicAuthCache();
+        BasicScheme basicAuth = new BasicScheme();
+        authCache.put(new HttpHost("localhost", LAUNCHPAD_PORT, "http"), 
basicAuth);
+
+        httpClientContext = HttpClientContext.create();
+        httpClientContext.setCredentialsProvider(credsProvider);
+        httpClientContext.setAuthCache(authCache);
+    }
+
+    private CloseableHttpClient newClient() {
+
+        return HttpClientBuilder.create()
+                
.setDefaultCredentialsProvider(httpClientContext.getCredentialsProvider())
+                .build();
     }
 
     @Test
@@ -69,7 +89,9 @@ public class SmokeIT {
 
             HttpGet get = new HttpGet("http://localhost:"; + LAUNCHPAD_PORT + 
"/system/console/bundles.json");
 
-            try ( CloseableHttpResponse response = client.execute(get) ) {
+            // pass the context to ensure preemptive basic auth is used
+            // 
https://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html
+            try ( CloseableHttpResponse response = client.execute(get, 
httpClientContext) ) {
 
                 if ( response.getStatusLine().getStatusCode() != 200 ) {
                     fail("Unexpected status line " + response.getStatusLine());

Reply via email to