mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 02:07:42 +00:00
Merge pull request #3644 from zhhl/3591-2ndTestForFileFilterTest
3591 2nd test for file filter test
This commit is contained in:
commit
1384e3323d
@ -147,8 +147,8 @@ public class IngestFileFiltersTest extends NbTestCase {
|
|||||||
//All files in dir1 should have MIME type, except '.' '..' and slack files
|
//All files in dir1 should have MIME type, except '.' '..' and slack files
|
||||||
if (file.getParentPath().equalsIgnoreCase("/dir1/")) {
|
if (file.getParentPath().equalsIgnoreCase("/dir1/")) {
|
||||||
if (!(file.getName().equals(".") || file.getName().equals("..") || file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
|
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());
|
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()));
|
assertTrue(errMsg, file.getMIMEType() != null && !file.getMIMEType().isEmpty());
|
||||||
}
|
}
|
||||||
} else { //All files not in dir1 shouldn't have MIME type
|
} 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());
|
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<String, Rule> 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<AbstractFile> 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<Content> datasources, FilesSet filter) {
|
private void runIngestJob(List<Content> datasources, FilesSet filter) {
|
||||||
FileTypeIdModuleFactory factory = new FileTypeIdModuleFactory();
|
FileTypeIdModuleFactory factory = new FileTypeIdModuleFactory();
|
||||||
IngestModuleIngestJobSettings settings = factory.getDefaultIngestJobSettings();
|
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);
|
IngestJobSettings ingestJobSettings = new IngestJobSettings(IngestFileFiltersTest.class.getCanonicalName(), IngestType.FILES_ONLY, templates, filter);
|
||||||
try {
|
try {
|
||||||
List<IngestModuleError> errs = IngestJobRunner.runIngestJob(datasources, ingestJobSettings);
|
List<IngestModuleError> 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());
|
assertEquals(0, errs.size());
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
Exceptions.printStackTrace(ex);
|
Exceptions.printStackTrace(ex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user