You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2014/08/20 10:53:48 UTC

svn commit: r1619052 - in /qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption: AESKeyFileEncrypterFactoryTest.java AESKeyFileEncrypterTest.java

Author: rgodfrey
Date: Wed Aug 20 08:53:47 2014
New Revision: 1619052

URL: http://svn.apache.org/r1619052
Log:
QPID-6017 : Attempt to skip tests that require strong encryption when strong encryption is not available in the Java environment

Modified:
    qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterFactoryTest.java
    qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterTest.java

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterFactoryTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterFactoryTest.java?rev=1619052&r1=1619051&r2=1619052&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterFactoryTest.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterFactoryTest.java Wed Aug 20 08:53:47 2014
@@ -36,11 +36,15 @@ import java.nio.file.Paths;
 import java.nio.file.SimpleFileVisitor;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.nio.file.attribute.PosixFilePermission;
+import java.security.NoSuchAlgorithmException;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.Map;
 import java.util.UUID;
 
+import javax.crypto.Cipher;
+
+import org.junit.Assume;
 import org.mockito.ArgumentCaptor;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
@@ -84,6 +88,8 @@ public class AESKeyFileEncrypterFactoryT
 
     public void testCreateKeyInDefaultLocation() throws Exception
     {
+        Assume.assumeTrue(isStrongEncryptionEnabled());
+
         ConfigurationSecretEncrypter encrypter = _factory.createEncrypter(_broker);
 
         KeyFilePathChecker keyFilePathChecker = new KeyFilePathChecker();
@@ -114,6 +120,8 @@ public class AESKeyFileEncrypterFactoryT
 
     public void testSettingContextKeyLeadsToFileCreation() throws Exception
     {
+        Assume.assumeTrue(isStrongEncryptionEnabled());
+
         String filename = UUID.randomUUID().toString() + ".key";
         String subdirName = getTestName() + File.separator + "test";
         String fileLocation = _tmpDir.toString() + File.separator + subdirName + File.separator + filename;
@@ -132,6 +140,8 @@ public class AESKeyFileEncrypterFactoryT
 
     public void testUnableToCreateFileInSpecifiedLocation() throws Exception
     {
+        Assume.assumeTrue(isStrongEncryptionEnabled());
+
         String filename = UUID.randomUUID().toString() + ".key";
         String subdirName = getTestName() + File.separator + "test";
         String fileLocation = _tmpDir.toString() + File.separator + subdirName + File.separator + filename;
@@ -155,6 +165,8 @@ public class AESKeyFileEncrypterFactoryT
 
     public void testPermissionsAreChecked() throws Exception
     {
+        Assume.assumeTrue(isStrongEncryptionEnabled());
+
         String filename = UUID.randomUUID().toString() + ".key";
         String subdirName = getTestName() + File.separator + "test";
         String fileLocation = _tmpDir.toString() + File.separator + subdirName + File.separator + filename;
@@ -181,6 +193,8 @@ public class AESKeyFileEncrypterFactoryT
 
     public void testInvalidKey() throws Exception
     {
+        Assume.assumeTrue(isStrongEncryptionEnabled());
+
         String filename = UUID.randomUUID().toString() + ".key";
         String subdirName = getTestName() + File.separator + "test";
         String fileLocation = _tmpDir.toString() + File.separator + subdirName + File.separator + filename;
@@ -233,6 +247,11 @@ public class AESKeyFileEncrypterFactoryT
         super.tearDown();
     }
 
+    private boolean isStrongEncryptionEnabled() throws NoSuchAlgorithmException
+    {
+        return Cipher.getMaxAllowedKeyLength("AES")>=256;
+    }
+
     private class KeyFilePathChecker extends SimpleFileVisitor<Path>
     {
 

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterTest.java?rev=1619052&r1=1619051&r2=1619052&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterTest.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterTest.java Wed Aug 20 08:53:47 2014
@@ -21,15 +21,19 @@
 package org.apache.qpid.server.security.encryption;
 
 import java.nio.charset.StandardCharsets;
+import java.security.NoSuchAlgorithmException;
 import java.security.SecureRandom;
 import java.util.HashSet;
 import java.util.Random;
 import java.util.Set;
 
+import javax.crypto.Cipher;
 import javax.crypto.SecretKeyFactory;
 import javax.crypto.spec.PBEKeySpec;
 import javax.crypto.spec.SecretKeySpec;
 
+import org.junit.Assume;
+
 import org.apache.qpid.test.utils.QpidTestCase;
 
 public class AESKeyFileEncrypterTest extends QpidTestCase
@@ -39,12 +43,14 @@ public class AESKeyFileEncrypterTest ext
 
     public void testSimpleEncryptDecrypt() throws Exception
     {
+        Assume.assumeTrue(isStrongEncryptionEnabled());
         doTestSimpleEncryptDecrypt(PLAINTEXT);
     }
 
 
-    public void testRepeatedEncryptionsReturnDifferentValues()
+    public void testRepeatedEncryptionsReturnDifferentValues() throws Exception
     {
+        Assume.assumeTrue(isStrongEncryptionEnabled());
         SecretKeySpec secretKey = createSecretKey();
         AESKeyFileEncrypter encrypter = new AESKeyFileEncrypter(secretKey);
 
@@ -67,6 +73,7 @@ public class AESKeyFileEncrypterTest ext
 
     public void testCreationFailsOnInvalidSecret() throws Exception
     {
+        Assume.assumeTrue(isStrongEncryptionEnabled());
         try
         {
             new AESKeyFileEncrypter(null);
@@ -90,8 +97,9 @@ public class AESKeyFileEncrypterTest ext
         }
     }
 
-    public void testEncryptionOfEmptyString()
+    public void testEncryptionOfEmptyString() throws Exception
     {
+        Assume.assumeTrue(isStrongEncryptionEnabled());
         String text = "";
         doTestSimpleEncryptDecrypt(text);
     }
@@ -109,8 +117,9 @@ public class AESKeyFileEncrypterTest ext
         assertTrue("Encryption was not reversible", text.equals(decrypted));
     }
 
-    public void testEncryptingNullFails()
+    public void testEncryptingNullFails() throws Exception
     {
+        Assume.assumeTrue(isStrongEncryptionEnabled());
         try
         {
             SecretKeySpec secretKey = createSecretKey();
@@ -125,8 +134,9 @@ public class AESKeyFileEncrypterTest ext
         }
     }
 
-    public void testEncryptingVeryLargeSecret()
+    public void testEncryptingVeryLargeSecret() throws Exception
     {
+        Assume.assumeTrue(isStrongEncryptionEnabled());
         Random random = new Random();
         byte[] data = new byte[4096];
         random.nextBytes(data);
@@ -137,9 +147,14 @@ public class AESKeyFileEncrypterTest ext
         doTestSimpleEncryptDecrypt(new String(data, StandardCharsets.US_ASCII));
     }
 
-    public void testDecryptNonsense()
+    private boolean isStrongEncryptionEnabled() throws NoSuchAlgorithmException
     {
+        return Cipher.getMaxAllowedKeyLength("AES")>=256;
+    }
 
+    public void testDecryptNonsense() throws Exception
+    {
+        Assume.assumeTrue(isStrongEncryptionEnabled());
         SecretKeySpec secretKey = createSecretKey();
         AESKeyFileEncrypter encrypter = new AESKeyFileEncrypter(secretKey);
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org