summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core_utils/src/test')
-rw-r--r--eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java
index 62de99c0..7f3982be 100644
--- a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java
+++ b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java
@@ -1,5 +1,7 @@
package at.gv.egiz.eaaf.core.test.http;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
@@ -179,6 +181,7 @@ public class HttpClientFactoryTest {
public void getCustomClientBasicAuth() throws EaafException, ClientProtocolException,
IOException, InterruptedException {
final HttpClientConfiguration config = new HttpClientConfiguration("jUnit");
+ config.setEnablePreEmptiveHttpBasicAuth(false);
config.setAuthMode("password");
config.setUsername("jUnit");
config.setPassword("password");
@@ -206,10 +209,40 @@ public class HttpClientFactoryTest {
final RecordedRequest httpReq2 = mockWebServer.takeRequest();
Assert.assertNull("wrong BasicAuthHeader", httpReq1.getHeader("Authorization"));
Assert.assertNotNull("missing BasicAuthHeader", httpReq2.getHeader("Authorization"));
+ assertEquals("Basic alVuaXQ6cGFzc3dvcmQ=", httpReq2.getHeader("Authorization"), "wrong authHeader");
}
@Test
+ public void getCustomClientBasicAuthWithPreEmptive() throws EaafException, ClientProtocolException,
+ IOException, InterruptedException {
+ final HttpClientConfiguration config = new HttpClientConfiguration("jUnit");
+ config.setAuthMode("password");
+ config.setUsername("jUnit");
+ config.setPassword("password");
+
+ final CloseableHttpClient client = httpClientFactory.getHttpClient(config);
+ Assert.assertNotNull("httpClient", client);
+
+ //setup test webserver that requestes http Basic authentication
+ mockWebServer = new MockWebServer();
+ mockServerUrl = mockWebServer.url("/sp/junit");
+ mockWebServer.enqueue(new MockResponse().setResponseCode(200)
+ .setBody("Successful auth!"));
+
+ //request webservice
+ final HttpUriRequest httpGet2 = new HttpGet(mockServerUrl.url().toString());
+ final CloseableHttpResponse httpResp2 = client.execute(httpGet2);
+ Assert.assertEquals("http statusCode", 200, httpResp2.getStatusLine().getStatusCode());
+
+ //check request contains basic authentication after authentication was requested
+ final RecordedRequest httpReq1 = mockWebServer.takeRequest();
+ Assert.assertNotNull("missing BasicAuthHeader", httpReq1.getHeader("Authorization"));
+ assertEquals("Basic alVuaXQ6cGFzc3dvcmQ=", httpReq1.getHeader("Authorization"), "wrong authHeader");
+
+ }
+
+ @Test
public void getCustomClientBasicAuthNoUsername() {
final HttpClientConfiguration config = new HttpClientConfiguration("jUnit");
config.setAuthMode("password");