Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 477F9200C70 for ; Thu, 4 May 2017 18:14:50 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4620B160BB0; Thu, 4 May 2017 16:14:50 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8CD57160B9F for ; Thu, 4 May 2017 18:14:49 +0200 (CEST) Received: (qmail 52689 invoked by uid 500); 4 May 2017 16:14:48 -0000 Mailing-List: contact commits-help@nifi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nifi.apache.org Delivered-To: mailing list commits@nifi.apache.org Received: (qmail 52680 invoked by uid 99); 4 May 2017 16:14:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 May 2017 16:14:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A6987DFBC7; Thu, 4 May 2017 16:14:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mcgilman@apache.org To: commits@nifi.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer 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, 4 May 2017 16:14:48 +0000 (UTC) archived-at: Thu, 04 May 2017 16:14:50 -0000 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 Authored: Thu May 4 10:30:38 2017 -0400 Committer: Matt Gilman 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) + 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) + } } @Test @@ -433,4 +463,5 @@ class CryptoUtilsTest { Base64.encoder.encodeToString(CryptoUtils.concatByteArrays(ivBytes, cipherBytes)) } + }