Author: schultz
Date: Sun Jan  6 22:26:02 2019
New Revision: 1850600

URL: http://svn.apache.org/viewvc?rev=1850600&view=rev
Log:
Fix logic for skipping GCM tests.

Modified:
    
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java

Modified: 
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java?rev=1850600&r1=1850599&r2=1850600&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java
 (original)
+++ 
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java
 Sun Jan  6 22:26:02 2019
@@ -19,15 +19,21 @@ package org.apache.catalina.tribes.group
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.security.NoSuchAlgorithmException;
+import java.security.Security;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import javax.crypto.Cipher;
+
 import org.hamcrest.core.IsEqual;
 import org.hamcrest.core.IsNot;
 
 import org.junit.AfterClass;
 import org.junit.Assert;
+import org.junit.Assume;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.FixMethodOrder;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -62,6 +68,12 @@ public class TestEncryptInterceptor {
     EncryptInterceptor dest;
 
 
+    @BeforeClass
+    public static void setupClass() {
+        Security.setProperty("jdk.tls.disabledAlgorithms", "");
+        Security.setProperty("crypto.policy", "unlimited"); // For Java 9+
+    }
+
     @AfterClass
     public static void cleanup() {
         File f = new File(MESSAGE_FILE);
@@ -175,6 +187,9 @@ public class TestEncryptInterceptor {
 
     @Test
     public void test192BitKey() throws Exception {
+        Assume.assumeTrue("Skipping test192BitKey because the JVM does not 
support it",
+                192 <= Cipher.getMaxAllowedKeyLength("AES"));
+
         src.setEncryptionKey(encryptionKey192);
         dest.setEncryptionKey(encryptionKey192);
         src.start(Channel.SND_TX_SEQ);
@@ -189,6 +204,9 @@ public class TestEncryptInterceptor {
 
     @Test
     public void test256BitKey() throws Exception {
+        Assume.assumeTrue("Skipping test256BitKey because the JVM does not 
support it",
+                256 <= Cipher.getMaxAllowedKeyLength("AES"));
+
         src.setEncryptionKey(encryptionKey256);
         dest.setEncryptionKey(encryptionKey256);
         src.start(Channel.SND_TX_SEQ);
@@ -268,10 +286,18 @@ public class TestEncryptInterceptor {
 
     @Test
     public void testGCM() throws Exception {
-        src.setEncryptionAlgorithm("AES/GCM/PKCS5Padding");
-        src.start(Channel.SND_TX_SEQ);
-        dest.setEncryptionAlgorithm("AES/GCM/PKCS5Padding");
-        dest.start(Channel.SND_TX_SEQ);
+        try {
+            src.setEncryptionAlgorithm("AES/GCM/PKCS5Padding");
+            src.start(Channel.SND_TX_SEQ);
+            dest.setEncryptionAlgorithm("AES/GCM/PKCS5Padding");
+            dest.start(Channel.SND_TX_SEQ);
+        } catch (ChannelException ce) {
+            Assume.assumeFalse("Skipping testGCM due to lack of JVM support",
+                    ce.getCause() instanceof NoSuchAlgorithmException
+                    && ce.getCause().getMessage().contains("GCM"));
+
+            throw ce;
+        }
 
         String testInput = "The quick brown fox jumps over the lazy dog.";
 



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

Reply via email to