alopresto commented on a change in pull request #3844: NIFI-1474 Added 
validation for p in scrypt
URL: https://github.com/apache/nifi/pull/3844#discussion_r339188893
 
 

 ##########
 File path: 
nifi-commons/nifi-security-utils/src/test/groovy/org/apache/nifi/security/util/crypto/ScryptCipherProviderGroovyTest.groovy
 ##########
 @@ -513,6 +513,81 @@ class ScryptCipherProviderGroovyTest {
         assert params[2] == EXPECTED_P
     }
 
+    @Test
+    void testShouldVerifyPBoundary() throws Exception {
+        // Arrange
+        final int r = 8;
+        final int p = 1;
+
+        // Act
+        boolean valid = ScryptCipherProvider.isPValid(r, p)
+
+        // Assert
+        assert valid
+    }
+
+    @Test
+    void testShouldFailPBoundary() throws Exception {
+        // Arrange
+        // The p upper bound is calculated with the formula below:
+        // pBoundary = ((Math.pow(2,32))-1) * (32.0/(r * 128)), where 
pBoundary = 134217727.96875;
+        Map costParameters = [8:134217729, 128:8388608, 4096: 0]
+
+        // Act
+        def results = costParameters.collectEntries { r, p ->
+            def isValid = ScryptCipherProvider.isPValid(r, p)
+            [r, isValid]
+        }
+
+        // results => [8: false, 128: false, 4096: false]
+
+        // Assert
+        results.each { r, isPValid ->
+            logger.info("For r ${r}, p is ${isPValid}")
+            assert !isPValid
+        }
+
+
+
+    }
+//    *****************************************************************
 
 Review comment:
   Remove this comment block. 

----------------------------------------------------------------
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