nifi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcgil...@apache.org
Subject nifi git commit: NIFI-3796 Added test logic to only run POSIX permission set on *nix OS. Separated missing and unreadable key providers to different tests and run unreadable on POSIX-compliant OS only. This closes #1751
Date Thu, 04 May 2017 16:14:48 GMT
Repository: nifi
Updated Branches:
  refs/heads/master 4f40eca16 -> 7f2f38be5


NIFI-3796
Added test logic to only run POSIX permission set on *nix OS.
Separated missing and unreadable key providers to different tests and run unreadable on POSIX-compliant
OS only.
This closes #1751


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/7f2f38be
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/7f2f38be
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/7f2f38be

Branch: refs/heads/master
Commit: 7f2f38be5237a2f8064ca58b52f9587b4f0920a3
Parents: 4f40eca
Author: Andy LoPresto <alopresto@apache.org>
Authored: Thu May 4 10:30:38 2017 -0400
Committer: Matt Gilman <matt.c.gilman@gmail.com>
Committed: Thu May 4 12:13:06 2017 -0400

----------------------------------------------------------------------
 .../nifi/provenance/CryptoUtilsTest.groovy      | 51 ++++++++++++++++----
 1 file changed, 41 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/7f2f38be/nifi-commons/nifi-data-provenance-utils/src/test/groovy/org/apache/nifi/provenance/CryptoUtilsTest.groovy
----------------------------------------------------------------------
diff --git a/nifi-commons/nifi-data-provenance-utils/src/test/groovy/org/apache/nifi/provenance/CryptoUtilsTest.groovy
b/nifi-commons/nifi-data-provenance-utils/src/test/groovy/org/apache/nifi/provenance/CryptoUtilsTest.groovy
index 162896f..f4992b6 100644
--- a/nifi-commons/nifi-data-provenance-utils/src/test/groovy/org/apache/nifi/provenance/CryptoUtilsTest.groovy
+++ b/nifi-commons/nifi-data-provenance-utils/src/test/groovy/org/apache/nifi/provenance/CryptoUtilsTest.groovy
@@ -16,10 +16,12 @@
  */
 package org.apache.nifi.provenance
 
+import org.apache.commons.lang3.SystemUtils
 import org.bouncycastle.jce.provider.BouncyCastleProvider
 import org.bouncycastle.util.encoders.Hex
 import org.junit.After
 import org.junit.AfterClass
+import org.junit.Assume
 import org.junit.Before
 import org.junit.BeforeClass
 import org.junit.ClassRule
@@ -175,32 +177,60 @@ class CryptoUtilsTest {
     }
 
     @Test
-    void testShouldNotValidateUnreadableOrMissingFileBasedKeyProvider() {
+    void testShouldNotValidateMissingFileBasedKeyProvider() {
         // Arrange
         String fileBasedProvider = FileBasedKeyProvider.class.name
+        File fileBasedProviderFile = new File(tempFolder.root, "filebased_missing.kp")
+        String providerLocation = fileBasedProviderFile.path
+        logger.info("Created (no actual file) temporary file based key provider: ${providerLocation}")
+
+        // Act
+        String missingLocation = providerLocation
+        boolean missingKeyProviderIsValid = CryptoUtils.isValidKeyProvider(fileBasedProvider,
missingLocation, KEY_ID, null)
+        logger.info("Key Provider ${fileBasedProvider} with location ${missingLocation} and
keyId ${KEY_ID} / ${null} is ${missingKeyProviderIsValid ? "valid" : "invalid"}")
+
+        // Assert
+        assert !missingKeyProviderIsValid
+    }
+
+    @Test
+    void testShouldNotValidateUnreadableFileBasedKeyProvider() {
+        // Arrange
+        Assume.assumeFalse("This test does not run on Windows", SystemUtils.IS_OS_WINDOWS)
+
+        String fileBasedProvider = FileBasedKeyProvider.class.name
         File fileBasedProviderFile = tempFolder.newFile("filebased.kp")
         String providerLocation = fileBasedProviderFile.path
         logger.info("Created temporary file based key provider: ${providerLocation}")
 
         // Make it unreadable
-        fileBasedProviderFile.setReadable(false, false)
-        Files.setPosixFilePermissions(fileBasedProviderFile.toPath(), [] as Set<PosixFilePermission>)
+        markFileUnreadable(fileBasedProviderFile)
 
         // Act
         boolean unreadableKeyProviderIsValid = CryptoUtils.isValidKeyProvider(fileBasedProvider,
providerLocation, KEY_ID, null)
         logger.info("Key Provider ${fileBasedProvider} with location ${providerLocation}
and keyId ${KEY_ID} / ${null} is ${unreadableKeyProviderIsValid ? "valid" : "invalid"}")
 
-        String missingLocation = providerLocation + "_missing"
-        boolean missingKeyProviderIsValid = CryptoUtils.isValidKeyProvider(fileBasedProvider,
missingLocation, KEY_ID, null)
-        logger.info("Key Provider ${fileBasedProvider} with location ${missingLocation} and
keyId ${KEY_ID} / ${null} is ${missingKeyProviderIsValid ? "valid" : "invalid"}")
-
         // Assert
         assert !unreadableKeyProviderIsValid
-        assert !missingKeyProviderIsValid
 
         // Make the file deletable so cleanup can occur
-        fileBasedProviderFile.setReadable(true, false)
-        Files.setPosixFilePermissions(fileBasedProviderFile.toPath(), ALL_POSIX_ATTRS)
+        markFileReadable(fileBasedProviderFile)
+    }
+
+    private static void markFileReadable(File fileBasedProviderFile) {
+        if (SystemUtils.IS_OS_WINDOWS) {
+            fileBasedProviderFile.setReadable(true, false)
+        } else {
+            Files.setPosixFilePermissions(fileBasedProviderFile.toPath(), ALL_POSIX_ATTRS)
+        }
+    }
+
+    private static void markFileUnreadable(File fileBasedProviderFile) {
+        if (SystemUtils.IS_OS_WINDOWS) {
+            fileBasedProviderFile.setReadable(false, false)
+        } else {
+            Files.setPosixFilePermissions(fileBasedProviderFile.toPath(), [] as Set<PosixFilePermission>)
+        }
     }
 
     @Test
@@ -433,4 +463,5 @@ class CryptoUtilsTest {
 
         Base64.encoder.encodeToString(CryptoUtils.concatByteArrays(ivBytes, cipherBytes))
     }
+
 }


Mime
View raw message