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 <alopresto@apache.org>
This commit is contained in:
exceptionfactory 2020-10-05 22:02:31 -04:00 committed by Andy LoPresto
parent ea6b01159d
commit efb629e37d
No known key found for this signature in database
GPG Key ID: 6EC293152D90B61D
2 changed files with 37 additions and 19 deletions

View File

@ -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);
}

View File

@ -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();
}
}