You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by al...@apache.org on 2020/10/07 18:00:16 UTC
[nifi] branch main updated: NIFI-7777 Removed support for
Expression Language from Password property Added unit test for no password
configured on Zip files
This is an automated email from the ASF dual-hosted git repository.
alopresto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new efb629e NIFI-7777 Removed support for Expression Language from Password property Added unit test for no password configured on Zip files
efb629e is described below
commit efb629e37d487ea72d3e08e1c479e98f7ffc8291
Author: exceptionfactory <ex...@gmail.com>
AuthorDate: Mon Oct 5 22:02:31 2020 -0400
NIFI-7777 Removed support for Expression Language from Password property
Added unit test for no password configured on Zip files
This closes #4572.
Signed-off-by: Andy LoPresto <al...@apache.org>
---
.../nifi/processors/standard/UnpackContent.java | 4 +-
.../processors/standard/TestUnpackContent.java | 50 +++++++++++++++-------
2 files changed, 36 insertions(+), 18 deletions(-)
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/UnpackContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/UnpackContent.java
index d6bf5a3..1fc4e9f 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/UnpackContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/UnpackContent.java
@@ -55,7 +55,6 @@ import org.apache.nifi.annotation.lifecycle.OnScheduled;
import org.apache.nifi.annotation.lifecycle.OnStopped;
import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.components.PropertyValue;
-import org.apache.nifi.expression.ExpressionLanguageScope;
import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.flowfile.attributes.FragmentAttributes;
@@ -158,7 +157,6 @@ public class UnpackContent extends AbstractProcessor {
.required(false)
.sensitive(true)
.addValidator(StandardValidators.NON_BLANK_VALIDATOR)
- .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
.build();
public static final Relationship REL_SUCCESS = new Relationship.Builder()
@@ -221,7 +219,7 @@ public class UnpackContent extends AbstractProcessor {
char[] password = null;
final PropertyValue passwordProperty = context.getProperty(PASSWORD);
if (passwordProperty.isSet()) {
- password = passwordProperty.evaluateAttributeExpressions().getValue().toCharArray();
+ password = passwordProperty.getValue().toCharArray();
}
zipUnpacker = new ZipUnpacker(fileFilter, password);
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java
index 73635bd..f14759f 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java
@@ -237,6 +237,22 @@ public class TestUnpackContent {
}
@Test
+ public void testZipEncryptionNoPasswordConfigured() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new UnpackContent());
+ runner.setProperty(UnpackContent.PACKAGING_FORMAT, UnpackContent.PackageFormat.ZIP_FORMAT.toString());
+
+ final String password = String.class.getSimpleName();
+ final char[] streamPassword = password.toCharArray();
+ final String contents = TestRunner.class.getCanonicalName();
+
+ final byte[] zipEncrypted = createZipEncrypted(EncryptionMethod.AES, streamPassword, contents);
+ runner.enqueue(zipEncrypted);
+ runner.run();
+
+ runner.assertTransferCount(UnpackContent.REL_FAILURE, 1);
+ }
+
+ @Test
public void testZipWithFilter() throws IOException {
final TestRunner unpackRunner = TestRunners.newTestRunner(new UnpackContent());
final TestRunner autoUnpackRunner = TestRunners.newTestRunner(new UnpackContent());
@@ -474,12 +490,28 @@ public class TestUnpackContent {
runner.setProperty(UnpackContent.PASSWORD, password);
final char[] streamPassword = password.toCharArray();
+ final String contents = TestRunner.class.getCanonicalName();
+
+ final byte[] zipEncrypted = createZipEncrypted(encryptionMethod, streamPassword, contents);
+ runner.enqueue(zipEncrypted);
+ runner.run();
+
+ runner.assertTransferCount(UnpackContent.REL_SUCCESS, 1);
+ runner.assertTransferCount(UnpackContent.REL_ORIGINAL, 1);
+
+ final MockFlowFile unpacked = runner.getFlowFilesForRelationship(UnpackContent.REL_SUCCESS).iterator().next();
+ unpacked.assertAttributeEquals(UnpackContent.FILE_ENCRYPTION_METHOD_ATTRIBUTE, encryptionMethod.toString());
+
+ final byte[] unpackedBytes = runner.getContentAsByteArray(unpacked);
+ final String unpackedContents = new String(unpackedBytes);
+ assertEquals("Unpacked Contents not matched", contents, unpackedContents);
+ }
+ private byte[] createZipEncrypted(final EncryptionMethod encryptionMethod, final char[] password, final String contents) throws IOException {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- final ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream, streamPassword);
+ final ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream, password);
final String name = UUID.randomUUID().toString();
- final String contents = TestRunner.class.getCanonicalName();
final ZipParameters zipParameters = new ZipParameters();
zipParameters.setEncryptionMethod(encryptionMethod);
@@ -490,18 +522,6 @@ public class TestUnpackContent {
zipOutputStream.closeEntry();
zipOutputStream.close();
- final byte[] bytes = outputStream.toByteArray();
- runner.enqueue(bytes);
- runner.run();
-
- runner.assertTransferCount(UnpackContent.REL_SUCCESS, 1);
- runner.assertTransferCount(UnpackContent.REL_ORIGINAL, 1);
-
- final MockFlowFile unpacked = runner.getFlowFilesForRelationship(UnpackContent.REL_SUCCESS).iterator().next();
- unpacked.assertAttributeEquals(UnpackContent.FILE_ENCRYPTION_METHOD_ATTRIBUTE, encryptionMethod.toString());
-
- final byte[] unpackedBytes = runner.getContentAsByteArray(unpacked);
- final String unpackedContents = new String(unpackedBytes);
- assertEquals("Unpacked Contents not matched", contents, unpackedContents);
+ return outputStream.toByteArray();
}
}