mirror of https://github.com/apache/nifi.git
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:
parent
ea6b01159d
commit
efb629e37d
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue