Keep case directory when test fails.

This commit is contained in:
U-BASIS\dgrove 2018-05-18 16:09:43 -04:00
parent c75adf1df9
commit 9ecaa0d34b
5 changed files with 61 additions and 31 deletions

1
.gitignore vendored
View File

@ -13,7 +13,6 @@
/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

@ -30,7 +30,6 @@ import org.openide.util.Exceptions;
import org.python.icu.impl.Assert;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.ImageDSProcessor;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.ingest.IngestJobSettings.IngestType;
import org.sleuthkit.autopsy.modules.embeddedfileextractor.EmbeddedFileExtractorModuleFactory;
import org.sleuthkit.autopsy.modules.hashdatabase.HashLookupModuleFactory;
@ -48,6 +47,8 @@ public class EmbeddedFileTest extends NbTestCase {
public static final String HASH_VALUE = "098f6bcd4621d373cade4e832627b4f6";
private static final int DEEP_FOLDER_COUNT = 25;
private Case openCase;
private boolean testSucceeded;
public static Test suite() {
NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(EmbeddedFileTest.class).
@ -62,6 +63,8 @@ public class EmbeddedFileTest extends NbTestCase {
@Override
public void setUp() {
testSucceeded = false;
openCase = CaseUtils.createAsCurrentCase(CASE_NAME);
ImageDSProcessor dataSourceProcessor = new ImageDSProcessor();
IngestUtils.addDataSource(dataSourceProcessor, IMAGE_PATH);
@ -84,7 +87,7 @@ public class EmbeddedFileTest extends NbTestCase {
@Override
public void tearDown() {
CaseUtils.closeCurrentCase();
CaseUtils.closeCurrentCase(testSucceeded);
}
public void testEncryption() {
@ -117,6 +120,7 @@ public class EmbeddedFileTest extends NbTestCase {
Assert.fail(ex);
}
testSucceeded = true;
}
public void testBigFolder() {
@ -143,6 +147,7 @@ public class EmbeddedFileTest extends NbTestCase {
Assert.fail(ex);
}
testSucceeded = true;
}
public void testDeepFolder() {
@ -165,6 +170,7 @@ public class EmbeddedFileTest extends NbTestCase {
Assert.fail(ex);
}
testSucceeded = true;
}
public void testEmbeddedFile() {
@ -190,6 +196,7 @@ public class EmbeddedFileTest extends NbTestCase {
Assert.fail(ex);
}
testSucceeded = true;
}
public void testContent() {
@ -213,7 +220,9 @@ public class EmbeddedFileTest extends NbTestCase {
} catch (TskCoreException ex) {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
}
testSucceeded = true;
}
public void testExtension() {
@ -225,7 +234,9 @@ public class EmbeddedFileTest extends NbTestCase {
} catch (TskCoreException ex) {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
}
testSucceeded = true;
}
private void checkEachFileInDeepFolder(AbstractFile file, StringBuffer dirReached, ArrayList<String> fileReached, int numOfDir) {

View File

@ -55,6 +55,8 @@ public class IngestFileFiltersTest extends NbTestCase {
private final Path IMAGE_PATH = Paths.get(this.getDataDir().toString(),"filter_test1.img");
private final Path ZIPFILE_PATH = Paths.get(this.getDataDir().toString(), "local_files_test.zip");
private boolean testSucceeded;
public static Test suite() {
NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(IngestFileFiltersTest.class).
clusters(".*").
@ -65,10 +67,15 @@ public class IngestFileFiltersTest extends NbTestCase {
public IngestFileFiltersTest(String name) {
super(name);
}
@Override
public void setUp() {
testSucceeded = false;
}
@Override
public void tearDown() {
CaseUtils.closeCurrentCase();
CaseUtils.closeCurrentCase(testSucceeded);
}
public void testBasicDir() {
@ -110,6 +117,7 @@ public class IngestFileFiltersTest extends NbTestCase {
Assert.fail(ex);
}
testSucceeded = true;
}
public void testExtAndDirWithOneRule() {
@ -144,6 +152,8 @@ public class IngestFileFiltersTest extends NbTestCase {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
testSucceeded = true;
}
public void testExtAndDirWithTwoRules() {
@ -187,6 +197,8 @@ public class IngestFileFiltersTest extends NbTestCase {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
testSucceeded = true;
}
public void testFullFileNameRule() {
@ -221,6 +233,8 @@ public class IngestFileFiltersTest extends NbTestCase {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
testSucceeded = true;
}
public void testCarvingWithExtRuleAndUnallocSpace() {
@ -268,6 +282,8 @@ public class IngestFileFiltersTest extends NbTestCase {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
testSucceeded = true;
}
public void testCarvingNoUnallocatedSpace() {
@ -300,6 +316,8 @@ public class IngestFileFiltersTest extends NbTestCase {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
testSucceeded = true;
}
public void testEmbeddedModule() {
@ -345,5 +363,7 @@ public class IngestFileFiltersTest extends NbTestCase {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
testSucceeded = true;
}
}

View File

@ -56,6 +56,8 @@ public class EncryptionDetectionTest extends NbTestCase {
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");
private boolean testSucceeded;
public static Test suite() {
NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(EncryptionDetectionTest.class).
@ -67,10 +69,15 @@ public class EncryptionDetectionTest extends NbTestCase {
public EncryptionDetectionTest(String name) {
super(name);
}
@Override
public void setUp() {
testSucceeded = false;
}
@Override
public void tearDown() {
CaseUtils.closeCurrentCase();
CaseUtils.closeCurrentCase(testSucceeded);
}
/**
@ -141,6 +148,8 @@ public class EncryptionDetectionTest extends NbTestCase {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
testSucceeded = true;
}
/**
@ -227,6 +236,8 @@ public class EncryptionDetectionTest extends NbTestCase {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
testSucceeded = true;
}
/**
@ -280,6 +291,8 @@ public class EncryptionDetectionTest extends NbTestCase {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
testSucceeded = true;
}
}

View File

@ -22,7 +22,6 @@ 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;
@ -78,37 +77,25 @@ public final class CaseUtils {
}
/**
* Close and delete the current case. This will fail the test if the case
* Close the current case. This will fail the test if the case
* was unable to be closed.
*
* Note: This method will skip case deletion if '.preserve' exists in the
* 'org.sleuthkit.autopsy.testutils' package and includes the current case
* path.
*
* @param deleteCase Delete the case after closure?
*/
public static void closeCurrentCase() {
public static void closeCurrentCase(boolean deleteCase) {
try {
if (Case.isCaseOpen()) {
String currentCaseDirectory = Case.getCurrentCase().getCaseDirectory();
Case.closeCurrentCase();
System.gc();
/*
* Look for the current case directory in '.preserved'. If
* found, skip case deletion.
*/
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;
}
}
// Seems like we need some time to close the case, so file handler later can delete the case directory.
try {
Thread.sleep(20000);
} catch (InterruptedException ex) {
}
if (deleteCase) {
deleteCaseDir(new File(currentCaseDirectory));
}