Skip to content

Commit 6ab7dc9

Browse files
committed
SocketException been observed as well as SSLHandshakeException
1 parent 25bb2bb commit 6ab7dc9

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

test/org/apache/tomcat/util/net/TestSslHandshakeFailure.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.tomcat.util.net;
1919

20+
import java.net.SocketException;
2021
import java.util.ArrayList;
2122
import java.util.Collection;
2223
import java.util.List;
@@ -25,6 +26,7 @@
2526
import javax.net.ssl.SSLContext;
2627
import javax.net.ssl.SSLHandshakeException;
2728

29+
import org.junit.Assert;
2830
import org.junit.Test;
2931
import org.junit.runners.Parameterized;
3032
import org.junit.runners.Parameterized.Parameter;
@@ -57,7 +59,7 @@ public static Collection<Object[]> parameters() {
5759
@Parameter(2)
5860
public String sslImplementationName;
5961

60-
@Test(expected = SSLHandshakeException.class)
62+
@Test
6163
public void testMissingClientCertificate() throws Exception {
6264
Tomcat tomcat = getTomcatInstance();
6365

@@ -76,8 +78,24 @@ public void testMissingClientCertificate() throws Exception {
7678
sc.init(null, TesterSupport.getTrustManagers(), null);
7779
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
7880

79-
getUrl("https://localhost:" + getPort() + "/");
80-
81+
Throwable actual = null;
82+
try {
83+
getUrl("https://localhost:" + getPort() + "/");
84+
} catch (Throwable t) {
85+
actual = t;
86+
}
87+
88+
/*
89+
* SSLHandshakeException expected but SocketException has been observed
90+
*/
91+
Assert.assertNotNull("No exception was thrown when SSLHandshakeException was expected", actual);
92+
93+
if (actual instanceof SSLHandshakeException || actual instanceof SocketException) {
94+
// Tests passes = NO-OP
95+
} else {
96+
actual.printStackTrace();
97+
Assert.fail("Unexpected exception [" + actual.getClass() + ": " + actual.getMessage() + "].");
98+
}
8199
}
82100

83101
}

0 commit comments

Comments
 (0)