diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/ingest/IngestFileFiltersTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/ingest/IngestFileFiltersTest.java index 54b7024790..6d6f48424e 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/ingest/IngestFileFiltersTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/ingest/IngestFileFiltersTest.java @@ -147,8 +147,8 @@ public class IngestFileFiltersTest extends NbTestCase { //All files in dir1 should have MIME type, except '.' '..' and slack files if (file.getParentPath().equalsIgnoreCase("/dir1/")) { if (!(file.getName().equals(".") || file.getName().equals("..") || file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) { - String errMsg = String.format("File %s (objId=%d) unexpectedly blocked by the file filter.", file.getName(), file.getId()); - assertTrue(errMsg, !(file.getMIMEType() == null || file.getMIMEType().isEmpty())); + String errMsg = String.format("File %s (objId=%d) unexpectedly passed by the file filter.", file.getName(), file.getId()); + assertTrue(errMsg, file.getMIMEType() != null && !file.getMIMEType().isEmpty()); } } else { //All files not in dir1 shouldn't have MIME type String errMsg = String.format("File %s (objId=%d) unexpectedly passed by the file filter.", file.getName(), file.getId()); @@ -161,6 +161,34 @@ public class IngestFileFiltersTest extends NbTestCase { } } + public void testExtAndDirWithOneRule() { + HashMap rules = new HashMap<>(); + rules.put("Rule", new Rule("testExtAndDirWithOneRule", new Rule.ExtensionCondition("jpg"), new MetaTypeCondition(MetaTypeCondition.Type.FILES), new ParentPathCondition("dir1"), null, null, null)); + //Build the filter that ignore unallocated space and with one rule + FilesSet filesExtDirsFilter = new FilesSet("Filter", "Filter to find all jpg files in dir1.", false, true, rules); + + try { + Case openCase = Case.getOpenCase(); + runIngestJob(openCase.getDataSources(), filesExtDirsFilter); + FileManager fileManager = Case.getOpenCase().getServices().getFileManager(); + List results = fileManager.findFiles("%%"); + assertEquals(62, results.size()); + for (AbstractFile file : results) { + //Files with jpg extension in dir1 should have MIME Type + if (file.getParentPath().equalsIgnoreCase("/dir1/") && file.getNameExtension().equalsIgnoreCase("jpg")) { + String errMsg = String.format("File %s (objId=%d) unexpectedly blocked by the file filter.", file.getName(), file.getId()); + assertTrue(errMsg, file.getMIMEType() != null && !file.getMIMEType().isEmpty()); + } else { //All others shouldn't have MIME Type + String errMsg = String.format("File %s (objId=%d) unexpectedly passed by the file filter.", file.getName(), file.getId()); + assertTrue(errMsg, file.getMIMEType() == null); + } + } + } catch (NoCurrentCaseException | TskCoreException ex) { + Exceptions.printStackTrace(ex); + Assert.fail(ex); + } + } + private void runIngestJob(List datasources, FilesSet filter) { FileTypeIdModuleFactory factory = new FileTypeIdModuleFactory(); IngestModuleIngestJobSettings settings = factory.getDefaultIngestJobSettings(); @@ -171,6 +199,9 @@ public class IngestFileFiltersTest extends NbTestCase { IngestJobSettings ingestJobSettings = new IngestJobSettings(IngestFileFiltersTest.class.getCanonicalName(), IngestType.FILES_ONLY, templates, filter); try { List errs = IngestJobRunner.runIngestJob(datasources, ingestJobSettings); + for (IngestModuleError err : errs) { + System.out.println(String.format("Error: %s: %s.", err.getModuleDisplayName(), err.toString())); + } assertEquals(0, errs.size()); } catch (InterruptedException ex) { Exceptions.printStackTrace(ex);