mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-18 16:07:11 +00:00
Fixed disabled test case and removed broken one in TestSSLSocketFactory
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1631243 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8a7586336d
commit
f6fed403fa
@ -32,25 +32,27 @@
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.SSLException;
|
||||||
import javax.net.ssl.SSLHandshakeException;
|
import javax.net.ssl.SSLHandshakeException;
|
||||||
|
import javax.net.ssl.SSLServerSocket;
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
|
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.http.HttpHost;
|
||||||
import org.apache.http.impl.bootstrap.HttpServer;
|
import org.apache.http.impl.bootstrap.HttpServer;
|
||||||
|
import org.apache.http.impl.bootstrap.SSLServerSetupHandler;
|
||||||
import org.apache.http.impl.bootstrap.ServerBootstrap;
|
import org.apache.http.impl.bootstrap.ServerBootstrap;
|
||||||
import org.apache.http.localserver.LocalServerTestBase;
|
import org.apache.http.localserver.LocalServerTestBase;
|
||||||
import org.apache.http.localserver.SSLTestContexts;
|
import org.apache.http.localserver.SSLTestContexts;
|
||||||
import org.apache.http.protocol.BasicHttpContext;
|
import org.apache.http.protocol.BasicHttpContext;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
|
import org.apache.http.ssl.SSLContexts;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -159,54 +161,19 @@ public void testClientAuthSSL() throws Exception {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("There is no way to force client auth with HttpServer in 4.4a1")
|
|
||||||
@Test(expected=IOException.class)
|
@Test(expected=IOException.class)
|
||||||
public void testClientAuthSSLFailure() throws Exception {
|
public void testClientAuthSSLFailure() throws Exception {
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setServerInfo(LocalServerTestBase.ORIGIN)
|
.setServerInfo(LocalServerTestBase.ORIGIN)
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
.create();
|
.setSslSetupHandler(new SSLServerSetupHandler() {
|
||||||
this.server.start();
|
|
||||||
|
|
||||||
final HttpContext context = new BasicHttpContext();
|
@Override
|
||||||
final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
|
public void initialize(final SSLServerSocket socket) throws SSLException {
|
||||||
final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
|
socket.setNeedClientAuth(true);
|
||||||
SSLTestContexts.createClientSSLContext(), hostVerifier);
|
}
|
||||||
final Socket socket = socketFactory.createSocket(context);
|
|
||||||
final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
|
|
||||||
final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
|
|
||||||
final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
|
|
||||||
try {
|
|
||||||
final SSLSession sslsession = sslSocket.getSession();
|
|
||||||
|
|
||||||
Assert.assertNotNull(sslsession);
|
})
|
||||||
Assert.assertTrue(hostVerifier.isFired());
|
|
||||||
} finally {
|
|
||||||
sslSocket.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testClientAuthSSLAliasChoice() throws Exception {
|
|
||||||
// TODO unused - is there a bug in the test?
|
|
||||||
final PrivateKeyStrategy aliasStrategy = new PrivateKeyStrategy() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String chooseAlias(
|
|
||||||
final Map<String, PrivateKeyDetails> aliases, final Socket socket) {
|
|
||||||
Assert.assertEquals(2, aliases.size());
|
|
||||||
Assert.assertTrue(aliases.containsKey("hc-test-key-1"));
|
|
||||||
Assert.assertTrue(aliases.containsKey("hc-test-key-2"));
|
|
||||||
return "hc-test-key-2";
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.server = ServerBootstrap.bootstrap()
|
|
||||||
.setServerInfo(LocalServerTestBase.ORIGIN)
|
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
|
||||||
.create();
|
.create();
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user