1717
1818package org .apache .tomcat .util .net ;
1919
20+ import java .net .SocketException ;
2021import java .util .ArrayList ;
2122import java .util .Collection ;
2223import java .util .List ;
2526import javax .net .ssl .SSLContext ;
2627import javax .net .ssl .SSLHandshakeException ;
2728
29+ import org .junit .Assert ;
2830import org .junit .Test ;
2931import org .junit .runners .Parameterized ;
3032import 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