diff --git a/.gitignore b/.gitignore index 0f00c6c00fc7801bc90f144d228af345e8dcf4e8..cd8db0d520682f349433b3e7db116b3a8fe40eaf 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/modules/encryptiondetection/EncryptionDetectionTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/modules/encryptiondetection/EncryptionDetectionTest.java index 726a0e5439a8a28191773be9ef4722081c2b4491..bb590c0109bf3e738394bef13b7adf68d9aa0dca 100755 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/modules/encryptiondetection/EncryptionDetectionTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/modules/encryptiondetection/EncryptionDetectionTest.java @@ -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.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 @@ 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 EncryptionDetectionTest(String name) { @Override public void tearDown() { - File keepCaseData = new File(".keepCaseData"); - if (keepCaseData.exists()) { - System.out.println("!"); - } CaseUtils.closeCurrentCase(); } @@ -91,9 +78,9 @@ public void tearDown() { */ 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. diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/testutils/CaseUtils.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/testutils/CaseUtils.java index 7e0a9f97990c9ca7324faafda3de177c2e9d92df..f0f87838963c33f1f5fa777025f2a52d0e2c44e5 100755 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/testutils/CaseUtils.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/testutils/CaseUtils.java @@ -22,6 +22,7 @@ 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 @@ */ 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 static Case createAsCurrentCase(String caseName) { * 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);