diff options
| author | Robert Godfrey <rgodfrey@apache.org> | 2014-08-20 08:53:47 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org> | 2014-08-20 08:53:47 +0000 |
| commit | d52c2ef8fdc4a7e2b9d38eefe31887d5b9dc8354 (patch) | |
| tree | 5adf2f5c72e833f748da59d8813c28fb0f5a6351 /qpid/java | |
| parent | 269580b80a3242f7fb6e7dbfff9859e43bbad8fd (diff) | |
| download | qpid-python-d52c2ef8fdc4a7e2b9d38eefe31887d5b9dc8354.tar.gz | |
QPID-6017 : Attempt to skip tests that require strong encryption when strong encryption is not available in the Java environment
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1619052 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
2 files changed, 39 insertions, 5 deletions
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterFactoryTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterFactoryTest.java index 0d71f66cc2..ac853a1242 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterFactoryTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterFactoryTest.java @@ -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 AESKeyFileEncrypterFactoryTest extends QpidTestCase public void testCreateKeyInDefaultLocation() throws Exception { + Assume.assumeTrue(isStrongEncryptionEnabled()); + ConfigurationSecretEncrypter encrypter = _factory.createEncrypter(_broker); KeyFilePathChecker keyFilePathChecker = new KeyFilePathChecker(); @@ -114,6 +120,8 @@ public class AESKeyFileEncrypterFactoryTest extends QpidTestCase 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 AESKeyFileEncrypterFactoryTest extends QpidTestCase 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 AESKeyFileEncrypterFactoryTest extends QpidTestCase 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 AESKeyFileEncrypterFactoryTest extends QpidTestCase 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 AESKeyFileEncrypterFactoryTest extends QpidTestCase super.tearDown(); } + private boolean isStrongEncryptionEnabled() throws NoSuchAlgorithmException + { + return Cipher.getMaxAllowedKeyLength("AES")>=256; + } + private class KeyFilePathChecker extends SimpleFileVisitor<Path> { diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterTest.java index b08c32a4f2..252ae23e78 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypterTest.java @@ -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 extends QpidTestCase 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 extends QpidTestCase public void testCreationFailsOnInvalidSecret() throws Exception { + Assume.assumeTrue(isStrongEncryptionEnabled()); try { new AESKeyFileEncrypter(null); @@ -90,8 +97,9 @@ public class AESKeyFileEncrypterTest extends QpidTestCase } } - public void testEncryptionOfEmptyString() + public void testEncryptionOfEmptyString() throws Exception { + Assume.assumeTrue(isStrongEncryptionEnabled()); String text = ""; doTestSimpleEncryptDecrypt(text); } @@ -109,8 +117,9 @@ public class AESKeyFileEncrypterTest extends QpidTestCase 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 extends QpidTestCase } } - 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 extends QpidTestCase 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); |
