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 d6bf5a307f..1fc4e9f311 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 73635bd8a4..f14759f55d 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 @@ -236,6 +236,22 @@ public class TestUnpackContent { runZipEncryptionMethod(EncryptionMethod.AES); } + @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()); @@ -474,24 +490,10 @@ public class TestUnpackContent { runner.setProperty(UnpackContent.PASSWORD, password); final char[] streamPassword = password.toCharArray(); - - final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - final ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream, streamPassword); - - final String name = UUID.randomUUID().toString(); final String contents = TestRunner.class.getCanonicalName(); - final ZipParameters zipParameters = new ZipParameters(); - zipParameters.setEncryptionMethod(encryptionMethod); - zipParameters.setEncryptFiles(true); - zipParameters.setFileNameInZip(name); - zipOutputStream.putNextEntry(zipParameters); - zipOutputStream.write(contents.getBytes()); - zipOutputStream.closeEntry(); - zipOutputStream.close(); - - final byte[] bytes = outputStream.toByteArray(); - runner.enqueue(bytes); + final byte[] zipEncrypted = createZipEncrypted(encryptionMethod, streamPassword, contents); + runner.enqueue(zipEncrypted); runner.run(); runner.assertTransferCount(UnpackContent.REL_SUCCESS, 1); @@ -504,4 +506,22 @@ public class TestUnpackContent { 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, password); + + final String name = UUID.randomUUID().toString(); + + final ZipParameters zipParameters = new ZipParameters(); + zipParameters.setEncryptionMethod(encryptionMethod); + zipParameters.setEncryptFiles(true); + zipParameters.setFileNameInZip(name); + zipOutputStream.putNextEntry(zipParameters); + zipOutputStream.write(contents.getBytes()); + zipOutputStream.closeEntry(); + zipOutputStream.close(); + + return outputStream.toByteArray(); + } }