"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java" between
httpcomponents-client-4.5.6-src.tar.gz and httpcomponents-client-4.5.7-src.tar.gz

About: HttpComponents is an Apache project responsible for creating and maintaining a toolset of low level Java components focused on HTTP and associated protocols. Java sources.

TestSSLSocketFactory.java  (httpcomponents-client-4.5.6-src):TestSSLSocketFactory.java  (httpcomponents-client-4.5.7-src)
skipping to change at line 31 skipping to change at line 31
* This software consists of voluntary contributions made by many * This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more * individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
* *
*/ */
package org.apache.http.conn.ssl; package org.apache.http.conn.ssl;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketTimeoutException;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
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.SSLException;
skipping to change at line 56 skipping to change at line 58
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.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.apache.http.ssl.SSLContexts;
import org.hamcrest.CoreMatchers;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
/** /**
* Unit tests for {@link SSLConnectionSocketFactory}. * Unit tests for {@link SSLConnectionSocketFactory}.
*/ */
public class TestSSLSocketFactory { public class TestSSLSocketFactory {
private HttpServer server; private HttpServer server;
skipping to change at line 203 skipping to change at line 206
final HttpContext context = new BasicHttpContext(); final HttpContext context = new BasicHttpContext();
final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifi er(); final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifi er();
final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocket Factory( final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocket Factory(
SSLTestContexts.createClientSSLContext(), hostVerifier); SSLTestContexts.createClientSSLContext(), hostVerifier);
final Socket socket = socketFactory.createSocket(context); final Socket socket = socketFactory.createSocket(context);
final InetSocketAddress remoteAddress = new InetSocketAddress("localhost ", this.server.getLocalPort()); final InetSocketAddress remoteAddress = new InetSocketAddress("localhost ", this.server.getLocalPort());
final HttpHost target = new HttpHost("localhost", this.server.getLocalPo rt(), "https"); final HttpHost target = new HttpHost("localhost", this.server.getLocalPo rt(), "https");
final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, s ocket, target, remoteAddress, null, final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, s ocket, target, remoteAddress, null,
context); context);
try { try {
final SSLSession sslsession = sslSocket.getSession(); final InputStream inputStream = sslSocket.getInputStream();
Assert.assertEquals(-1, inputStream.read());
final SSLSession sslsession = sslSocket.getSession();
Assert.assertNotNull(sslsession); Assert.assertNotNull(sslsession);
Assert.assertTrue(hostVerifier.isFired()); Assert.assertTrue(hostVerifier.isFired());
} finally { } finally {
sslSocket.close(); sslSocket.close();
} }
} }
@Test(expected = SSLException.class) @Test(expected = SSLException.class)
public void testSSLTrustVerification() throws Exception { public void testSSLTrustVerification() throws Exception {
// @formatter:off // @formatter:off
skipping to change at line 344 skipping to change at line 349
this.server.start(); this.server.start();
final HttpContext context = new BasicHttpContext(); final HttpContext context = new BasicHttpContext();
final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocket Factory( final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocket Factory(
SSLTestContexts.createClientSSLContext()); SSLTestContexts.createClientSSLContext());
final Socket socket = socketFactory.createSocket(context); final Socket socket = socketFactory.createSocket(context);
final InetSocketAddress remoteAddress = new InetSocketAddress("localhost ", this.server.getLocalPort()); final InetSocketAddress remoteAddress = new InetSocketAddress("localhost ", this.server.getLocalPort());
final HttpHost target = new HttpHost("localhost", this.server.getLocalPo rt(), "https"); final HttpHost target = new HttpHost("localhost", this.server.getLocalPo rt(), "https");
socketFactory.connectSocket(0, socket, target, remoteAddress, null, cont ext); socketFactory.connectSocket(0, socket, target, remoteAddress, null, cont ext);
} }
@Test
public void testSSLTimeout() throws Exception {
// @formatter:off
this.server = ServerBootstrap.bootstrap()
.setServerInfo(LocalServerTestBase.ORIGIN)
.setSslContext(SSLTestContexts.createServerSSLContext())
.create();
// @formatter:on
this.server.start();
final HttpContext context = new BasicHttpContext();
final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocket
Factory(
SSLTestContexts.createClientSSLContext());
final Socket socket = socketFactory.createSocket(context);
final InetSocketAddress remoteAddress = new InetSocketAddress("localhost
", this.server.getLocalPort());
final HttpHost target = new HttpHost("localhost", this.server.getLocalPo
rt(), "https");
final Socket sslSocket = socketFactory.connectSocket(0, socket, target,
remoteAddress, null, context);
final InputStream inputStream = sslSocket.getInputStream();
try {
sslSocket.setSoTimeout(1);
inputStream.read();
Assert.fail("SocketTimeoutException expected");
} catch (final SocketTimeoutException ex){
Assert.assertThat(sslSocket.isClosed(), CoreMatchers.equalTo(false))
;
Assert.assertThat(socket.isClosed(), CoreMatchers.equalTo(false));
} finally {
inputStream.close();
}
}
} }
 End of changes. 6 change blocks. 
1 lines changed or deleted 41 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)