Author: rjung
Date: Sun Aug 13 12:38:22 2017
New Revision: 1804908

URL: http://svn.apache.org/viewvc?rev=1804908&view=rev
Log:
Add another custom trust manager test case
based on a trust manager, that sequentially
checks all CA certificates in a truststore
using the new TesterSupport.SequentialTrustManager.

Modified:
    tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java

Modified: tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java?rev=1804908&r1=1804907&r2=1804908&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/net/TestCustomSsl.java Sun Aug 13 
12:38:22 2017
@@ -45,6 +45,12 @@ import org.apache.tomcat.websocket.serve
  */
 public class TestCustomSsl extends TomcatBaseTest {
 
+    private static enum TrustType {
+        ALL,
+        CA,
+        NONE
+    }
+
     @Test
     public void testCustomSslImplementation() throws Exception {
 
@@ -86,16 +92,21 @@ public class TestCustomSsl extends Tomca
     }
 
     @Test
-    public void testCustomTrustManager1() throws Exception {
-        doTestCustomTrustManager(false);
+    public void testCustomTrustManagerAll() throws Exception {
+        doTestCustomTrustManager(TrustType.ALL);
+    }
+
+    @Test
+    public void testCustomTrustManagerCA() throws Exception {
+        doTestCustomTrustManager(TrustType.CA);
     }
 
     @Test
-    public void testCustomTrustManager2() throws Exception {
-        doTestCustomTrustManager(true);
+    public void testCustomTrustManagerNone() throws Exception {
+        doTestCustomTrustManager(TrustType.NONE);
     }
 
-    private void doTestCustomTrustManager(boolean serverTrustAll)
+    private void doTestCustomTrustManager(TrustType trustType)
             throws Exception {
 
         Tomcat tomcat = getTomcatInstance();
@@ -113,9 +124,12 @@ public class TestCustomSsl extends Tomca
             // Unexpected
             fail("Unexpected handler type");
         }
-        if (serverTrustAll) {
+        if (trustType.equals(TrustType.ALL)) {
             tomcat.getConnector().setAttribute("trustManagerClassName",
                     "org.apache.tomcat.util.net.TesterSupport$TrustAllCerts");
+        } else if (trustType.equals(TrustType.CA)) {
+            tomcat.getConnector().setAttribute("trustManagerClassName",
+                    
"org.apache.tomcat.util.net.TesterSupport$SequentialTrustManager");
         }
 
         // Start Tomcat
@@ -135,22 +149,22 @@ public class TestCustomSsl extends Tomca
             rc = getUrl("https://localhost:"; + getPort() + "/protected", res,
                 null, null);
         } catch (SocketException se) {
-            if (serverTrustAll) {
+            if (!trustType.equals(TrustType.NONE)) {
                 fail(se.getMessage());
                 se.printStackTrace();
             }
         } catch (SSLException he) {
-            if (serverTrustAll) {
+            if (!trustType.equals(TrustType.NONE)) {
                 fail(he.getMessage());
                 he.printStackTrace();
             }
         }
-        if (serverTrustAll) {
-            assertEquals(200, rc);
-            assertEquals("OK-" + TesterSupport.ROLE, res.toString());
-        } else {
+        if (trustType.equals(TrustType.NONE)) {
             assertTrue(rc != 200);
             assertEquals("", res.toString());
+        } else {
+            assertEquals(200, rc);
+            assertEquals("OK-" + TesterSupport.ROLE, res.toString());
         }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to