natural commented on a change in pull request #3672: NIFI-6363 Additional 
Sensitive Property Providers
URL: https://github.com/apache/nifi/pull/3672#discussion_r319311223
 
 

 ##########
 File path: 
nifi-commons/nifi-security-utils/src/test/java/org/apache/nifi/security/util/CipherUtilsTest.java
 ##########
 @@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.security.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.crypto.Cipher;
+import javax.crypto.NoSuchPaddingException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+
+
+public class CipherUtilsTest {
+
+    // This test shows we get an IV of the correct length when we ask for one.
+    @Test
+    public void showIvLengthIsCorrect() {
+        byte[] iv = CipherUtils.generateIV();
+        Assert.assertNotNull(iv);
+        Assert.assertEquals(CipherUtils.IV_LENGTH, iv.length);
+    }
+
+    // This test shows we get new IVs each time we ask for one.
+    @Test
+    public void showIvsAreDifferentEachTime() {
+        // Create a bunch of IVs
+        int count = 4;
+        byte [][] ivs = new byte[count][];
+        for (int i = 0; i < count; i++) {
+            ivs[i] = CipherUtils.generateIV();
+        }
+
+        // Compare each IV to every other IV
+        for (int i = 0; i < count; i++) {
+            byte[] iv = ivs[i];
+
+            for (int j = 0; j < count; j++) {
 
 Review comment:
   Great example, note added.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to