CaseUtils API improved.

This commit is contained in:
U-BASIS\dgrove 2018-05-17 00:55:10 -04:00
parent c597985175
commit fe1a278efa
3 changed files with 25 additions and 27 deletions

1
.gitignore vendored
View File

@ -13,6 +13,7 @@
/Core/dist/
/Core/nbproject/*
/Core/test/qa-functional/data/*
/Core/test/qa-functional/src/org/sleuthkit/autopsy/testutils/.preserve
!/Core/nbproject/project.xml
!/Core/nbproject/project.properties

View File

@ -18,7 +18,6 @@
*/
package org.sleuthkit.autopsy.modules.encryptiondetection;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@ -30,7 +29,6 @@ import org.netbeans.junit.NbTestCase;
import org.openide.util.Exceptions;
import org.python.icu.impl.Assert;
import org.sleuthkit.autopsy.casemodule.ImageDSProcessor;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.casemodule.services.FileManager;
import org.sleuthkit.autopsy.ingest.IngestJobSettings;
import org.sleuthkit.autopsy.ingest.IngestJobSettings.IngestType;
@ -51,18 +49,11 @@ import org.sleuthkit.datamodel.VolumeSystem;
public class EncryptionDetectionTest extends NbTestCase {
private static final String BITLOCKER_CASE_NAME = "testBitlockerEncryption";
private static final String PASSWORD_CASE_NAME = "testPasswordProtection";
private static final Path BITLOCKER_CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), BITLOCKER_CASE_NAME);
private static final Path PASSWORD_CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), PASSWORD_CASE_NAME);
private final Path BITLOCKER_IMAGE_PATH = Paths.get(this.getDataDir().toString(), "encryption_detection_bitlocker_test.vhd");
private final Path PASSWORD_IMAGE_PATH = Paths.get(this.getDataDir().toString(), "password_detection_test.img");
private static final String BITLOCKER_DETECTION_CASE_NAME = "testBitlockerEncryption";
private static final String PASSWORD_DETECTION_CASE_NAME = "PasswordDetectionTest";
private static final String VERACRYPT_DETECTION_CASE_NAME = "VeraCryptDetectionTest";
private final Path BITLOCKER_DETECTION_IMAGE_PATH = Paths.get(this.getDataDir().toString(), "encryption_detection_bitlocker_test.vhd");
private final Path PASSWORD_DETECTION_IMAGE_PATH = Paths.get(this.getDataDir().toString(), "password_detection_test.img");
private final Path VERACRYPT_DETECTION_IMAGE_PATH = Paths.get(this.getDataDir().toString(), "veracrypt_detection_test.vhd");
@ -79,10 +70,6 @@ public class EncryptionDetectionTest extends NbTestCase {
@Override
public void tearDown() {
File keepCaseData = new File(".keepCaseData");
if (keepCaseData.exists()) {
System.out.println("!");
}
CaseUtils.closeCurrentCase();
}
@ -91,9 +78,9 @@ public class EncryptionDetectionTest extends NbTestCase {
*/
public void testBitlockerEncryption() {
try {
Case openCase = CaseUtils.createAsCurrentCase(BITLOCKER_CASE_NAME);
Case openCase = CaseUtils.createAsCurrentCase(BITLOCKER_DETECTION_CASE_NAME);
ImageDSProcessor dataSourceProcessor = new ImageDSProcessor();
IngestUtils.addDataSource(dataSourceProcessor, BITLOCKER_IMAGE_PATH);
IngestUtils.addDataSource(dataSourceProcessor, BITLOCKER_DETECTION_IMAGE_PATH);
/*
* Create ingest job settings.

View File

@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import org.apache.commons.io.FileUtils;
@ -38,6 +39,8 @@ import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
*/
public final class CaseUtils {
private static final String PRESERVE_CASE_DATA_LIST_FILE_NAME = ".preserve";
/**
* Create a case case directory and case for the given case name.
*
@ -78,26 +81,33 @@ public final class CaseUtils {
* Close and delete the current case. This will fail the test if the case
* was unable to be closed.
*
* Note: This method will skip case deletion if '//DLG:' exists in the class
* folder.
* Note: This method will skip case deletion if '.preserve' exists with the
* functional test data and includes the current case path.
*/
public static void closeCurrentCase() {
try {
if (Case.isCaseOpen()) {
String currentCaseDirectory = Case.getCurrentCase().getCaseDirectory();
Case.closeCurrentCase();
File keepCaseData = new File(".keepCaseData");
if (keepCaseData.exists()) {
boolean deleteCase = true;
File preserveListFile = new File(
CaseUtils.class.getResource(PRESERVE_CASE_DATA_LIST_FILE_NAME).toExternalForm()
.substring(6)); // Use substring to remove "file:\" from path.
if (preserveListFile.exists()) {
Scanner scanner = new Scanner(preserveListFile);
while (scanner.hasNext()) {
if (scanner.nextLine().equalsIgnoreCase(currentCaseDirectory)) {
deleteCase = false;
break;
}
}
}
if (deleteCase) {
deleteCaseDir(new File(currentCaseDirectory));
}
}
System.gc();
//DLG: //Seems like we need some time to close the case, so file handler later can delete the case directory.
//DLG: try {
//DLG: Thread.sleep(20000);
//DLG: } catch (Exception ex) {
//DLG:
//DLG: }
} catch (CaseActionException | IOException ex) {
Exceptions.printStackTrace(ex);
Assert.fail(ex);