geoffreyblake commented on a change in pull request #97:
URL: https://github.com/apache/commons-crypto/pull/97#discussion_r413105247



##########
File path: 
src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
##########
@@ -147,6 +153,75 @@ public void cryptoTest() throws Exception {
         }
     }
 
+    @Test
+    public void testNullTransform() throws Exception {
+        for (String transform : transformations) {
+            try {
+                final CryptoCipher cipher = getCipher(null);
+                Assert.fail("Expected RuntimeException via 
NullPointerException");
+            } catch (final RuntimeException e) {
+            }
+        }
+    }
+
+    @Test
+    public void testInvalidTransform() throws Exception {
+        for (String transform : transformations) {
+            try {
+                final CryptoCipher cipher = 
getCipher("AES/CBR/NoPadding/garbage/garbage");
+                Assert.fail("Expected RuntimeException via a 
InvocationTargetException");
+            } catch (final RuntimeException e) {
+            }
+        }
+    }
+
+    @Test
+    public void testInvalidKey() throws Exception {
+        for (String transform : transformations) {
+            try {
+                final CryptoCipher cipher = getCipher(transform);
+                Assert.assertNotNull(cipher);
+
+                final byte[] invalidKey = { 0x00, 0x01, 0x02, 0x03, 0x04, 
0x05, 0x06,
+                    0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x11 
};
+                cipher.init(OpenSsl.ENCRYPT_MODE, new 
SecretKeySpec(invalidKey, "AES"), new IvParameterSpec(IV));
+                Assert.fail("Expected InvalidKeyException");
+            } catch (final InvalidKeyException ike) {
+            }
+        }
+    }
+
+    //@Test(expected = InvalidAlgorithmParameterException.class, timeout = 
120000)
+    @Test
+    public void testInvalidIV() throws Exception {
+        for (String transform : transformations) {
+            try {
+                final CryptoCipher cipher = getCipher(transform);
+                Assert.assertNotNull(cipher);
+
+                final byte[] invalidIV = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 
0x06,
+                        0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
0x11 };
+                cipher.init(OpenSsl.ENCRYPT_MODE, new SecretKeySpec(KEY, 
"AES"), new IvParameterSpec(invalidIV));
+                Assert.fail("Expected InvalidAlgorithmParameterException");
+            } catch (final InvalidAlgorithmParameterException iape) {
+            }
+        }
+    }
+
+    @Test
+    public void testInvalidIVClass() throws Exception {
+        for (String transform : transformations) {
+            try {
+            final CryptoCipher cipher = getCipher(transform);

Review comment:
       Fixed all the odd formatting, redundant code concerns.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to