Skip to content

Commit 8b6fcee

Browse files
author
Stephane Landelle
committed
Add AsyncHttpClient#355 test on master: both Netty and Grizzly are OK
1 parent 683e24c commit 8b6fcee

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
import org.asynchttpclient.AsyncHttpClient;
2626
import org.asynchttpclient.AsyncHttpClientConfig.Builder;
2727
import org.asynchttpclient.Response;
28+
import org.testng.Assert;
2829
import org.testng.annotations.Test;
2930

31+
import javax.net.ssl.HostnameVerifier;
3032
import javax.net.ssl.SSLHandshakeException;
33+
import javax.net.ssl.SSLSession;
3134
import javax.servlet.http.HttpServletResponse;
3235

3336
import java.io.IOException;
@@ -125,4 +128,33 @@ public void reconnectsAfterFailedCertificationPath() throws Exception {
125128
c.close();
126129
}
127130
}
131+
132+
@Test(timeOut = 5000)
133+
public void failInstantlyIfHostNamesDiffer() throws Exception {
134+
AsyncHttpClient client = null;
135+
136+
try {
137+
final Builder builder = new Builder().setHostnameVerifier(new HostnameVerifier() {
138+
139+
public boolean verify(String arg0, SSLSession arg1) {
140+
return false;
141+
}
142+
}).setRequestTimeoutInMs(20000);
143+
144+
client = getAsyncHttpClient(builder.build());
145+
146+
try {
147+
client.prepareGet("https://github.com/AsyncHttpClient/async-http-client/issues/355").execute().get(TIMEOUT, TimeUnit.SECONDS);
148+
149+
Assert.assertTrue(false, "Shouldn't be here: should get an Exception");
150+
} catch (ExecutionException e) {
151+
Assert.assertTrue(e.getCause() instanceof ConnectException, "Cause should be a ConnectException");
152+
} catch (Exception e) {
153+
Assert.assertTrue(false, "Shouldn't be here: should get a ConnectException wrapping a ConnectException");
154+
}
155+
156+
} finally {
157+
client.close();
158+
}
159+
}
128160
}

0 commit comments

Comments
 (0)