Updated 'addDataSource()' to handle critical errors.

This commit is contained in:
U-BASIS\dgrove 2018-05-15 16:45:23 -04:00
parent 79b703d0f4
commit 9cd23cdece
3 changed files with 21 additions and 20 deletions

View File

@ -160,9 +160,7 @@ public class EncryptionDetectionTest extends NbTestCase {
CaseUtils.createCase(PASSWORD_DETECTION_CASE_NAME);
ImageDSProcessor dataSourceProcessor = new ImageDSProcessor();
List<String> errorMessages = IngestUtils.addDataSource(dataSourceProcessor, PASSWORD_DETECTION_IMAGE_PATH);
String joinedErrors = String.join(System.lineSeparator(), errorMessages);
assertEquals(joinedErrors, 0, errorMessages.size());
IngestUtils.addDataSource(dataSourceProcessor, PASSWORD_DETECTION_IMAGE_PATH);
Case openCase = Case.getCurrentCaseThrows();
@ -260,15 +258,7 @@ public class EncryptionDetectionTest extends NbTestCase {
try {
CaseUtils.createCase(VERACRYPT_DETECTION_CASE_NAME);
ImageDSProcessor dataSourceProcessor = new ImageDSProcessor();
List<String> errorMessages = IngestUtils.addDataSource(dataSourceProcessor, VERACRYPT_DETECTION_IMAGE_PATH);
String joinedErrors;
if (errorMessages.isEmpty()) {
joinedErrors = "Encrypted partition did not cause error, it was expected to";
} else {
joinedErrors = String.join(System.lineSeparator(), errorMessages);
}
//there will be 1 expected error regarding the encrypted partition not having a file system
assertEquals(joinedErrors, 1, errorMessages.size());
IngestUtils.addDataSource(dataSourceProcessor, VERACRYPT_DETECTION_IMAGE_PATH);
Case openCase = Case.getCurrentCaseThrows();
ArrayList<IngestModuleTemplate> templates = new ArrayList<>();

View File

@ -62,6 +62,7 @@ public final class DataSourceProcessorRunner {
private final Object monitor;
private final List<String> errorMessages = new ArrayList<>();
private final List<Content> dataSourceContent = new ArrayList<>();
private DataSourceProcessorResult result;
/**
* Constructs a data source processor "callback" that collects the
@ -91,6 +92,7 @@ public final class DataSourceProcessorRunner {
public void done(DataSourceProcessorCallback.DataSourceProcessorResult result, List<String> errorMessages, List<Content> dataSourceContent) {
this.errorMessages.addAll(errorMessages);
this.dataSourceContent.addAll(dataSourceContent);
this.result = result;
synchronized (monitor) {
monitor.notify();
}
@ -131,6 +133,15 @@ public final class DataSourceProcessorRunner {
public List<Content> getDataSourceContent() {
return new ArrayList<>(this.dataSourceContent);
}
/**
* Gets the result of the data source processor run.
*
* @return The result.
*/
public DataSourceProcessorResult getResult() {
return result;
}
}
/**

View File

@ -19,11 +19,11 @@
package org.sleuthkit.autopsy.testutils;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import static junit.framework.Assert.assertEquals;
import org.openide.util.Exceptions;
import org.python.icu.impl.Assert;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorCallback;
import org.sleuthkit.autopsy.datasourceprocessors.AutoIngestDataSourceProcessor;
import org.sleuthkit.autopsy.ingest.IngestJobSettings;
import org.sleuthkit.autopsy.ingest.IngestModuleError;
@ -53,23 +53,23 @@ public final class IngestUtils {
* datasource
* @param dataSourcePath the path to the datasource which is being
* added
*
* @return errorMessages a list of all error messages as strings which
* encountered while processing the data source
*/
public static List<String> addDataSource(AutoIngestDataSourceProcessor dataSourceProcessor, Path dataSourcePath) {
List<String> errorMessages = new ArrayList<>();
public static void addDataSource(AutoIngestDataSourceProcessor dataSourceProcessor, Path dataSourcePath) {
DataSourceProcessorCallback.DataSourceProcessorResult result = null;
try {
if (!dataSourcePath.toFile().exists()) {
Assert.fail("Data source not found: " + dataSourcePath.toString());
}
DataSourceProcessorRunner.ProcessorCallback callBack = DataSourceProcessorRunner.runDataSourceProcessor(dataSourceProcessor, dataSourcePath);
errorMessages = callBack.getErrorMessages();
result = callBack.getResult();
if (result.equals(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS)) {
Assert.fail("Critical errors occurred while running the data source processor.");
}
} catch (AutoIngestDataSourceProcessor.AutoIngestDataSourceProcessorException | InterruptedException ex) {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
return errorMessages;
}
/**