Repository: nifi Updated Branches: refs/heads/master 6bf6a92ab -> 6356d7b9e
NIFI-4988 This closes #2725. Changed the exception handling so that an invliad ZIP is handled. When an invalid zip is processed, the exception is an IllegalArgumentException which was not being handled and thus the session was being rollbacked. Signed-off-by: joewitt <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/6356d7b9 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/6356d7b9 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/6356d7b9 Branch: refs/heads/master Commit: 6356d7b9ee7cd9a84515a441724a2659397a0ffa Parents: 6bf6a92 Author: Andrew Psaltis <[email protected]> Authored: Sun May 20 15:10:39 2018 +0800 Committer: joewitt <[email protected]> Committed: Tue May 22 10:24:57 2018 -0400 ---------------------------------------------------------------------- .../nifi-standard-processors/pom.xml | 1 + .../nifi/processors/standard/UnpackContent.java | 3 +- .../processors/standard/TestUnpackContent.java | 33 +++++++++++++++++++ .../TestUnpackContent/invalid_data.zip | Bin 0 -> 1019 bytes 4 files changed, 35 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/6356d7b9/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml index 1e7ffb4..6052daf 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml @@ -448,6 +448,7 @@ <exclude>src/test/resources/TestIdentifyMimeType/flowfilev1.tar</exclude> <exclude>src/test/resources/TestUnpackContent/data.tar</exclude> <exclude>src/test/resources/TestUnpackContent/data.zip</exclude> + <exclude>src/test/resources/TestUnpackContent/invalid_data.zip</exclude> <exclude>src/test/resources/TestEncryptContent/plain.txt</exclude> <exclude>src/test/resources/TestEncryptContent/salted_raw.enc</exclude> <exclude>src/test/resources/TestEncryptContent/salted_128_raw.enc</exclude> http://git-wip-us.apache.org/repos/asf/nifi/blob/6356d7b9/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/UnpackContent.java ---------------------------------------------------------------------- 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 1e7f05b..26308da 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 @@ -20,7 +20,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; @@ -268,7 +267,7 @@ public class UnpackContent extends AbstractProcessor { session.transfer(flowFile, REL_ORIGINAL); session.getProvenanceReporter().fork(flowFile, unpacked); logger.info("Unpacked {} into {} and transferred to success", new Object[]{flowFile, unpacked}); - } catch (final ProcessException | InvalidPathException e) { + } catch (final Exception e) { logger.error("Unable to unpack {} due to {}; routing to failure", new Object[]{flowFile, e}); session.transfer(flowFile, REL_FAILURE); session.remove(unpacked); http://git-wip-us.apache.org/repos/asf/nifi/blob/6356d7b9/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java ---------------------------------------------------------------------- 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 587d050..980d293 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 @@ -168,6 +168,39 @@ public class TestUnpackContent { flowFile.assertContentEquals(path.toFile()); } } + @Test + public void testInvalidZip() throws IOException { + final TestRunner unpackRunner = TestRunners.newTestRunner(new UnpackContent()); + final TestRunner autoUnpackRunner = TestRunners.newTestRunner(new UnpackContent()); + unpackRunner.setProperty(UnpackContent.PACKAGING_FORMAT, UnpackContent.PackageFormat.ZIP_FORMAT.toString()); + autoUnpackRunner.setProperty(UnpackContent.PACKAGING_FORMAT, UnpackContent.PackageFormat.AUTO_DETECT_FORMAT.toString()); + unpackRunner.enqueue(dataPath.resolve("invalid_data.zip")); + unpackRunner.enqueue(dataPath.resolve("invalid_data.zip")); + Map<String, String> attributes = new HashMap<>(1); + attributes.put("mime.type", "application/zip"); + autoUnpackRunner.enqueue(dataPath.resolve("invalid_data.zip"), attributes); + autoUnpackRunner.enqueue(dataPath.resolve("invalid_data.zip"), attributes); + unpackRunner.run(2); + autoUnpackRunner.run(2); + + unpackRunner.assertTransferCount(UnpackContent.REL_FAILURE, 2); + unpackRunner.assertTransferCount(UnpackContent.REL_ORIGINAL, 0); + unpackRunner.assertTransferCount(UnpackContent.REL_SUCCESS, 0); + + autoUnpackRunner.assertTransferCount(UnpackContent.REL_FAILURE, 2); + autoUnpackRunner.assertTransferCount(UnpackContent.REL_ORIGINAL, 0); + autoUnpackRunner.assertTransferCount(UnpackContent.REL_SUCCESS, 0); + + final List<MockFlowFile> unpacked = unpackRunner.getFlowFilesForRelationship(UnpackContent.REL_FAILURE); + for (final MockFlowFile flowFile : unpacked) { + final String filename = flowFile.getAttribute(CoreAttributes.FILENAME.key()); + // final String folder = flowFile.getAttribute(CoreAttributes.PATH.key()); + final Path path = dataPath.resolve(filename); + assertTrue(Files.exists(path)); + + flowFile.assertContentEquals(path.toFile()); + } + } @Test public void testZipWithFilter() throws IOException { http://git-wip-us.apache.org/repos/asf/nifi/blob/6356d7b9/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestUnpackContent/invalid_data.zip ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestUnpackContent/invalid_data.zip b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestUnpackContent/invalid_data.zip new file mode 100644 index 0000000..73d3fe6 Binary files /dev/null and b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestUnpackContent/invalid_data.zip differ
