From c78bc0585c82269759eef1a0f28c9d5fa9b43317 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 25 Apr 2018 11:45:12 +0100 Subject: [PATCH] Make tests' detection of SSL handshake failures more robust Closes gh-12961 --- ...towEmbeddedServletContainerFactoryTests.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java index cebe2497ab..7b026ade9b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.boot.context.embedded.undertow; import java.io.File; import java.io.IOException; +import java.net.SocketException; import java.net.URISyntaxException; import java.nio.charset.Charset; import java.util.Arrays; @@ -51,6 +52,8 @@ import org.springframework.http.HttpStatus; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.anyOf; +import static org.hamcrest.CoreMatchers.instanceOf; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; @@ -222,14 +225,18 @@ public class UndertowEmbeddedServletContainerFactoryTests }); } - @Test(expected = SSLHandshakeException.class) + @Test public void sslRestrictedProtocolsEmptyCipherFailure() throws Exception { + this.thrown.expect(anyOf(instanceOf(SSLHandshakeException.class), + instanceOf(SocketException.class))); testRestrictedSSLProtocolsAndCipherSuites(new String[] { "TLSv1.2" }, new String[] { "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" }); } - @Test(expected = SSLHandshakeException.class) + @Test public void sslRestrictedProtocolsECDHETLS1Failure() throws Exception { + this.thrown.expect(anyOf(instanceOf(SSLHandshakeException.class), + instanceOf(SocketException.class))); testRestrictedSSLProtocolsAndCipherSuites(new String[] { "TLSv1" }, new String[] { "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" }); } @@ -246,8 +253,10 @@ public class UndertowEmbeddedServletContainerFactoryTests new String[] { "TLS_RSA_WITH_AES_128_CBC_SHA256" }); } - @Test(expected = SSLHandshakeException.class) + @Test public void sslRestrictedProtocolsRSATLS11Failure() throws Exception { + this.thrown.expect(anyOf(instanceOf(SSLHandshakeException.class), + instanceOf(SocketException.class))); testRestrictedSSLProtocolsAndCipherSuites(new String[] { "TLSv1.1" }, new String[] { "TLS_RSA_WITH_AES_128_CBC_SHA256" }); }