Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitacc4ee0

Browse files
author
Stephane Landelle
committed
Merge pull requestAsyncHttpClient#714 from wsargent/fix-555
Check in a fix for hostname validation failure.
2 parentseace5fe +4ba9a9f commitacc4ee0

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

‎src/main/java/com/ning/http/client/providers/netty/NettyConnectListener.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public final void operationComplete(ChannelFuture f) throws Exception {
7777
// TODO: channel.getRemoteAddress()).getHostName() is very expensive. Should cache the result.
7878
if (!v.verify(InetSocketAddress.class.cast(channel.getRemoteAddress()).getHostName(),
7979
sslHandler.getEngine().getSession())) {
80-
thrownewConnectException("HostnameVerifier exception.");
80+
future.abort(newConnectException("HostnameVerifier exception."));
81+
return;
8182
}
8283
}
8384

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2014 AsyncHttpClient Project
3+
*
4+
* AsyncHttpClient Project licenses this file to you under the Apache License, version 2.0
5+
* (the "License"); you may not use this file except in compliance with the
6+
* License. You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*
16+
*/
17+
packagecom.ning.http.client.providers.netty;
18+
19+
importcom.ning.http.client.AsyncHttpClient;
20+
importcom.ning.http.client.AsyncHttpClientConfig;
21+
importcom.ning.http.client.Response;
22+
importorg.jboss.netty.logging.InternalLoggerFactory;
23+
importorg.jboss.netty.logging.Slf4JLoggerFactory;
24+
importorg.testng.annotations.Test;
25+
26+
importjavax.net.ssl.HostnameVerifier;
27+
importjavax.net.ssl.SSLSession;
28+
importjava.io.IOException;
29+
importjava.net.ConnectException;
30+
importjava.util.concurrent.ExecutionException;
31+
32+
importstaticorg.testng.Assert.*;
33+
34+
/**
35+
*
36+
*/
37+
publicclassNettyHostnameValidationFailureTest {
38+
39+
@Test(groups ="standalone")
40+
publicvoidtestHostnameValidationFailure() {
41+
//InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
42+
43+
AsyncHttpClientConfig.Builderbuilder =newAsyncHttpClientConfig.Builder()//
44+
.setAllowPoolingConnection(true)//
45+
.setHostnameVerifier(newHostnameVerifier() {
46+
publicbooleanverify(Stringarg0,SSLSessionarg1) {
47+
returnfalse;
48+
}
49+
})
50+
.setConnectionTimeoutInMs(60000);
51+
AsyncHttpClientclient =newAsyncHttpClient(builder.build());
52+
53+
try {
54+
client.prepareGet("https://www.google.fr").execute().get();
55+
fail("Should have thrown an exception");
56+
}catch (ExecutionExceptione) {
57+
assertTrue(e.getMessage().contains("HostnameVerifier exception."));
58+
}catch (Exceptione) {
59+
fail(e.getClass().getCanonicalName());
60+
}finally {
61+
client.close();
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp