|
25 | 25 | import org.asynchttpclient.AsyncHttpClient;
|
26 | 26 | import org.asynchttpclient.AsyncHttpClientConfig.Builder;
|
27 | 27 | import org.asynchttpclient.Response;
|
| 28 | +import org.testng.Assert; |
28 | 29 | import org.testng.annotations.Test;
|
29 | 30 |
|
| 31 | +import javax.net.ssl.HostnameVerifier; |
30 | 32 | import javax.net.ssl.SSLHandshakeException;
|
| 33 | +import javax.net.ssl.SSLSession; |
31 | 34 | import javax.servlet.http.HttpServletResponse;
|
32 | 35 |
|
33 | 36 | import java.io.IOException;
|
@@ -125,4 +128,33 @@ public void reconnectsAfterFailedCertificationPath() throws Exception {
|
125 | 128 | c.close();
|
126 | 129 | }
|
127 | 130 | }
|
| 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 | + } |
128 | 160 | }
|
0 commit comments