You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2018/10/29 14:56:16 UTC

httpcomponents-client git commit: HTTPCORE-561: added SSLSocket timeout test [Forced Update!]

Repository: httpcomponents-client
Updated Branches:
  refs/heads/4.5.x ddf65605d -> b8c0e1745 (forced update)


HTTPCORE-561: added SSLSocket timeout test


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/b8c0e174
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/b8c0e174
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/b8c0e174

Branch: refs/heads/4.5.x
Commit: b8c0e1745d3b5e7b092d690af11d60ca6ba5f04e
Parents: c54895c
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Oct 29 15:43:18 2018 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Oct 29 15:56:00 2018 +0100

----------------------------------------------------------------------
 .../http/conn/ssl/TestSSLSocketFactory.java     | 33 ++++++++++++++++++++
 1 file changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/b8c0e174/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
----------------------------------------------------------------------
diff --git a/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java b/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
index 0941356..c6ff47f 100644
--- a/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
+++ b/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
@@ -28,8 +28,10 @@
 package org.apache.http.conn.ssl;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.InetSocketAddress;
 import java.net.Socket;
+import java.net.SocketTimeoutException;
 import java.security.KeyManagementException;
 import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
@@ -53,6 +55,7 @@ import org.apache.http.localserver.SSLTestContexts;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.ssl.SSLContexts;
+import org.hamcrest.CoreMatchers;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Test;
@@ -341,4 +344,34 @@ public class TestSSLSocketFactory {
         final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
         socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
     }
+
+    @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 SSLConnectionSocketFactory(
+                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.getLocalPort(), "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();
+        }
+    }
 }