1
0
mirror of https://github.com/elisspace/autopsy.git synced 2026-09-03 22:39:56 +00:00

more tests

This commit is contained in:
Brian Sweeney
2018-05-08 15:42:46 -06:00
parent 25b6ac9de9
commit 4a0ae67b05
5 changed files with 268 additions and 71 deletions

View File

@@ -69,7 +69,7 @@ public class DataSourceLoader {
public Map<Long, String> getDataSourceMap() throws NoCurrentCaseException, TskCoreException, SQLException {
Map<Long, String> dataSouceMap = new HashMap<>();
Case currentCase = Case.getOpenCase();
Case currentCase = Case.getCurrentCaseThrows();
SleuthkitCase tskDb = currentCase.getSleuthkitCase();
loadLogicalSources(tskDb, dataSouceMap);

View File

@@ -21,11 +21,8 @@ package org.sleuthkit.autopsy.commonfilessearch;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import junit.framework.Test;
import org.netbeans.junit.NbModuleSuite;
import org.openide.util.Exceptions;
@@ -35,8 +32,6 @@ import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.commonfilesearch.AllDataSourcesCommonFilesAlgorithm;
import org.sleuthkit.autopsy.commonfilesearch.CommonFilesMetadata;
import org.sleuthkit.autopsy.commonfilesearch.CommonFilesMetadataBuilder;
import org.sleuthkit.autopsy.commonfilesearch.FileInstanceMetadata;
import org.sleuthkit.autopsy.commonfilesearch.Md5Metadata;
import org.sleuthkit.autopsy.commonfilesearch.SingleDataSource;
import org.sleuthkit.autopsy.ingest.IngestJobSettings;
import org.sleuthkit.autopsy.ingest.IngestJobSettings.IngestType;
@@ -46,6 +41,9 @@ import org.sleuthkit.autopsy.testutils.IngestUtils;
import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.TskCoreException;
/**
* Add #1, #2, #3, and #4 to case and ingest with hash algorithm.
*/
public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest {
public static Test suite() {
@@ -71,7 +69,7 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest {
IngestJobSettings ingestJobSettings = new IngestJobSettings(IngestedWithHashAlgOnly.class.getCanonicalName(), IngestType.FILES_ONLY, templates);
try {
IngestUtils.runIngestJob(Case.getOpenCase().getDataSources(), ingestJobSettings);
IngestUtils.runIngestJob(Case.getCurrentCaseThrows().getDataSources(), ingestJobSettings);
} catch (NoCurrentCaseException | TskCoreException ex) {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
@@ -79,12 +77,8 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest {
}
/**
* Add #1, #2, #3, and #4 to case and ingest with hash algorithm. Find all
* matches & all file types. Confirm file.jpg is found on all three and
* file.docx is found on two. Find matches on #1 & all file types. Confirm
* same results. Find matches on #2 & all file types: Confirm file.jpg.
* Find matches on #3 & all file types: Confirm file.jpg and file.docx.
* Find matches on #4 & all file types: Confirm nothing is found
* Find all matches & all file types. Confirm file.jpg is found on all three and
* file.docx is found on two.
*/
public void testOne() {
try {
@@ -92,11 +86,27 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest {
CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, false, false);
CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles();
Map<Long, String> objectIdToDataSource = mapFileInstancesToDataSources(metadata);
List<AbstractFile> files = getFiles(objectIdToDataSource.keySet());
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET1, 2));
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET2, 1));
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET3, 1));
assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1));
assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 3));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET2, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET3, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET4, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET2, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET3, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET4, 0));
} catch (NoCurrentCaseException ex) {
@@ -107,31 +117,14 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest {
Exceptions.printStackTrace(ex);
}
}
private boolean fileExists(List<AbstractFile> files, String name, String dataSource, int count){
for (AbstractFile file : files){
Long id = file.getId();
String fileName = file.getName();
final String dataSourceName = objectIdToDataSource.get(id);
switch(fileName){
case "IMG_6175.jpg":
case "BasicStyleGuide.doc":
case "asdf.pdf":
case "file.dat":
}
}
}
private boolean fileExists(List<AbstractFile> files, String name, String dataSource){
return fileExists(files, name, dataSource, 1);
}
/**
* Find matches on #1 & all file types. Confirm
* same results.
*
*/
public void testTwo() {
try {
Map<Long, String> dataSources = this.dataSourceLoader.getDataSourceMap();
@@ -139,40 +132,146 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest {
CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false);
CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles();
Map<Long, String> objectIdToDataSource = mapFileInstancesToDataSources(metadata);
List<AbstractFile> files = getFiles(objectIdToDataSource.keySet());
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET1, 2));
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET2, 1));
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET3, 1));
assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1));
assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 3));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET2, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET3, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET4, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET2, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET3, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET4, 0));
} catch (NoCurrentCaseException | TskCoreException | SQLException ex) {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
}
private Map<Long, String> mapFileInstancesToDataSources(CommonFilesMetadata metadata) {
Map<Long, String> instanceIdToDataSource = new HashMap<>();
for(Entry<String, Md5Metadata> entry : metadata.getMetadata().entrySet()){
for (FileInstanceMetadata md : entry.getValue().getMetadata()){
instanceIdToDataSource.put(md.getObjectId(), md.getDataSourceName());
}
/**
* Find matches on #2 & all file types: Confirm file.jpg.
*
*/
public void testThree(){
try {
Map<Long, String> dataSources = this.dataSourceLoader.getDataSourceMap();
Long second = new Long(2);
CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(second, dataSources, false, false);
CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles();
Map<Long, String> objectIdToDataSource = mapFileInstancesToDataSources(metadata);
List<AbstractFile> files = getFiles(objectIdToDataSource.keySet());
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET1, 2));
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET2, 1));
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET3, 1));
assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET2, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET3, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET4, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET2, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET3, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET4, 0));
} catch (NoCurrentCaseException | TskCoreException | SQLException ex) {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
return instanceIdToDataSource;
}
private List<AbstractFile> getFiles(Set<Long> keySet) {
List<AbstractFile> files = new ArrayList<>(keySet.size());
for(Long id : keySet){
try {
AbstractFile file = Case.getOpenCase().getSleuthkitCase().getAbstractFileById(id);
files.add(file);
} catch (NoCurrentCaseException | TskCoreException ex) {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
/**
* Find matches on #4 & all file types: Confirm nothing is found.
*/
public void testFour(){
try {
Map<Long, String> dataSources = this.dataSourceLoader.getDataSourceMap();
Long last = new Long(4);
CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(last, dataSources, false, false);
CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles();
Map<Long, String> objectIdToDataSource = mapFileInstancesToDataSources(metadata);
List<AbstractFile> files = getFiles(objectIdToDataSource.keySet());
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET2, 0));
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET3, 0));
assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET2, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET3, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET4, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET2, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET3, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET4, 0));
} catch (NoCurrentCaseException | TskCoreException | SQLException ex) {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
}
/**
* Find matches on #3 & all file types: Confirm file.jpg and file.docx.
*/
public void testFive(){
try {
Map<Long, String> dataSources = this.dataSourceLoader.getDataSourceMap();
Long third = new Long(3);
CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(third, dataSources, false, false);
CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles();
Map<Long, String> objectIdToDataSource = mapFileInstancesToDataSources(metadata);
List<AbstractFile> files = getFiles(objectIdToDataSource.keySet());
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET1, 2));
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET2, 1));
assertTrue(fileExists(files, objectIdToDataSource, IMG, SET3, 1));
assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET2, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET3, 0));
assertTrue(fileExists(files, objectIdToDataSource, PDF, SET4, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET1, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET2, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET3, 0));
assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET4, 0));
} catch (NoCurrentCaseException | TskCoreException | SQLException ex) {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
return files;
}
}

View File

@@ -21,15 +21,51 @@ package org.sleuthkit.autopsy.commonfilessearch;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.netbeans.junit.NbTestCase;
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.commonfilesearch.CommonFilesMetadata;
import org.sleuthkit.autopsy.commonfilesearch.DataSourceLoader;
import org.sleuthkit.autopsy.commonfilesearch.FileInstanceMetadata;
import org.sleuthkit.autopsy.commonfilesearch.Md5Metadata;
import org.sleuthkit.autopsy.testutils.CaseUtils;
import org.sleuthkit.autopsy.testutils.IngestUtils;
import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.TskCoreException;
/**
*
* @author bsweeney
* Provides setup and utility for testing presence of files in different data
* sets discoverable by Common Files Features.
*
* Data set definitions:
*
* set 1
* + file1
* - IMG_6175.jpg
* + file2
* - IMG_6175.jpg
* + file3
* - BasicStyleGuide.doc
*
* set 2
* - adsf.pdf
* - IMG_6175.jpg
*
* set 3
* - BasicStyleGuide.doc
* - IMG_6175.jpg
*
* set 4
* - file.dat (empty file)
*/
public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase {
@@ -40,6 +76,16 @@ public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase {
private final Path IMAGE_PATH_2 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image2_v1.vhd");
private final Path IMAGE_PATH_3 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image3_v1.vhd");
protected final Path IMAGE_PATH_4 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image4_v1.vhd");
protected final String IMG = "IMG_6175.jpg";
protected final String DOC = "BasicStyleGuide.doc";
protected final String PDF = "adsf.pdf";
protected final String EMPTY = "file.dat";
protected final String SET1 = "commonfiles_image1_v1.vhd";
protected final String SET2 = "commonfiles_image2_v1.vhd";
protected final String SET3 = "commonfiles_image3_v1.vhd";
protected final String SET4 = "commonfiles_image4_v1.vhd";
protected DataSourceLoader dataSourceLoader;
@@ -50,7 +96,7 @@ public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase {
@Override
public void setUp() {
CaseUtils.createCase(CASE_DIRECTORY_PATH);
CaseUtils.createCase(CASE_DIRECTORY_PATH, "IntraCaseCommonFilesSearchTests");
IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_1);
IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_2);
@@ -65,4 +111,56 @@ public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase {
CaseUtils.closeCase();
CaseUtils.deleteCaseDir(CASE_DIRECTORY_PATH);
}
protected boolean fileExists(List<AbstractFile> files, Map<Long, String> objectIdToDataSource, String name, String dataSource, int count) {
int tally = 0;
for (AbstractFile file : files) {
Long id = file.getId();
String fileName = file.getName();
String dataSourceName = objectIdToDataSource.get(id);
if (fileName.equals(name) && dataSourceName.equals(dataSource)) {
tally++;
}
}
return tally == count;
}
protected boolean fileExists(List<AbstractFile> files, Map<Long, String> objectIdToDataSource, String name, String dataSource) {
return fileExists(files, objectIdToDataSource, name, dataSource, 1);
}
protected Map<Long, String> mapFileInstancesToDataSources(CommonFilesMetadata metadata) {
Map<Long, String> instanceIdToDataSource = new HashMap<>();
for (Map.Entry<String, Md5Metadata> entry : metadata.getMetadata().entrySet()) {
for (FileInstanceMetadata md : entry.getValue().getMetadata()) {
instanceIdToDataSource.put(md.getObjectId(), md.getDataSourceName());
}
}
return instanceIdToDataSource;
}
protected List<AbstractFile> getFiles(Set<Long> keySet) {
List<AbstractFile> files = new ArrayList<>(keySet.size());
for (Long id : keySet) {
try {
AbstractFile file = Case.getCurrentCaseThrows().getSleuthkitCase().getAbstractFileById(id);
files.add(file);
} catch (NoCurrentCaseException | TskCoreException ex) {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
}
return files;
}
}

View File

@@ -1,5 +1,5 @@
#Updated by build script
#Mon, 19 Mar 2018 11:17:11 -0700
#Tue, 08 May 2018 10:29:55 -0600
LBL_splash_window_title=Starting Autopsy
SPLASH_HEIGHT=314
SPLASH_WIDTH=538
@@ -8,4 +8,4 @@ SplashRunningTextBounds=0,289,538,18
SplashRunningTextColor=0x0
SplashRunningTextFontSize=19
currentVersion=Autopsy 4.6.0
currentVersion=Autopsy 4.7.0

View File

@@ -1,4 +1,4 @@
#Updated by build script
#Fri, 09 Mar 2018 13:03:41 -0700
CTL_MainWindow_Title=Autopsy 4.6.0
CTL_MainWindow_Title_No_Project=Autopsy 4.6.0
#Tue, 08 May 2018 10:29:55 -0600
CTL_MainWindow_Title=Autopsy 4.7.0
CTL_MainWindow_Title_No_Project=Autopsy 4.7.0