From 8d6b279bf2dc1948bbcb292afdba4c0f421ee255 Mon Sep 17 00:00:00 2001 From: jaymode Date: Tue, 31 May 2016 10:29:13 -0400 Subject: [PATCH] test: catch socketexception which may also be thrown We need to catch SocketException as this can be thrown during the handshake we expect to fail if the server closes the socket during the handshake. Closes elastic/elasticsearch#2378 Original commit: elastic/x-pack-elasticsearch@45c4b93ab6147f74d189c2f93fbcb9dd14a8c4a2 --- .../org/elasticsearch/shield/ssl/SSLReloadIntegTests.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ssl/SSLReloadIntegTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ssl/SSLReloadIntegTests.java index d76060efefa..cfacfa0ba72 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ssl/SSLReloadIntegTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ssl/SSLReloadIntegTests.java @@ -32,6 +32,7 @@ import javax.net.ssl.SSLSocketFactory; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.SocketException; import java.nio.file.AtomicMoveNotSupportedException; import java.nio.file.Files; import java.nio.file.Path; @@ -45,6 +46,7 @@ import java.util.Map.Entry; import java.util.concurrent.CountDownLatch; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; /** * Integration tests for SSL reloading support @@ -113,9 +115,10 @@ public class SSLReloadIntegTests extends ShieldIntegTestCase { InetSocketTransportAddress address = (InetSocketTransportAddress) internalCluster() .getInstance(Transport.class, node).boundAddress().publishAddress(); try (SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(address.getAddress(), address.getPort())) { + assertThat(socket.isConnected(), is(true)); socket.startHandshake(); fail("handshake should not have been successful!"); - } catch (SSLHandshakeException expected) { + } catch (SSLHandshakeException | SocketException expected) { } KeyStore nodeStore = KeyStore.getInstance("jks");