From 24f515af0d537cd46c213a50a9e085a531883b36 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Tue, 1 May 2018 17:16:35 -0600 Subject: [PATCH 01/36] test stub --- .../IntraCaseCommonFilesSearchTest.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java new file mode 100644 index 0000000000..f9f744f200 --- /dev/null +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java @@ -0,0 +1,93 @@ +/* + * + * Autopsy Forensic Browser + * + * Copyright 2018 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.commonfilessearch; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import static junit.framework.Assert.assertFalse; +import org.apache.commons.io.FileUtils; +import org.netbeans.junit.NbTestCase; +import org.openide.util.Exceptions; +import org.python.icu.impl.Assert; +import org.sleuthkit.autopsy.testutils.CaseUtils; + +/** + * + * @author bsweeney + */ +public class IntraCaseCommonFilesSearchTest extends NbTestCase { + + private static final String CASE_NAME = "IntraCaseCommonFilesSearchTest"; + private static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); + private static final File CASE_DIR = new File(CASE_DIRECTORY_PATH.toString()); + private final Path IMAGE_PATH_1 = Paths.get(this.getDataDir().toString(), "3776", "3776-1.e01.ad1"); + private final Path IMAGE_PATH_2 = Paths.get(this.getDataDir().toString(), "3776", "3776-2.e01.ad1"); + private final Path IMAGE_PATH_3 = Paths.get(this.getDataDir().toString(), "3776", "3776-3.e01.ad1"); + private final Path IMAGE_PATH_4 = Paths.get(this.getDataDir().toString(), "3776", "3776-4.e01.ad1"); + + public IntraCaseCommonFilesSearchTest(String name) { + super(name); + } + + @Override + public void setUp(){ + + CaseUtils.createCase(CASE_DIRECTORY_PATH); + } + + /** + * Add images #1, #2, #3, and #4 to case. Do not ingest. + * Find all matches & all file types. Confirm no matches are found (since there are no hashes to match). + * Find all matches on image #1 & all file types. Confirm no matches. + */ + public void testOne(){ + + } + + + /** + * 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 + */ + public void testTwo(){ + + } + + /** + * Add #1 and #4 to case and ingest. + * Find all matches & all file types. Confirm nothing matches + */ + public void testThree(){ + + } + + @Override + public void tearDown(){ + CaseUtils.closeCase(); + CaseUtils.deleteCaseDir(CASE_DIRECTORY_PATH); + } + +} From 0d166feaa2e4ece5e3883d13adb74ab31ea769d1 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Wed, 2 May 2018 18:08:55 -0600 Subject: [PATCH 02/36] testing --- .../AllDataSourcesCommonFilesAlgorithm.java | 4 +- .../commonfilesearch/CommonFilesMetadata.java | 4 +- .../CommonFilesMetadataBuilder.java | 2 +- .../commonfilesearch/CommonFilesPanel.java | 55 +----- .../commonfilesearch/DataSourceLoader.java | 81 ++++++++ .../commonfilesearch/SingleDataSource.java | 10 +- .../IntraCaseCommonFilesSearchTest.java | 176 +++++++++++++----- 7 files changed, 223 insertions(+), 109 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSourcesCommonFilesAlgorithm.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSourcesCommonFilesAlgorithm.java index 437d4d1885..a1b1af6aa4 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSourcesCommonFilesAlgorithm.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/AllDataSourcesCommonFilesAlgorithm.java @@ -24,7 +24,7 @@ import java.util.Map; /** * Provides logic for selecting common files from all data sources. */ -final class AllDataSourcesCommonFilesAlgorithm extends CommonFilesMetadataBuilder { +final public class AllDataSourcesCommonFilesAlgorithm extends CommonFilesMetadataBuilder { private static final String WHERE_CLAUSE = "%s md5 in (select md5 from tsk_files where (known != 1 OR known IS NULL)%s GROUP BY md5 HAVING COUNT(*) > 1) order by md5"; //NON-NLS @@ -36,7 +36,7 @@ final class AllDataSourcesCommonFilesAlgorithm extends CommonFilesMetadataBuilde * @param filterByMediaMimeType match only on files whose mime types can be broadly categorized as media types * @param filterByDocMimeType match only on files whose mime types can be broadly categorized as document types */ - AllDataSourcesCommonFilesAlgorithm(Map dataSourceIdMap, boolean filterByMediaMimeType, boolean filterByDocMimeType) { + public AllDataSourcesCommonFilesAlgorithm(Map dataSourceIdMap, boolean filterByMediaMimeType, boolean filterByDocMimeType) { super(dataSourceIdMap, filterByMediaMimeType, filterByDocMimeType); } diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetadata.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetadata.java index c7c70676b8..1b405e9224 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetadata.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetadata.java @@ -27,7 +27,7 @@ import java.util.Map; * results. Subclass this to implement different selections of files from the * case. */ -final class CommonFilesMetadata { +final public class CommonFilesMetadata { private final Map metadata; @@ -61,7 +61,7 @@ final class CommonFilesMetadata { * How many distinct file instances exist for this metadata? * @return number of file instances */ - int size() { + public int size() { int count = 0; for (Md5Metadata data : this.metadata.values()) { count += data.size(); diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetadataBuilder.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetadataBuilder.java index 2d279179ee..49525e7343 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetadataBuilder.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetadataBuilder.java @@ -46,7 +46,7 @@ import org.sleuthkit.datamodel.TskCoreException; * This entire thing runs on a background thread where exceptions are handled. */ @SuppressWarnings("PMD.AbstractNaming") -abstract class CommonFilesMetadataBuilder { +public abstract class CommonFilesMetadataBuilder { private final Map dataSourceIdToNameMap; private final boolean filterByMedia; diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java index ad278a4cb5..866a76f061 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java @@ -42,7 +42,6 @@ import org.sleuthkit.autopsy.corecomponents.TableFilterNode; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.autopsy.directorytree.DataResultFilterNode; -import org.sleuthkit.autopsy.directorytree.DirectoryTreeTopComponent; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitCase.CaseDbQuery; import org.sleuthkit.datamodel.TskCoreException; @@ -77,7 +76,7 @@ public final class CommonFilesPanel extends javax.swing.JPanel { initComponents(); this.setupDataSources(); - + this.errorText.setVisible(false); } @@ -98,10 +97,6 @@ public final class CommonFilesPanel extends javax.swing.JPanel { new SwingWorker, Void>() { - private static final String SELECT_DATA_SOURCES_LOGICAL = "select obj_id, name from tsk_files where obj_id in (SELECT obj_id FROM tsk_objects WHERE obj_id in (select obj_id from data_source_info))"; - - private static final String SELECT_DATA_SOURCES_IMAGE = "select obj_id, name from tsk_image_names where obj_id in (SELECT obj_id FROM tsk_objects WHERE obj_id in (select obj_id from data_source_info))"; - private void updateUi() { String[] dataSourcesNames = new String[CommonFilesPanel.this.dataSourceMap.size()]; @@ -132,48 +127,10 @@ public final class CommonFilesPanel extends javax.swing.JPanel { return CommonFilesPanel.this.dataSourceMap.size() >= 2; } - private void loadLogicalSources(SleuthkitCase tskDb, Map dataSouceMap) throws TskCoreException, SQLException { - //try block releases resources - exceptions are handled in done() - try ( - CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_LOGICAL); - ResultSet resultSet = query.getResultSet()) { - while (resultSet.next()) { - Long objectId = resultSet.getLong(1); - String dataSourceName = resultSet.getString(2); - dataSouceMap.put(objectId, dataSourceName); - } - } - } - - private void loadImageSources(SleuthkitCase tskDb, Map dataSouceMap) throws SQLException, TskCoreException { - //try block releases resources - exceptions are handled in done() - try ( - CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_IMAGE); - ResultSet resultSet = query.getResultSet()) { - - while (resultSet.next()) { - Long objectId = resultSet.getLong(1); - String dataSourceName = resultSet.getString(2); - File image = new File(dataSourceName); - String dataSourceNameTrimmed = image.getName(); - dataSouceMap.put(objectId, dataSourceNameTrimmed); - } - } - } - @Override protected Map doInBackground() throws NoCurrentCaseException, TskCoreException, SQLException { - - Map dataSouceMap = new HashMap<>(); - - Case currentCase = Case.getCurrentCaseThrows(); - SleuthkitCase tskDb = currentCase.getSleuthkitCase(); - - loadLogicalSources(tskDb, dataSouceMap); - - loadImageSources(tskDb, dataSouceMap); - - return dataSouceMap; + DataSourceLoader loader = new DataSourceLoader(); + return loader.getDataSourceMap(); } @Override @@ -296,10 +253,10 @@ public final class CommonFilesPanel extends javax.swing.JPanel { TableFilterNode tableFilterWithDescendantsNode = new TableFilterNode(dataResultFilterNode); DataResultViewerTable table = new DataResultViewerTable(); - + Collection viewers = new ArrayList<>(1); viewers.add(table); - + DataResultTopComponent.createInstance(tabTitle, pathText, tableFilterWithDescendantsNode, metadata.size(), viewers); } catch (InterruptedException ex) { @@ -591,7 +548,7 @@ public final class CommonFilesPanel extends javax.swing.JPanel { this.pictureVideoCheckbox.setEnabled(true); this.documentsCheckbox.setEnabled(true); - + this.toggleErrorTextAndSearchBox(); } } diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java new file mode 100644 index 0000000000..117d45bc90 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java @@ -0,0 +1,81 @@ +/* + * + * Autopsy Forensic Browser + * + * Copyright 2018 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.commonfilesearch; + +import java.io.File; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.datamodel.SleuthkitCase; +import org.sleuthkit.datamodel.TskCoreException; + +public class DataSourceLoader { + + private static final String SELECT_DATA_SOURCES_LOGICAL = "select obj_id, name from tsk_files where obj_id in (SELECT obj_id FROM tsk_objects WHERE obj_id in (select obj_id from data_source_info))"; + + private static final String SELECT_DATA_SOURCES_IMAGE = "select obj_id, name from tsk_image_names where obj_id in (SELECT obj_id FROM tsk_objects WHERE obj_id in (select obj_id from data_source_info))"; + + public DataSourceLoader() { + } + + private void loadLogicalSources(SleuthkitCase tskDb, Map dataSouceMap) throws TskCoreException, SQLException { + //try block releases resources - exceptions are handled in done() + try (SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_LOGICAL)) { + ResultSet resultSet = query.getResultSet(); + while (resultSet.next()) { + Long objectId = resultSet.getLong(1); + String dataSourceName = resultSet.getString(2); + dataSouceMap.put(objectId, dataSourceName); + } + } + } + + private void loadImageSources(SleuthkitCase tskDb, Map dataSouceMap) throws SQLException, TskCoreException { + //try block releases resources - exceptions are handled in done() + try ( + SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_IMAGE); + ResultSet resultSet = query.getResultSet()) { + + while (resultSet.next()) { + Long objectId = resultSet.getLong(1); + String dataSourceName = resultSet.getString(2); + File image = new File(dataSourceName); + String dataSourceNameTrimmed = image.getName(); + dataSouceMap.put(objectId, dataSourceNameTrimmed); + } + } + } + + public Map getDataSourceMap() throws NoCurrentCaseException, TskCoreException, SQLException { + Map dataSouceMap = new HashMap<>(); + + Case currentCase = Case.getOpenCase(); + SleuthkitCase tskDb = currentCase.getSleuthkitCase(); + + loadLogicalSources(tskDb, dataSouceMap); + + loadImageSources(tskDb, dataSouceMap); + + return dataSouceMap; + } +} diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java index a3643d3306..5e31754c62 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/SingleDataSource.java @@ -24,7 +24,7 @@ import java.util.Map; /** * Provides logic for selecting common files from a single data source. */ -final class SingleDataSource extends CommonFilesMetadataBuilder { +final public class SingleDataSource extends CommonFilesMetadataBuilder { private static final String WHERE_CLAUSE = "%s md5 in (select md5 from tsk_files where md5 in (select md5 from tsk_files where (known != 1 OR known IS NULL) and data_source_obj_id=%s%s) GROUP BY md5 HAVING COUNT(*) > 1) order by md5"; //NON-NLS private final Long selectedDataSourceId; @@ -37,10 +37,12 @@ final class SingleDataSource extends CommonFilesMetadataBuilder { * @param dataSourceId data source id for which common files must appear at * least once * @param dataSourceIdMap a map of obj_id to datasource name - * @param filterByMediaMimeType match only on files whose mime types can be broadly categorized as media types - * @param filterByDocMimeType match only on files whose mime types can be broadly categorized as document types + * @param filterByMediaMimeType match only on files whose mime types can be + * broadly categorized as media types + * @param filterByDocMimeType match only on files whose mime types can be + * broadly categorized as document types */ - SingleDataSource(Long dataSourceId, Map dataSourceIdMap, boolean filterByMediaMimeType, boolean filterByDocMimeType) { + public SingleDataSource(Long dataSourceId, Map dataSourceIdMap, boolean filterByMediaMimeType, boolean filterByDocMimeType) { super(dataSourceIdMap, filterByMediaMimeType, filterByDocMimeType); this.selectedDataSourceId = dataSourceId; this.dataSourceName = dataSourceIdMap.get(this.selectedDataSourceId); diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java index f9f744f200..4a09369193 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java @@ -19,75 +19,149 @@ */ package org.sleuthkit.autopsy.commonfilessearch; -import java.io.File; -import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; -import static junit.framework.Assert.assertFalse; -import org.apache.commons.io.FileUtils; +import java.sql.SQLException; +import java.util.Map; +import junit.framework.Assert; +import static junit.framework.Assert.*; 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.commonfilesearch.AllDataSourcesCommonFilesAlgorithm; +import org.sleuthkit.autopsy.commonfilesearch.CommonFilesMetadata; +import org.sleuthkit.autopsy.commonfilesearch.CommonFilesMetadataBuilder; +import org.sleuthkit.autopsy.commonfilesearch.DataSourceLoader; +import org.sleuthkit.autopsy.commonfilesearch.SingleDataSource; import org.sleuthkit.autopsy.testutils.CaseUtils; +import org.sleuthkit.autopsy.testutils.IngestUtils; +import org.sleuthkit.datamodel.TskCoreException; /** * * @author bsweeney */ -public class IntraCaseCommonFilesSearchTest extends NbTestCase { - +public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { + private static final String CASE_NAME = "IntraCaseCommonFilesSearchTest"; private static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); - private static final File CASE_DIR = new File(CASE_DIRECTORY_PATH.toString()); - private final Path IMAGE_PATH_1 = Paths.get(this.getDataDir().toString(), "3776", "3776-1.e01.ad1"); - private final Path IMAGE_PATH_2 = Paths.get(this.getDataDir().toString(), "3776", "3776-2.e01.ad1"); - private final Path IMAGE_PATH_3 = Paths.get(this.getDataDir().toString(), "3776", "3776-3.e01.ad1"); - private final Path IMAGE_PATH_4 = Paths.get(this.getDataDir().toString(), "3776", "3776-4.e01.ad1"); - + + private final Path IMAGE_PATH_1 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image1_v1.vhd"); + 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"); + private final Path IMAGE_PATH_4 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image4_v1.vhd"); + + protected DataSourceLoader dataSourceLoader; + public IntraCaseCommonFilesSearchTest(String name) { super(name); } - - @Override - public void setUp(){ - CaseUtils.createCase(CASE_DIRECTORY_PATH); - } - - /** - * Add images #1, #2, #3, and #4 to case. Do not ingest. - * Find all matches & all file types. Confirm no matches are found (since there are no hashes to match). - * Find all matches on image #1 & all file types. Confirm no matches. - */ - public void testOne(){ - - } - - - /** - * 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 - */ - public void testTwo(){ - - } - - /** - * Add #1 and #4 to case and ingest. - * Find all matches & all file types. Confirm nothing matches - */ - public void testThree(){ - - } - @Override - public void tearDown(){ + public void setUp() { + + CaseUtils.createCase(CASE_DIRECTORY_PATH); + + IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_1); + IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_2); + IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_3); + IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_4); + + this.dataSourceLoader = new DataSourceLoader(); + } + + @Override + public void tearDown() { CaseUtils.closeCase(); CaseUtils.deleteCaseDir(CASE_DIRECTORY_PATH); } - + + public class UningestedCases extends IntraCaseCommonFilesSearchTest { + + public UningestedCases(String name) { + super(name); + } + + /** + * Add images #1, #2, #3, and #4 to case. Do not ingest. Find all + * matches & all file types. Confirm no matches are found (since there + * are no hashes to match). Find all matches on image #1 & all file + * types. Confirm no matches. + */ + public void testOne() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + + CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, false, false); + CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); + + int resultCount = metadata.size(); + assertEquals(resultCount, 0); + + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { + fail(ex.getMessage()); + } + } + + public void testTwo() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + Long first = new Long(1); + + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); + CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); + + int resultCount = metadata.size(); + assertEquals(resultCount, 0); + + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { + fail(ex.getMessage()); + } + } + } + + public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { + + public IngestedWithHashAlgOnly(String name) { + super(name); + } + + /** + * 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 + */ + public void testTwo() { + + } + + } + + public class NoMatches extends IntraCaseCommonFilesSearchTest { + + public NoMatches(String name) { + super(name); + } + + @Override + public void setUp() { + + CaseUtils.createCase(CASE_DIRECTORY_PATH); + IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_1); + IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_4); + } + + /** + * Add #1 and #4 to case and ingest. Find all matches & all file types. + * Confirm nothing matches + */ + public void testThree() { + + } + } } From 8517a877c342798fb4472fb7e78171917735cb90 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 7 May 2018 17:16:11 -0600 Subject: [PATCH 03/36] functional testing - wip --- .../commonfilesearch/CommonFilesMetadata.java | 2 +- .../IngestedWithHashAlgOnly.java | 178 ++++++++++++++++++ .../IntraCaseCommonFilesSearchTest.java | 105 +---------- .../autopsy/commonfilessearch/NoMatches.java | 56 ++++++ .../commonfilessearch/UningestedCases.java | 97 ++++++++++ 5 files changed, 335 insertions(+), 103 deletions(-) create mode 100644 Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java create mode 100644 Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java create mode 100644 Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetadata.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetadata.java index 1b405e9224..2437d28cf4 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetadata.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesMetadata.java @@ -53,7 +53,7 @@ final public class CommonFilesMetadata { return this.metadata.get(md5); } - Map getMetadata() { + public Map getMetadata() { return Collections.unmodifiableMap(this.metadata); } diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java new file mode 100644 index 0000000000..1358f50d8a --- /dev/null +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java @@ -0,0 +1,178 @@ +/* + * + * Autopsy Forensic Browser + * + * Copyright 2018 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +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; +import org.python.icu.impl.Assert; +import org.sleuthkit.autopsy.casemodule.Case; +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; +import org.sleuthkit.autopsy.ingest.IngestModuleTemplate; +import org.sleuthkit.autopsy.modules.hashdatabase.HashLookupModuleFactory; +import org.sleuthkit.autopsy.testutils.IngestUtils; +import org.sleuthkit.datamodel.AbstractFile; +import org.sleuthkit.datamodel.TskCoreException; + +public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { + + public static Test suite() { + NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(IngestedWithHashAlgOnly.class). + clusters(".*"). + enableModules(".*"); + return conf.suite(); + } + + public IngestedWithHashAlgOnly(String name) { + super(name); + } + + @Override + public void setUp() { + super.setUp(); + + IngestModuleTemplate hashLookupTemplate = IngestUtils.getIngestModuleTemplate(new HashLookupModuleFactory()); + + ArrayList templates = new ArrayList<>(); + templates.add(hashLookupTemplate); + + IngestJobSettings ingestJobSettings = new IngestJobSettings(IngestedWithHashAlgOnly.class.getCanonicalName(), IngestType.FILES_ONLY, templates); + + try { + IngestUtils.runIngestJob(Case.getOpenCase().getDataSources(), ingestJobSettings); + } catch (NoCurrentCaseException | TskCoreException ex) { + Exceptions.printStackTrace(ex); + Assert.fail(ex); + } + } + + /** + * 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 + */ + public void testOne() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + + CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, false, false); + CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); + + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + + List files = getFiles(objectIdToDataSource.keySet()); + + + + } catch (NoCurrentCaseException ex) { + Exceptions.printStackTrace(ex); + } catch (TskCoreException ex) { + Exceptions.printStackTrace(ex); + } catch (SQLException ex) { + Exceptions.printStackTrace(ex); + } + } + + private boolean fileExists(List 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 files, String name, String dataSource){ + return fileExists(files, name, dataSource, 1); + } + + public void testTwo() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + Long first = new Long(1); + + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); + CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); + + + + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { + Exceptions.printStackTrace(ex); + Assert.fail(ex); + } + } + + private Map mapFileInstancesToDataSources(CommonFilesMetadata metadata) { + Map instanceIdToDataSource = new HashMap<>(); + + for(Entry entry : metadata.getMetadata().entrySet()){ + for (FileInstanceMetadata md : entry.getValue().getMetadata()){ + instanceIdToDataSource.put(md.getObjectId(), md.getDataSourceName()); + } + } + + return instanceIdToDataSource; + } + + private List getFiles(Set keySet) { + List 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); + } + } + + return files; + } +} diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java index 4a09369193..25a322a1af 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java @@ -21,22 +21,11 @@ package org.sleuthkit.autopsy.commonfilessearch; import java.nio.file.Path; import java.nio.file.Paths; -import java.sql.SQLException; -import java.util.Map; -import junit.framework.Assert; -import static junit.framework.Assert.*; import org.netbeans.junit.NbTestCase; -import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.ImageDSProcessor; -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.DataSourceLoader; -import org.sleuthkit.autopsy.commonfilesearch.SingleDataSource; import org.sleuthkit.autopsy.testutils.CaseUtils; import org.sleuthkit.autopsy.testutils.IngestUtils; -import org.sleuthkit.datamodel.TskCoreException; /** * @@ -45,12 +34,12 @@ import org.sleuthkit.datamodel.TskCoreException; public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { private static final String CASE_NAME = "IntraCaseCommonFilesSearchTest"; - private static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); + static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); - private final Path IMAGE_PATH_1 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image1_v1.vhd"); + protected final Path IMAGE_PATH_1 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image1_v1.vhd"); 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"); - private final Path IMAGE_PATH_4 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image4_v1.vhd"); + protected final Path IMAGE_PATH_4 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image4_v1.vhd"); protected DataSourceLoader dataSourceLoader; @@ -76,92 +65,4 @@ public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { CaseUtils.closeCase(); CaseUtils.deleteCaseDir(CASE_DIRECTORY_PATH); } - - public class UningestedCases extends IntraCaseCommonFilesSearchTest { - - public UningestedCases(String name) { - super(name); - } - - /** - * Add images #1, #2, #3, and #4 to case. Do not ingest. Find all - * matches & all file types. Confirm no matches are found (since there - * are no hashes to match). Find all matches on image #1 & all file - * types. Confirm no matches. - */ - public void testOne() { - try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); - - CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, false, false); - CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); - - int resultCount = metadata.size(); - assertEquals(resultCount, 0); - - } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { - fail(ex.getMessage()); - } - } - - public void testTwo() { - try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = new Long(1); - - CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); - CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); - - int resultCount = metadata.size(); - assertEquals(resultCount, 0); - - } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { - fail(ex.getMessage()); - } - } - } - - public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { - - public IngestedWithHashAlgOnly(String name) { - super(name); - } - - /** - * 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 - */ - public void testTwo() { - - } - - } - - public class NoMatches extends IntraCaseCommonFilesSearchTest { - - public NoMatches(String name) { - super(name); - } - - @Override - public void setUp() { - - CaseUtils.createCase(CASE_DIRECTORY_PATH); - IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_1); - IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_4); - } - - /** - * Add #1 and #4 to case and ingest. Find all matches & all file types. - * Confirm nothing matches - */ - public void testThree() { - - } - } } diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java new file mode 100644 index 0000000000..b8d86d9956 --- /dev/null +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java @@ -0,0 +1,56 @@ +/* + * + * Autopsy Forensic Browser + * + * Copyright 2018 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.commonfilessearch; + +import junit.framework.Test; +import org.netbeans.junit.NbModuleSuite; +import org.sleuthkit.autopsy.casemodule.ImageDSProcessor; +import org.sleuthkit.autopsy.testutils.CaseUtils; +import org.sleuthkit.autopsy.testutils.IngestUtils; + +public class NoMatches extends IntraCaseCommonFilesSearchTest { + + public static Test suite() { + NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(NoMatches.class). + clusters(".*"). + enableModules(".*"); + return conf.suite(); + } + + public NoMatches(String name) { + super(name); + } + + @Override + public void setUp() { + + CaseUtils.createCase(CASE_DIRECTORY_PATH); + IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_1); + IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_4); + } + + /** + * Add #1 and #4 to case and ingest. Find all matches & all file types. + * Confirm nothing matches + */ + public void testThree() { + + } +} diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java new file mode 100644 index 0000000000..38e32fd981 --- /dev/null +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java @@ -0,0 +1,97 @@ +/* + * + * Autopsy Forensic Browser + * + * Copyright 2018 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.commonfilessearch; + +import java.sql.SQLException; +import java.util.Map; +import static junit.framework.Assert.assertEquals; +import junit.framework.Test; +import org.netbeans.junit.NbModuleSuite; +import org.openide.util.Exceptions; +import org.python.icu.impl.Assert; +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.SingleDataSource; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * Test that cases which are created but have not run any ingest modules turn up + * no results. + * + * Setup: + * + * Add images #1, #2, #3, and #4 to case. Do not ingest. + * + */ +public class UningestedCases extends IntraCaseCommonFilesSearchTest { + + public static Test suite() { + NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(UningestedCases.class). + clusters(".*"). + enableModules(".*"); + return conf.suite(); + } + + public UningestedCases(String name) { + super(name); + } + + /** + * Find all matches & all file types. Confirm no matches are found (since + * there are no hashes to match). + */ + public void testOne() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + + CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, false, false); + CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); + + int resultCount = metadata.size(); + assertEquals(resultCount, 0); + + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { + Exceptions.printStackTrace(ex); + Assert.fail(ex); + } + } + + /** + * Find all matches on image #1 & all file types. Confirm no matches. + */ + public void testTwo() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + Long first = new Long(1); + + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); + CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); + + int resultCount = metadata.size(); + assertEquals(resultCount, 0); + + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { + Exceptions.printStackTrace(ex); + Assert.fail(ex); + } + } +} From 226acf8c3b1f6e5c0d36e44a7bcdf21680e50647 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Wed, 2 May 2018 18:08:55 -0600 Subject: [PATCH 04/36] testing --- .../IntraCaseCommonFilesSearchTest.java | 105 +++++++++++++++++- 1 file changed, 102 insertions(+), 3 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java index 25a322a1af..8cd069b4ef 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java @@ -21,11 +21,22 @@ package org.sleuthkit.autopsy.commonfilessearch; import java.nio.file.Path; import java.nio.file.Paths; +import java.sql.SQLException; +import java.util.Map; +import junit.framework.Assert; +import static junit.framework.Assert.*; import org.netbeans.junit.NbTestCase; +import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.ImageDSProcessor; +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.DataSourceLoader; +import org.sleuthkit.autopsy.commonfilesearch.SingleDataSource; import org.sleuthkit.autopsy.testutils.CaseUtils; import org.sleuthkit.autopsy.testutils.IngestUtils; +import org.sleuthkit.datamodel.TskCoreException; /** * @@ -34,12 +45,12 @@ import org.sleuthkit.autopsy.testutils.IngestUtils; public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { private static final String CASE_NAME = "IntraCaseCommonFilesSearchTest"; - static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); + private static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); - protected final Path IMAGE_PATH_1 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image1_v1.vhd"); + private final Path IMAGE_PATH_1 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image1_v1.vhd"); 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"); + private final Path IMAGE_PATH_4 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image4_v1.vhd"); protected DataSourceLoader dataSourceLoader; @@ -65,4 +76,92 @@ public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { CaseUtils.closeCase(); CaseUtils.deleteCaseDir(CASE_DIRECTORY_PATH); } + + public class UningestedCases extends IntraCaseCommonFilesSearchTest { + + public UningestedCases(String name) { + super(name); + } + + /** + * Add images #1, #2, #3, and #4 to case. Do not ingest. Find all + * matches & all file types. Confirm no matches are found (since there + * are no hashes to match). Find all matches on image #1 & all file + * types. Confirm no matches. + */ + public void testOne() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + + CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, false, false); + CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); + + int resultCount = metadata.size(); + assertEquals(resultCount, 0); + + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { + fail(ex.getMessage()); + } + } + + public void testTwo() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + Long first = new Long(1); + + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); + CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); + + int resultCount = metadata.size(); + assertEquals(resultCount, 0); + + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { + fail(ex.getMessage()); + } + } + } + + public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { + + public IngestedWithHashAlgOnly(String name) { + super(name); + } + + /** + * 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 + */ + public void testTwo() { + + } + + } + + public class NoMatches extends IntraCaseCommonFilesSearchTest { + + public NoMatches(String name) { + super(name); + } + + @Override + public void setUp() { + + CaseUtils.createCase(CASE_DIRECTORY_PATH); + IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_1); + IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_4); + } + + /** + * Add #1 and #4 to case and ingest. Find all matches & all file types. + * Confirm nothing matches + */ + public void testThree() { + + } + } } From 25b6ac9de98ccf89e5ecba19cb34a1180856a17f Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 7 May 2018 17:16:11 -0600 Subject: [PATCH 05/36] functional testing - wip --- .../IntraCaseCommonFilesSearchTest.java | 105 +----------------- 1 file changed, 3 insertions(+), 102 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java index 8cd069b4ef..25a322a1af 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java @@ -21,22 +21,11 @@ package org.sleuthkit.autopsy.commonfilessearch; import java.nio.file.Path; import java.nio.file.Paths; -import java.sql.SQLException; -import java.util.Map; -import junit.framework.Assert; -import static junit.framework.Assert.*; import org.netbeans.junit.NbTestCase; -import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.ImageDSProcessor; -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.DataSourceLoader; -import org.sleuthkit.autopsy.commonfilesearch.SingleDataSource; import org.sleuthkit.autopsy.testutils.CaseUtils; import org.sleuthkit.autopsy.testutils.IngestUtils; -import org.sleuthkit.datamodel.TskCoreException; /** * @@ -45,12 +34,12 @@ import org.sleuthkit.datamodel.TskCoreException; public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { private static final String CASE_NAME = "IntraCaseCommonFilesSearchTest"; - private static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); + static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); - private final Path IMAGE_PATH_1 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image1_v1.vhd"); + protected final Path IMAGE_PATH_1 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image1_v1.vhd"); 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"); - private final Path IMAGE_PATH_4 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image4_v1.vhd"); + protected final Path IMAGE_PATH_4 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image4_v1.vhd"); protected DataSourceLoader dataSourceLoader; @@ -76,92 +65,4 @@ public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { CaseUtils.closeCase(); CaseUtils.deleteCaseDir(CASE_DIRECTORY_PATH); } - - public class UningestedCases extends IntraCaseCommonFilesSearchTest { - - public UningestedCases(String name) { - super(name); - } - - /** - * Add images #1, #2, #3, and #4 to case. Do not ingest. Find all - * matches & all file types. Confirm no matches are found (since there - * are no hashes to match). Find all matches on image #1 & all file - * types. Confirm no matches. - */ - public void testOne() { - try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); - - CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, false, false); - CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); - - int resultCount = metadata.size(); - assertEquals(resultCount, 0); - - } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { - fail(ex.getMessage()); - } - } - - public void testTwo() { - try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = new Long(1); - - CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); - CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); - - int resultCount = metadata.size(); - assertEquals(resultCount, 0); - - } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { - fail(ex.getMessage()); - } - } - } - - public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { - - public IngestedWithHashAlgOnly(String name) { - super(name); - } - - /** - * 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 - */ - public void testTwo() { - - } - - } - - public class NoMatches extends IntraCaseCommonFilesSearchTest { - - public NoMatches(String name) { - super(name); - } - - @Override - public void setUp() { - - CaseUtils.createCase(CASE_DIRECTORY_PATH); - IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_1); - IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_4); - } - - /** - * Add #1 and #4 to case and ingest. Find all matches & all file types. - * Confirm nothing matches - */ - public void testThree() { - - } - } } From 4a0ae67b0516144cd831cee30fdcdaf69a045ea9 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Tue, 8 May 2018 15:42:46 -0600 Subject: [PATCH 06/36] more tests --- .../commonfilesearch/DataSourceLoader.java | 2 +- .../IngestedWithHashAlgOnly.java | 225 +++++++++++++----- .../IntraCaseCommonFilesSearchTest.java | 102 +++++++- .../netbeans/core/startup/Bundle.properties | 4 +- .../core/windows/view/ui/Bundle.properties | 6 +- 5 files changed, 268 insertions(+), 71 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java index 117d45bc90..8bafeef885 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java @@ -69,7 +69,7 @@ public class DataSourceLoader { public Map getDataSourceMap() throws NoCurrentCaseException, TskCoreException, SQLException { Map dataSouceMap = new HashMap<>(); - Case currentCase = Case.getOpenCase(); + Case currentCase = Case.getCurrentCaseThrows(); SleuthkitCase tskDb = currentCase.getSleuthkitCase(); loadLogicalSources(tskDb, dataSouceMap); diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java index 1358f50d8a..2f0d52245f 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java @@ -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 objectIdToDataSource = mapFileInstancesToDataSources(metadata); - + List 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 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 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 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 objectIdToDataSource = mapFileInstancesToDataSources(metadata); + + List 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 mapFileInstancesToDataSources(CommonFilesMetadata metadata) { - Map instanceIdToDataSource = new HashMap<>(); - - for(Entry 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 dataSources = this.dataSourceLoader.getDataSourceMap(); + Long second = new Long(2); + + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(second, dataSources, false, false); + CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); + + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + + List 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 getFiles(Set keySet) { - List 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 dataSources = this.dataSourceLoader.getDataSourceMap(); + Long last = new Long(4); + + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(last, dataSources, false, false); + CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); + + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + + List 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 dataSources = this.dataSourceLoader.getDataSourceMap(); + Long third = new Long(3); + + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(third, dataSources, false, false); + CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); + + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + + List 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; } } diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java index 25a322a1af..1933597089 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java @@ -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 files, Map 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 files, Map objectIdToDataSource, String name, String dataSource) { + return fileExists(files, objectIdToDataSource, name, dataSource, 1); + } + + protected Map mapFileInstancesToDataSources(CommonFilesMetadata metadata) { + Map instanceIdToDataSource = new HashMap<>(); + + for (Map.Entry entry : metadata.getMetadata().entrySet()) { + for (FileInstanceMetadata md : entry.getValue().getMetadata()) { + instanceIdToDataSource.put(md.getObjectId(), md.getDataSourceName()); + } + } + + return instanceIdToDataSource; + } + + protected List getFiles(Set keySet) { + List 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; + } } diff --git a/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties b/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties index b1adb5d40b..9a9a904cc5 100644 --- a/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties +++ b/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties @@ -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 diff --git a/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties b/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties index 6cb9d4bdea..db3cd01af5 100644 --- a/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties +++ b/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties @@ -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 From d6143993c5cce4f8894af9817b3e573868e9dc22 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Wed, 9 May 2018 10:35:39 -0600 Subject: [PATCH 07/36] more test cases, added a method for getting unique case name --- .../IngestedWithHashAlgOnly.java | 232 ++++++++++++++++-- .../IntraCaseCommonFilesSearchTest.java | 5 + .../autopsy/commonfilessearch/NoMatches.java | 7 +- 3 files changed, 223 insertions(+), 21 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java index 2f0d52245f..aa9ecedb65 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java @@ -42,7 +42,7 @@ import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.TskCoreException; /** - * Add #1, #2, #3, and #4 to case and ingest with hash algorithm. + * Add set 1, set 2, set 3, and set 4 to case and ingest with hash algorithm. */ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { @@ -80,7 +80,7 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { * Find all matches & all file types. Confirm file.jpg is found on all three and * file.docx is found on two. */ - public void testOne() { + public void testOneA() { try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); @@ -94,9 +94,100 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { 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, IMG, SET4, 0)); + + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 1)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 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 ex) { + Exceptions.printStackTrace(ex); + } catch (TskCoreException ex) { + Exceptions.printStackTrace(ex); + } catch (SQLException ex) { + Exceptions.printStackTrace(ex); + } + } + + /** + * Find all matches & only image types. Confirm file.jpg is found on all three. + */ + public void testOneB() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + + CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, true, false); + CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); + + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + + List 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, IMG, SET4, 0)); + + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 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 ex) { + Exceptions.printStackTrace(ex); + } catch (TskCoreException ex) { + Exceptions.printStackTrace(ex); + } catch (SQLException ex) { + Exceptions.printStackTrace(ex); + } + } + + /** + * Find all matches & only image types. Confirm file.jpg is found on all three. + */ + public void testOneC() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + + CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, false, true); + CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); + + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + + List 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, IMG, SET4, 0)); assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 3)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 1)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); assertTrue(fileExists(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(fileExists(files, objectIdToDataSource, PDF, SET2, 0)); @@ -118,14 +209,12 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { } } - - /** - * Find matches on ‘#1’ & all file types. Confirm + * Find matches on set 1 & all file types. Confirm * same results. * */ - public void testTwo() { + public void testTwoA() { try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); Long first = new Long(1); @@ -137,12 +226,15 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { List 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, IMG, SET1, 0)); + assertTrue(fileExists(files, objectIdToDataSource, IMG, SET2, 0)); + assertTrue(fileExists(files, objectIdToDataSource, IMG, SET3, 0)); + assertTrue(fileExists(files, objectIdToDataSource, IMG, SET4, 0)); assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 3)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 1)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); assertTrue(fileExists(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(fileExists(files, objectIdToDataSource, PDF, SET2, 0)); @@ -161,7 +253,93 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { } /** - * Find matches on ‘#2 & all file types: Confirm file.jpg. + * Find matches on set 1 & only media types. Confirm + * same results. + * + */ + public void testTwoB() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + Long first = new Long(1); + + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, true, false); + CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); + + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + + List 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, IMG, SET4, 0)); + + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 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 set 1 & all file types. Confirm + * same results. + * + */ + public void testTwoC() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + Long first = new Long(1); + + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, true); + CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); + + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + + List 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, IMG, SET4, 0)); + + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 1)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 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 set 2 & all file types: Confirm file.jpg. * */ public void testThree(){ @@ -179,9 +357,12 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { 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, IMG, SET4, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); assertTrue(fileExists(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(fileExists(files, objectIdToDataSource, PDF, SET2, 0)); @@ -200,7 +381,7 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { } /** - * Find matches on #4 & all file types: Confirm nothing is found. + * Find matches on set 4 & all file types: Confirm nothing is found. */ public void testFour(){ try { @@ -216,10 +397,13 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { 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, IMG, SET3, 0)); + assertTrue(fileExists(files, objectIdToDataSource, IMG, SET4, 0)); assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0)); assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); assertTrue(fileExists(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(fileExists(files, objectIdToDataSource, PDF, SET2, 0)); @@ -238,7 +422,7 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { } /** - * Find matches on ‘#3’ & all file types: Confirm file.jpg and file.docx. + * Find matches on set 3 & all file types: Confirm file.jpg and file.docx. */ public void testFive(){ try { @@ -254,10 +438,13 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { 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, IMG, SET3, 1)); + assertTrue(fileExists(files, objectIdToDataSource, IMG, SET4, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); assertTrue(fileExists(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(fileExists(files, objectIdToDataSource, PDF, SET2, 0)); @@ -274,4 +461,9 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { Assert.fail(ex); } } + + @Override + protected String getCaseName() { + return "IngestedWithHashAlgOnlyTests"; + } } diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java index 1933597089..b42bb80b16 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java @@ -111,6 +111,11 @@ public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { CaseUtils.closeCase(); CaseUtils.deleteCaseDir(CASE_DIRECTORY_PATH); } + + /** + * Override this to provide a string for subclasses to use in CaseUtils.createCase(...) + */ + protected abstract String getCaseName(); protected boolean fileExists(List files, Map objectIdToDataSource, String name, String dataSource, int count) { diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java index b8d86d9956..73b0ee1f23 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java @@ -41,7 +41,7 @@ public class NoMatches extends IntraCaseCommonFilesSearchTest { @Override public void setUp() { - CaseUtils.createCase(CASE_DIRECTORY_PATH); + CaseUtils.createCase(CASE_DIRECTORY_PATH, this.getCaseName()); IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_1); IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_4); } @@ -53,4 +53,9 @@ public class NoMatches extends IntraCaseCommonFilesSearchTest { public void testThree() { } + + @Override + protected String getCaseName() { + return "NoMatchesTest"; + } } From 2c271dbc9ce552f93528ea1230c7d78a18a3c415 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Wed, 9 May 2018 10:50:44 -0600 Subject: [PATCH 08/36] comments / stubs --- .../org/sleuthkit/autopsy/commonfilessearch/NoMatches.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java index 73b0ee1f23..5b3c15078a 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java @@ -25,6 +25,9 @@ import org.sleuthkit.autopsy.casemodule.ImageDSProcessor; import org.sleuthkit.autopsy.testutils.CaseUtils; import org.sleuthkit.autopsy.testutils.IngestUtils; +/** + * Add set 1 and set 4 to case and ingest. + */ public class NoMatches extends IntraCaseCommonFilesSearchTest { public static Test suite() { @@ -47,10 +50,10 @@ public class NoMatches extends IntraCaseCommonFilesSearchTest { } /** - * Add #1 and #4 to case and ingest. Find all matches & all file types. + * Find all matches & all file types. * Confirm nothing matches */ - public void testThree() { + public void testOne() { } From 763eb661dbd7250d30fb69a09ad7900d48b4ed67 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Thu, 10 May 2018 15:51:03 -0600 Subject: [PATCH 09/36] tests added, data download issue dealt with, case closed NPE dealt with tentatively --- Core/build.xml | 4 ++ .../autopsy/casemodule/services/Services.java | 4 +- .../hashdatabase/HashLookupModuleFactory.java | 2 - .../IngestedWithHashAlgOnly.java | 5 +- .../IngestedWithNoFileTypes.java | 70 +++++++++++++++++++ .../IntraCaseCommonFilesSearchTest.java | 20 +++--- .../autopsy/commonfilessearch/NoMatches.java | 64 ----------------- .../commonfilessearch/UningestedCases.java | 7 +- .../autopsy/testutils/IngestUtils.java | 1 - 9 files changed, 98 insertions(+), 79 deletions(-) create mode 100644 Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java delete mode 100644 Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java diff --git a/Core/build.xml b/Core/build.xml index 401d0dfb6b..2a83db79a5 100644 --- a/Core/build.xml +++ b/Core/build.xml @@ -88,6 +88,10 @@ + + + + diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java index c38bc12144..11dcb4ed28 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java @@ -105,7 +105,9 @@ public class Services implements Closeable { @Override public void close() throws IOException { for (Closeable service : services) { - service.close(); + if(service != null){ + service.close(); + } } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java index 257f90ad2f..068c52cf5e 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java @@ -18,8 +18,6 @@ */ package org.sleuthkit.autopsy.modules.hashdatabase; -import java.util.ArrayList; -import java.util.List; import org.openide.util.NbBundle; import org.openide.util.lookup.ServiceProvider; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java index aa9ecedb65..9a1135487c 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java @@ -36,6 +36,7 @@ import org.sleuthkit.autopsy.commonfilesearch.SingleDataSource; import org.sleuthkit.autopsy.ingest.IngestJobSettings; import org.sleuthkit.autopsy.ingest.IngestJobSettings.IngestType; import org.sleuthkit.autopsy.ingest.IngestModuleTemplate; +import org.sleuthkit.autopsy.modules.filetypeid.FileTypeIdModuleFactory; import org.sleuthkit.autopsy.modules.hashdatabase.HashLookupModuleFactory; import org.sleuthkit.autopsy.testutils.IngestUtils; import org.sleuthkit.datamodel.AbstractFile; @@ -62,9 +63,11 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { super.setUp(); IngestModuleTemplate hashLookupTemplate = IngestUtils.getIngestModuleTemplate(new HashLookupModuleFactory()); - + IngestModuleTemplate mimeTypeLookupTemplate = IngestUtils.getIngestModuleTemplate(new FileTypeIdModuleFactory()); + ArrayList templates = new ArrayList<>(); templates.add(hashLookupTemplate); + templates.add(mimeTypeLookupTemplate); IngestJobSettings ingestJobSettings = new IngestJobSettings(IngestedWithHashAlgOnly.class.getCanonicalName(), IngestType.FILES_ONLY, templates); diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java new file mode 100644 index 0000000000..2181ebcca8 --- /dev/null +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java @@ -0,0 +1,70 @@ +/* + * + * Autopsy Forensic Browser + * + * Copyright 2018 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.commonfilessearch; + +import java.util.ArrayList; +import org.openide.util.Exceptions; +import org.python.icu.impl.Assert; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.ingest.IngestJobSettings; +import org.sleuthkit.autopsy.ingest.IngestModuleTemplate; +import org.sleuthkit.autopsy.modules.hashdatabase.HashLookupModuleFactory; +import org.sleuthkit.autopsy.testutils.IngestUtils; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * Ingested w/o mime type info added to DB. + * + * Setup: + * + * Add images set 1, set 2, set 3, and set 4 to case. Do not run mime type module. + */ +public class IngestedWithNoFileTypes extends IntraCaseCommonFilesSearchTest { + + public IngestedWithNoFileTypes(String name) { + super(name); + } + + @Override + public void setUp() { + super.setUp(); + + IngestModuleTemplate hashLookupTemplate = IngestUtils.getIngestModuleTemplate(new HashLookupModuleFactory()); + + ArrayList templates = new ArrayList<>(); + templates.add(hashLookupTemplate); + + IngestJobSettings ingestJobSettings = new IngestJobSettings(IngestedWithHashAlgOnly.class.getCanonicalName(), IngestJobSettings.IngestType.FILES_ONLY, templates); + + try { + IngestUtils.runIngestJob(Case.getCurrentCaseThrows().getDataSources(), ingestJobSettings); + } catch (NoCurrentCaseException | TskCoreException ex) { + Exceptions.printStackTrace(ex); + Assert.fail(ex); + } + } + + @Override + protected String getCaseName() { + return "IngestedWithNoFileTypes"; + } + +} diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java index b42bb80b16..83fbc05daa 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java @@ -72,10 +72,10 @@ public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { private static final String CASE_NAME = "IntraCaseCommonFilesSearchTest"; static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); - protected final Path IMAGE_PATH_1 = Paths.get(this.getDataDir().toString(), "3776", "commonfiles_image1_v1.vhd"); - 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 Path IMAGE_PATH_1 = Paths.get(this.getDataDir().toString(), "commonfiles_image1_v1.vhd"); + private final Path IMAGE_PATH_2 = Paths.get(this.getDataDir().toString(), "commonfiles_image2_v1.vhd"); + private final Path IMAGE_PATH_3 = Paths.get(this.getDataDir().toString(), "commonfiles_image3_v1.vhd"); + protected final Path IMAGE_PATH_4 = Paths.get(this.getDataDir().toString(), "commonfiles_image4_v1.vhd"); protected final String IMG = "IMG_6175.jpg"; protected final String DOC = "BasicStyleGuide.doc"; @@ -96,12 +96,14 @@ public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { @Override public void setUp() { - CaseUtils.createCase(CASE_DIRECTORY_PATH, "IntraCaseCommonFilesSearchTests"); + CaseUtils.createCase(CASE_DIRECTORY_PATH, this.getCaseName()); + + final ImageDSProcessor imageDSProcessor = new ImageDSProcessor(); - IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_1); - IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_2); - IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_3); - IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_4); + IngestUtils.addDataSource(imageDSProcessor, IMAGE_PATH_1); + IngestUtils.addDataSource(imageDSProcessor, IMAGE_PATH_2); + IngestUtils.addDataSource(imageDSProcessor, IMAGE_PATH_3); + IngestUtils.addDataSource(imageDSProcessor, IMAGE_PATH_4); this.dataSourceLoader = new DataSourceLoader(); } diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java deleted file mode 100644 index 5b3c15078a..0000000000 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/NoMatches.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * - * Autopsy Forensic Browser - * - * Copyright 2018 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.commonfilessearch; - -import junit.framework.Test; -import org.netbeans.junit.NbModuleSuite; -import org.sleuthkit.autopsy.casemodule.ImageDSProcessor; -import org.sleuthkit.autopsy.testutils.CaseUtils; -import org.sleuthkit.autopsy.testutils.IngestUtils; - -/** - * Add set 1 and set 4 to case and ingest. - */ -public class NoMatches extends IntraCaseCommonFilesSearchTest { - - public static Test suite() { - NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(NoMatches.class). - clusters(".*"). - enableModules(".*"); - return conf.suite(); - } - - public NoMatches(String name) { - super(name); - } - - @Override - public void setUp() { - - CaseUtils.createCase(CASE_DIRECTORY_PATH, this.getCaseName()); - IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_1); - IngestUtils.addDataSource(new ImageDSProcessor(), IMAGE_PATH_4); - } - - /** - * Find all matches & all file types. - * Confirm nothing matches - */ - public void testOne() { - - } - - @Override - protected String getCaseName() { - return "NoMatchesTest"; - } -} diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java index 38e32fd981..204d69f581 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java @@ -39,7 +39,7 @@ import org.sleuthkit.datamodel.TskCoreException; * * Setup: * - * Add images #1, #2, #3, and #4 to case. Do not ingest. + * Add images set 1, set 2, set 3, and set 4 to case. Do not ingest. * */ public class UningestedCases extends IntraCaseCommonFilesSearchTest { @@ -94,4 +94,9 @@ public class UningestedCases extends IntraCaseCommonFilesSearchTest { Assert.fail(ex); } } + + @Override + protected String getCaseName() { + return "UningestedCasesTests"; + } } diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/testutils/IngestUtils.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/testutils/IngestUtils.java index fba62cdbde..be7171a9f2 100755 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/testutils/IngestUtils.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/testutils/IngestUtils.java @@ -58,7 +58,6 @@ public final class IngestUtils { } catch (AutoIngestDataSourceProcessor.AutoIngestDataSourceProcessorException | InterruptedException ex) { Exceptions.printStackTrace(ex); Assert.fail(ex); - } } From 3f0279ed72198b9bf22b5f565d84f630f79e57b3 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Fri, 11 May 2018 08:45:42 -0600 Subject: [PATCH 10/36] added some helper functions and corrected some test cases --- .../IngestedWithHashAlgOnly.java | 22 +++++++++---------- .../IntraCaseCommonFilesSearchTest.java | 14 ++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java index 9a1135487c..76a1e0b7f7 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java @@ -220,7 +220,7 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { public void testTwoA() { try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = new Long(1); + Long first = this.getDataSourceIdByIndex(0, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -229,9 +229,9 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { List 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, IMG, SET1, 2)); + assertTrue(fileExists(files, objectIdToDataSource, IMG, SET2, 1)); + assertTrue(fileExists(files, objectIdToDataSource, IMG, SET3, 1)); assertTrue(fileExists(files, objectIdToDataSource, IMG, SET4, 0)); assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); @@ -263,7 +263,7 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { public void testTwoB() { try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = new Long(1); + Long first = this.getDataSourceIdByIndex(0, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, true, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -306,7 +306,7 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { public void testTwoC() { try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = new Long(1); + Long first = this.getDataSourceIdByIndex(0, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, true); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -348,7 +348,7 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { public void testThree(){ try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long second = new Long(2); + Long second = this.getDataSourceIdByIndex(1, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(second, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -389,7 +389,7 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { public void testFour(){ try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long last = new Long(4); + Long last = this.getDataSourceIdByIndex(3, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(last, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -430,7 +430,7 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { public void testFive(){ try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long third = new Long(3); + Long third = this.getDataSourceIdByIndex(2, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(third, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -445,8 +445,8 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { assertTrue(fileExists(files, objectIdToDataSource, IMG, SET4, 0)); assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 1)); assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); assertTrue(fileExists(files, objectIdToDataSource, PDF, SET1, 0)); diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java index 83fbc05daa..865d886ef3 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java @@ -25,6 +25,7 @@ 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 org.netbeans.junit.NbTestCase; import org.openide.util.Exceptions; @@ -170,4 +171,17 @@ public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { return files; } + + protected Long getDataSourceIdByIndex(int index, Map dataSources){ + + int current = 0; + for(Entry dataSource : dataSources.entrySet()){ + if(current == index){ + return dataSource.getKey(); + } + current++; + } + final int size = dataSources.size() - 1; + throw new IndexOutOfBoundsException("The value given for index was unreasonable. Should be between 0 and " + size); + } } From 624e9cc3633eb7cd32ad1b429c6e474198e08180 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Fri, 11 May 2018 08:49:10 -0600 Subject: [PATCH 11/36] these pass - needed a minor tweak --- .../sleuthkit/autopsy/commonfilessearch/UningestedCases.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java index 204d69f581..1d88bc2464 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java @@ -81,7 +81,7 @@ public class UningestedCases extends IntraCaseCommonFilesSearchTest { public void testTwo() { try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = new Long(1); + Long first = this.getDataSourceIdByIndex(0, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); From 4dc2bf4118b0ced0a2d1af17d7c465d46263e2ec Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Fri, 11 May 2018 11:50:26 -0600 Subject: [PATCH 12/36] renaming --- ....java => IngestedWithHashAndFileType.java} | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) rename Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/{IngestedWithHashAlgOnly.java => IngestedWithHashAndFileType.java} (95%) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java similarity index 95% rename from Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java rename to Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java index 76a1e0b7f7..f6ff9b3608 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAlgOnly.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java @@ -45,16 +45,16 @@ import org.sleuthkit.datamodel.TskCoreException; /** * Add set 1, set 2, set 3, and set 4 to case and ingest with hash algorithm. */ -public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { +public class IngestedWithHashAndFileType extends IntraCaseCommonFilesSearchTest { public static Test suite() { - NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(IngestedWithHashAlgOnly.class). + NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(IngestedWithHashAndFileType.class). clusters(".*"). enableModules(".*"); return conf.suite(); } - public IngestedWithHashAlgOnly(String name) { + public IngestedWithHashAndFileType(String name) { super(name); } @@ -69,7 +69,7 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { templates.add(hashLookupTemplate); templates.add(mimeTypeLookupTemplate); - IngestJobSettings ingestJobSettings = new IngestJobSettings(IngestedWithHashAlgOnly.class.getCanonicalName(), IngestType.FILES_ONLY, templates); + IngestJobSettings ingestJobSettings = new IngestJobSettings(IngestedWithHashAndFileType.class.getCanonicalName(), IngestType.FILES_ONLY, templates); try { IngestUtils.runIngestJob(Case.getCurrentCaseThrows().getDataSources(), ingestJobSettings); @@ -115,12 +115,9 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET4, 0)); - } catch (NoCurrentCaseException ex) { - Exceptions.printStackTrace(ex); - } catch (TskCoreException ex) { - Exceptions.printStackTrace(ex); - } catch (SQLException ex) { + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); + Assert.fail(ex); } } @@ -159,12 +156,9 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET4, 0)); - } catch (NoCurrentCaseException ex) { - Exceptions.printStackTrace(ex); - } catch (TskCoreException ex) { - Exceptions.printStackTrace(ex); - } catch (SQLException ex) { + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); + Assert.fail(ex); } } @@ -203,12 +197,9 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { assertTrue(fileExists(files, objectIdToDataSource, EMPTY, SET4, 0)); - } catch (NoCurrentCaseException ex) { - Exceptions.printStackTrace(ex); - } catch (TskCoreException ex) { - Exceptions.printStackTrace(ex); - } catch (SQLException ex) { + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); + Assert.fail(ex); } } @@ -467,6 +458,6 @@ public class IngestedWithHashAlgOnly extends IntraCaseCommonFilesSearchTest { @Override protected String getCaseName() { - return "IngestedWithHashAlgOnlyTests"; + return "IngestedWithHashAndFileTypeTests"; } } From e04569658c76676bd16a0437e105ed86c3c92d1e Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Fri, 11 May 2018 11:54:21 -0600 Subject: [PATCH 13/36] test for no mime types --- .../IngestedWithNoFileTypes.java | 72 +++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java index 2181ebcca8..4a3c10b10b 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java @@ -19,26 +19,45 @@ */ package org.sleuthkit.autopsy.commonfilessearch; +import java.sql.SQLException; import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import static junit.framework.Assert.assertTrue; +import junit.framework.Test; +import org.netbeans.junit.NbModuleSuite; import org.openide.util.Exceptions; import org.python.icu.impl.Assert; import org.sleuthkit.autopsy.casemodule.Case; 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.SingleDataSource; import org.sleuthkit.autopsy.ingest.IngestJobSettings; import org.sleuthkit.autopsy.ingest.IngestModuleTemplate; import org.sleuthkit.autopsy.modules.hashdatabase.HashLookupModuleFactory; import org.sleuthkit.autopsy.testutils.IngestUtils; +import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.TskCoreException; /** * Ingested w/o mime type info added to DB. - * + * * Setup: * - * Add images set 1, set 2, set 3, and set 4 to case. Do not run mime type module. + * Add images set 1, set 2, set 3, and set 4 to case. Do not run mime type + * module. */ public class IngestedWithNoFileTypes extends IntraCaseCommonFilesSearchTest { + public static Test suite() { + NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(IngestedWithNoFileTypes.class). + clusters(".*"). + enableModules(".*"); + return conf.suite(); + } + public IngestedWithNoFileTypes(String name) { super(name); } @@ -46,13 +65,13 @@ public class IngestedWithNoFileTypes extends IntraCaseCommonFilesSearchTest { @Override public void setUp() { super.setUp(); - + IngestModuleTemplate hashLookupTemplate = IngestUtils.getIngestModuleTemplate(new HashLookupModuleFactory()); ArrayList templates = new ArrayList<>(); templates.add(hashLookupTemplate); - IngestJobSettings ingestJobSettings = new IngestJobSettings(IngestedWithHashAlgOnly.class.getCanonicalName(), IngestJobSettings.IngestType.FILES_ONLY, templates); + IngestJobSettings ingestJobSettings = new IngestJobSettings(IngestedWithHashAndFileType.class.getCanonicalName(), IngestJobSettings.IngestType.FILES_ONLY, templates); try { IngestUtils.runIngestJob(Case.getCurrentCaseThrows().getDataSources(), ingestJobSettings); @@ -67,4 +86,49 @@ public class IngestedWithNoFileTypes extends IntraCaseCommonFilesSearchTest { return "IngestedWithNoFileTypes"; } + /** + * Search using all data sources and filtering for media types. We should + * find nothing and no errors should arise. + */ + public void testOne() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + + CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, true, false); + CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); + + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + + List files = getFiles(objectIdToDataSource.keySet()); + + assertTrue(files.size() == 0); + + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { + Exceptions.printStackTrace(ex); + } + } + + /** + * Search using single data source and filtering for doc types. Observe that + * nothing is found and that nothing blows up. + */ + public void testTwo() { + try { + Map dataSources = this.dataSourceLoader.getDataSourceMap(); + Long third = this.getDataSourceIdByIndex(2, dataSources); + + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(third, dataSources, true, false); + CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); + + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + + List files = getFiles(objectIdToDataSource.keySet()); + + assertTrue(files.size() == 0); + + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { + Exceptions.printStackTrace(ex); + Assert.fail(ex); + } + } } From f9fcca7a0bb2e5be8cca04ae9487fba9ff6fc14e Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Fri, 11 May 2018 12:14:14 -0600 Subject: [PATCH 14/36] reverted --- .../org/sleuthkit/autopsy/casemodule/services/Services.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java index 11dcb4ed28..c38bc12144 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java @@ -105,9 +105,7 @@ public class Services implements Closeable { @Override public void close() throws IOException { for (Closeable service : services) { - if(service != null){ - service.close(); - } + service.close(); } } From e2dabf4a0ed12ef91018f8e367c732d52a28ed9e Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 14 May 2018 09:02:04 -0600 Subject: [PATCH 15/36] comments --- .../commonfilesearch/DataSourceLoader.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java index 8bafeef885..8e566740e2 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java @@ -29,6 +29,13 @@ import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; +/** + * Encapsulates logic required to create a mapping of data sources in the + * current case to their data source IDs. + * + * Intended to be used within the context of a SwingWorker or other background + * thread. + */ public class DataSourceLoader { private static final String SELECT_DATA_SOURCES_LOGICAL = "select obj_id, name from tsk_files where obj_id in (SELECT obj_id FROM tsk_objects WHERE obj_id in (select obj_id from data_source_info))"; @@ -66,6 +73,14 @@ public class DataSourceLoader { } } + /** + * Get a map of data source Ids to their string names for the current case. + * + * @return Map of Long (id) to String (name) + * @throws NoCurrentCaseException + * @throws TskCoreException + * @throws SQLException + */ public Map getDataSourceMap() throws NoCurrentCaseException, TskCoreException, SQLException { Map dataSouceMap = new HashMap<>(); From e9e3756d4014d202d58e856486d3e84b1ca3d7d4 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 14 May 2018 09:04:54 -0600 Subject: [PATCH 16/36] empty default constructor removed --- .../sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java index 8e566740e2..5095f7c6c5 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java @@ -42,9 +42,6 @@ public class DataSourceLoader { private static final String SELECT_DATA_SOURCES_IMAGE = "select obj_id, name from tsk_image_names where obj_id in (SELECT obj_id FROM tsk_objects WHERE obj_id in (select obj_id from data_source_info))"; - public DataSourceLoader() { - } - private void loadLogicalSources(SleuthkitCase tskDb, Map dataSouceMap) throws TskCoreException, SQLException { //try block releases resources - exceptions are handled in done() try (SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_LOGICAL)) { From d7e87d7831ad4da591461eefd00508e1c88ad724 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 14 May 2018 09:06:32 -0600 Subject: [PATCH 17/36] try-with-resources --- .../autopsy/commonfilesearch/DataSourceLoader.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java index 5095f7c6c5..69af771dad 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/DataSourceLoader.java @@ -44,8 +44,10 @@ public class DataSourceLoader { private void loadLogicalSources(SleuthkitCase tskDb, Map dataSouceMap) throws TskCoreException, SQLException { //try block releases resources - exceptions are handled in done() - try (SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_LOGICAL)) { - ResultSet resultSet = query.getResultSet(); + try ( + SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_LOGICAL); + ResultSet resultSet = query.getResultSet() + ) { while (resultSet.next()) { Long objectId = resultSet.getLong(1); String dataSourceName = resultSet.getString(2); From ac59c3e9165f77e8efd0487f2f8cc51eae452c29 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 14 May 2018 09:12:14 -0600 Subject: [PATCH 18/36] rename a super type --- ...hTest.java => AbstractIntraCaseCommonFilesSearchTest.java} | 4 ++-- .../commonfilessearch/IngestedWithHashAndFileType.java | 2 +- .../autopsy/commonfilessearch/IngestedWithNoFileTypes.java | 4 ++-- .../sleuthkit/autopsy/commonfilessearch/UningestedCases.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/{IntraCaseCommonFilesSearchTest.java => AbstractIntraCaseCommonFilesSearchTest.java} (97%) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java similarity index 97% rename from Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java rename to Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java index 865d886ef3..c4565b74cb 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java @@ -68,7 +68,7 @@ import org.sleuthkit.datamodel.TskCoreException; * set 4 * - file.dat (empty file) */ -public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { +public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase { private static final String CASE_NAME = "IntraCaseCommonFilesSearchTest"; static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); @@ -90,7 +90,7 @@ public abstract class IntraCaseCommonFilesSearchTest extends NbTestCase { protected DataSourceLoader dataSourceLoader; - public IntraCaseCommonFilesSearchTest(String name) { + public AbstractIntraCaseCommonFilesSearchTest(String name) { super(name); } diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java index f6ff9b3608..d4fc9f634d 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java @@ -45,7 +45,7 @@ import org.sleuthkit.datamodel.TskCoreException; /** * Add set 1, set 2, set 3, and set 4 to case and ingest with hash algorithm. */ -public class IngestedWithHashAndFileType extends IntraCaseCommonFilesSearchTest { +public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSearchTest { public static Test suite() { NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(IngestedWithHashAndFileType.class). diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java index 4a3c10b10b..a9c7ca707a 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java @@ -49,7 +49,7 @@ import org.sleuthkit.datamodel.TskCoreException; * Add images set 1, set 2, set 3, and set 4 to case. Do not run mime type * module. */ -public class IngestedWithNoFileTypes extends IntraCaseCommonFilesSearchTest { +public class IngestedWithNoFileTypes extends AbstractIntraCaseCommonFilesSearchTest { public static Test suite() { NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(IngestedWithNoFileTypes.class). @@ -101,7 +101,7 @@ public class IngestedWithNoFileTypes extends IntraCaseCommonFilesSearchTest { List files = getFiles(objectIdToDataSource.keySet()); - assertTrue(files.size() == 0); + assertTrue(files.isEmpty()); } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java index 1d88bc2464..17ed02cd61 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java @@ -42,7 +42,7 @@ import org.sleuthkit.datamodel.TskCoreException; * Add images set 1, set 2, set 3, and set 4 to case. Do not ingest. * */ -public class UningestedCases extends IntraCaseCommonFilesSearchTest { +public class UningestedCases extends AbstractIntraCaseCommonFilesSearchTest { public static Test suite() { NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(UningestedCases.class). From 461bc820d7cf8914c3ee466365093340c650bfb2 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 14 May 2018 09:15:52 -0600 Subject: [PATCH 19/36] static fields, descriptive names --- ...bstractIntraCaseCommonFilesSearchTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java index c4565b74cb..23d2ae0d39 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java @@ -78,15 +78,15 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase private final Path IMAGE_PATH_3 = Paths.get(this.getDataDir().toString(), "commonfiles_image3_v1.vhd"); protected final Path IMAGE_PATH_4 = Paths.get(this.getDataDir().toString(), "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 static final String IMG = "IMG_6175.jpg"; + protected static final String DOC = "BasicStyleGuide.doc"; + protected static final String PDF = "adsf.pdf"; + protected static 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 static final String SET1 = "commonfiles_image1_v1.vhd"; + protected static final String SET2 = "commonfiles_image2_v1.vhd"; + protected static final String SET3 = "commonfiles_image3_v1.vhd"; + protected static final String SET4 = "commonfiles_image4_v1.vhd"; protected DataSourceLoader dataSourceLoader; @@ -126,11 +126,11 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase for (AbstractFile file : files) { - Long id = file.getId(); + Long objectId = file.getId(); String fileName = file.getName(); - String dataSourceName = objectIdToDataSource.get(id); + String dataSourceName = objectIdToDataSource.get(objectId); if (fileName.equals(name) && dataSourceName.equals(dataSource)) { tally++; From df68ffebe0485690df44386a8fdd924fd76d2aff Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 14 May 2018 13:28:14 -0600 Subject: [PATCH 20/36] size == 0 changed to isEmpty --- .../autopsy/commonfilessearch/IngestedWithNoFileTypes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java index a9c7ca707a..24b614eb5b 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java @@ -124,7 +124,7 @@ public class IngestedWithNoFileTypes extends AbstractIntraCaseCommonFilesSearchT List files = getFiles(objectIdToDataSource.keySet()); - assertTrue(files.size() == 0); + assertTrue(files.isEmpty()); } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); From 62ea0399c3ad8533e2b29d167b92d145c72121a4 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 14 May 2018 13:29:17 -0600 Subject: [PATCH 21/36] unused imports --- .../autopsy/commonfilesearch/CommonFilesPanel.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java index 866a76f061..3ce2c34e26 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java @@ -18,12 +18,9 @@ */ package org.sleuthkit.autopsy.commonfilesearch; -import java.io.File; -import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ExecutionException; @@ -33,7 +30,6 @@ import javax.swing.SwingUtilities; import javax.swing.SwingWorker; import org.openide.explorer.ExplorerManager; import org.openide.util.NbBundle; -import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.corecomponentinterfaces.DataResultViewer; import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent; @@ -42,8 +38,6 @@ import org.sleuthkit.autopsy.corecomponents.TableFilterNode; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.autopsy.directorytree.DataResultFilterNode; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.SleuthkitCase.CaseDbQuery; import org.sleuthkit.datamodel.TskCoreException; /** From 0ec209021be6a3f67c76a483b472e28a5079317d Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 14 May 2018 14:20:26 -0600 Subject: [PATCH 22/36] reflects new case utils API --- .../AbstractIntraCaseCommonFilesSearchTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java index 23d2ae0d39..7131be5508 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java @@ -97,7 +97,7 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase @Override public void setUp() { - CaseUtils.createCase(CASE_DIRECTORY_PATH, this.getCaseName()); + CaseUtils.createCase(this.getCaseName()); final ImageDSProcessor imageDSProcessor = new ImageDSProcessor(); @@ -112,7 +112,7 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase @Override public void tearDown() { CaseUtils.closeCase(); - CaseUtils.deleteCaseDir(CASE_DIRECTORY_PATH); + CaseUtils.deleteCaseDir(); } /** From 59f7d30499bce8c97525560dba1d160411cdeefe Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 14 May 2018 15:41:21 -0600 Subject: [PATCH 23/36] reflects new test API --- .../AbstractIntraCaseCommonFilesSearchTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java index 7131be5508..0af583d25d 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java @@ -19,6 +19,7 @@ */ package org.sleuthkit.autopsy.commonfilessearch; +import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -112,7 +113,12 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase @Override public void tearDown() { CaseUtils.closeCase(); - CaseUtils.deleteCaseDir(); + try { + CaseUtils.deleteCaseDir(CASE_DIRECTORY_PATH.toFile()); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + //does not represent a failure in the common files search feature + } } /** From 4e13a6d97f6c0b7bf0b938c3f6885a4b803ec6df Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 21 May 2018 11:52:55 -0600 Subject: [PATCH 24/36] updated to latest api calls --- .../AbstractIntraCaseCommonFilesSearchTest.java | 4 ++-- .../src/org/sleuthkit/autopsy/testutils/CaseUtils.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java index 0af583d25d..d207b6a6a7 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java @@ -98,7 +98,7 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase @Override public void setUp() { - CaseUtils.createCase(this.getCaseName()); + CaseUtils.createAsCurrentCase(this.getCaseName()); final ImageDSProcessor imageDSProcessor = new ImageDSProcessor(); @@ -112,7 +112,7 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase @Override public void tearDown() { - CaseUtils.closeCase(); + CaseUtils.closeCurrentCase(false); try { CaseUtils.deleteCaseDir(CASE_DIRECTORY_PATH.toFile()); } catch (IOException ex) { 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 ebbbd3f8c7..cccd3fc639 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 @@ -127,5 +127,4 @@ public final class CaseUtils { */ private CaseUtils() { } - } From 14215f25fdf0a9be58530b8b36b140efcf511c48 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Wed, 23 May 2018 10:40:19 -0600 Subject: [PATCH 25/36] documentation / renaming --- ...bstractIntraCaseCommonFilesSearchTest.java | 29 +- .../IngestedWithHashAndFileType.java | 288 +++++++++--------- 2 files changed, 170 insertions(+), 147 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java index d207b6a6a7..5d3d733296 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java @@ -126,7 +126,19 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase */ protected abstract String getCaseName(); - protected boolean fileExists(List files, Map objectIdToDataSource, String name, String dataSource, int count) { + /** + * Verify that the given file appears a precise number times in the given + * data source. + * + * @param files search domain + * @param objectIdToDataSource mapping of file ids to data source names + * @param name name of file to search for + * @param dataSource name of data source where file should appear + * @param count number of appearances of the given file + * @return true if a file with the given name exists the specified number + * of times in the given data source + */ + protected boolean verifyFileExistanceAndCount(List files, Map objectIdToDataSource, String name, String dataSource, int count) { int tally = 0; @@ -146,8 +158,19 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase return tally == count; } - protected boolean fileExists(List files, Map objectIdToDataSource, String name, String dataSource) { - return fileExists(files, objectIdToDataSource, name, dataSource, 1); + /** + * Convenience method which verifies that a file exists within a given data + * source exactly once. + * + * @param files search domain + * @param objectIdToDataSource mapping of file ids to data source names + * @param name name of file to search for + * @param dataSource name of data source where file should appear + * @return true if a file with the given name exists once in the given data + * source + */ + protected boolean verifySingularFileExistance(List files, Map objectIdToDataSource, String name, String dataSource) { + return verifyFileExistanceAndCount(files, objectIdToDataSource, name, dataSource, 1); } protected Map mapFileInstancesToDataSources(CommonFilesMetadata metadata) { diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java index d4fc9f634d..215bc366f7 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java @@ -94,25 +94,25 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea List 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, IMG, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 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(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(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)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { @@ -135,25 +135,25 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea List 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, IMG, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 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(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(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)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { @@ -176,25 +176,25 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea List 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, IMG, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 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(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(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)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { @@ -220,25 +220,25 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea List 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, IMG, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 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(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(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)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); @@ -263,25 +263,25 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea List 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, IMG, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 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(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(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)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); @@ -306,25 +306,25 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea List 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, IMG, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 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(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(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)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); @@ -348,25 +348,25 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea List 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, IMG, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 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(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(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)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); @@ -389,25 +389,25 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea List 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, IMG, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 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(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(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)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); @@ -430,25 +430,25 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea List 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, IMG, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET1, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET2, 0)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET3, 1)); - assertTrue(fileExists(files, objectIdToDataSource, DOC, SET4, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 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(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(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)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); From 8adf71a9b9c6888a71923775bf8c252662c299a4 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Wed, 23 May 2018 15:52:57 -0600 Subject: [PATCH 26/36] getDataSourceByIndex changed to getDataSourceByName --- ...bstractIntraCaseCommonFilesSearchTest.java | 27 ++++++++++--------- .../IngestedWithHashAndFileType.java | 12 ++++----- .../IngestedWithNoFileTypes.java | 2 +- .../commonfilessearch/UningestedCases.java | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java index 5d3d733296..5788259127 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java @@ -81,7 +81,7 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase protected static final String IMG = "IMG_6175.jpg"; protected static final String DOC = "BasicStyleGuide.doc"; - protected static final String PDF = "adsf.pdf"; + protected static final String PDF = "adsf.pdf"; //not a typo - it appears this way in the test image protected static final String EMPTY = "file.dat"; protected static final String SET1 = "commonfiles_image1_v1.vhd"; @@ -185,10 +185,10 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase return instanceIdToDataSource; } - protected List getFiles(Set keySet) { - List files = new ArrayList<>(keySet.size()); + protected List getFiles(Set objectIds) { + List files = new ArrayList<>(objectIds.size()); - for (Long id : keySet) { + for (Long id : objectIds) { try { AbstractFile file = Case.getCurrentCaseThrows().getSleuthkitCase().getAbstractFileById(id); files.add(file); @@ -201,16 +201,17 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase return files; } - protected Long getDataSourceIdByIndex(int index, Map dataSources){ + protected Long getDataSourceIdByName(String name, Map dataSources){ - int current = 0; - for(Entry dataSource : dataSources.entrySet()){ - if(current == index){ - return dataSource.getKey(); + if(dataSources.containsValue(name)){ + for(Entry dataSource : dataSources.entrySet()){ + if(dataSource.getValue().equals(name)){ + return dataSource.getKey(); + } } - current++; - } - final int size = dataSources.size() - 1; - throw new IndexOutOfBoundsException("The value given for index was unreasonable. Should be between 0 and " + size); + } else { + throw new IndexOutOfBoundsException(String.format("Name should be one of: {0}", String.join(",", dataSources.values()))); + } + return null; } } diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java index 215bc366f7..9a2de34b16 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java @@ -211,7 +211,7 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea public void testTwoA() { try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = this.getDataSourceIdByIndex(0, dataSources); + Long first = this.getDataSourceIdByName(SET1, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -254,7 +254,7 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea public void testTwoB() { try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = this.getDataSourceIdByIndex(0, dataSources); + Long first = this.getDataSourceIdByName(SET1, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, true, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -297,7 +297,7 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea public void testTwoC() { try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = this.getDataSourceIdByIndex(0, dataSources); + Long first = this.getDataSourceIdByName(SET1, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, true); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -339,7 +339,7 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea public void testThree(){ try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long second = this.getDataSourceIdByIndex(1, dataSources); + Long second = this.getDataSourceIdByName(SET2, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(second, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -380,7 +380,7 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea public void testFour(){ try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long last = this.getDataSourceIdByIndex(3, dataSources); + Long last = this.getDataSourceIdByName(SET4, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(last, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -421,7 +421,7 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea public void testFive(){ try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long third = this.getDataSourceIdByIndex(2, dataSources); + Long third = this.getDataSourceIdByName(SET3, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(third, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java index 24b614eb5b..d487c93645 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java @@ -115,7 +115,7 @@ public class IngestedWithNoFileTypes extends AbstractIntraCaseCommonFilesSearchT public void testTwo() { try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long third = this.getDataSourceIdByIndex(2, dataSources); + Long third = this.getDataSourceIdByName(SET3, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(third, dataSources, true, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java index 17ed02cd61..bae94316dc 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java @@ -81,7 +81,7 @@ public class UningestedCases extends AbstractIntraCaseCommonFilesSearchTest { public void testTwo() { try { Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = this.getDataSourceIdByIndex(0, dataSources); + Long first = this.getDataSourceIdByName(SET1, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); From 19d6d25e1f4b5b63ba08fff4ece0d063254a2f2c Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Wed, 23 May 2018 22:34:26 -0600 Subject: [PATCH 27/36] removed polymorphism in favor of encapsulation --- .../IngestedWithHashAndFileType.java | 67 +++++++++------ .../IngestedWithNoFileTypes.java | 32 ++++--- ...lesSearchTest.java => IntraCaseUtils.java} | 85 ++++++++++--------- .../commonfilessearch/UningestedCases.java | 30 +++++-- 4 files changed, 126 insertions(+), 88 deletions(-) rename Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/{AbstractIntraCaseCommonFilesSearchTest.java => IntraCaseUtils.java} (72%) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java index 9a2de34b16..2f81c89099 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import junit.framework.Test; import org.netbeans.junit.NbModuleSuite; +import org.netbeans.junit.NbTestCase; import org.openide.util.Exceptions; import org.python.icu.impl.Assert; import org.sleuthkit.autopsy.casemodule.Case; @@ -33,6 +34,18 @@ import org.sleuthkit.autopsy.commonfilesearch.AllDataSourcesCommonFilesAlgorithm import org.sleuthkit.autopsy.commonfilesearch.CommonFilesMetadata; import org.sleuthkit.autopsy.commonfilesearch.CommonFilesMetadataBuilder; import org.sleuthkit.autopsy.commonfilesearch.SingleDataSource; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.DOC; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.EMPTY; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.IMG; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.PDF; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.SET1; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.SET2; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.SET3; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.SET4; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.getDataSourceIdByName; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.getFiles; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.mapFileInstancesToDataSources; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.verifyFileExistanceAndCount; import org.sleuthkit.autopsy.ingest.IngestJobSettings; import org.sleuthkit.autopsy.ingest.IngestJobSettings.IngestType; import org.sleuthkit.autopsy.ingest.IngestModuleTemplate; @@ -45,7 +58,7 @@ import org.sleuthkit.datamodel.TskCoreException; /** * Add set 1, set 2, set 3, and set 4 to case and ingest with hash algorithm. */ -public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSearchTest { +public class IngestedWithHashAndFileType extends NbTestCase { public static Test suite() { NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(IngestedWithHashAndFileType.class). @@ -53,14 +66,18 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea enableModules(".*"); return conf.suite(); } + + private final IntraCaseUtils utils; public IngestedWithHashAndFileType(String name) { super(name); + + this.utils = new IntraCaseUtils(this, "IngestedWithHashAndFileTypeTests"); } @Override public void setUp() { - super.setUp(); + this.utils.setUp(); IngestModuleTemplate hashLookupTemplate = IngestUtils.getIngestModuleTemplate(new HashLookupModuleFactory()); IngestModuleTemplate mimeTypeLookupTemplate = IngestUtils.getIngestModuleTemplate(new FileTypeIdModuleFactory()); @@ -78,6 +95,11 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea Assert.fail(ex); } } + + @Override + public void tearDown(){ + this.utils.tearDown(); + } /** * Find all matches & all file types. Confirm file.jpg is found on all three and @@ -85,14 +107,14 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea */ public void testOneA() { try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); + Map dataSources = this.utils.getDataSourceMap(); CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, false, false); CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); - Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + Map objectIdToDataSource = IntraCaseUtils.mapFileInstancesToDataSources(metadata); - List files = getFiles(objectIdToDataSource.keySet()); + List files = IntraCaseUtils.getFiles(objectIdToDataSource.keySet()); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); @@ -105,7 +127,7 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); - assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); + assertTrue(IntraCaseUtils.verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET4, 0)); @@ -126,7 +148,7 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea */ public void testOneB() { try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); + Map dataSources = this.utils.getDataSourceMap(); CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, true, false); CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); @@ -167,7 +189,7 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea */ public void testOneC() { try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); + Map dataSources = this.utils.getDataSourceMap(); CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, false, true); CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); @@ -210,8 +232,8 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea */ public void testTwoA() { try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = this.getDataSourceIdByName(SET1, dataSources); + Map dataSources = this.utils.getDataSourceMap(); + Long first = getDataSourceIdByName(SET1, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -253,8 +275,8 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea */ public void testTwoB() { try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = this.getDataSourceIdByName(SET1, dataSources); + Map dataSources = this.utils.getDataSourceMap(); + Long first = getDataSourceIdByName(SET1, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, true, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -296,8 +318,8 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea */ public void testTwoC() { try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = this.getDataSourceIdByName(SET1, dataSources); + Map dataSources = this.utils.getDataSourceMap(); + Long first = getDataSourceIdByName(SET1, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, true); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -338,8 +360,8 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea */ public void testThree(){ try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long second = this.getDataSourceIdByName(SET2, dataSources); + Map dataSources = this.utils.getDataSourceMap(); + Long second = getDataSourceIdByName(SET2, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(second, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -379,8 +401,8 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea */ public void testFour(){ try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long last = this.getDataSourceIdByName(SET4, dataSources); + Map dataSources = this.utils.getDataSourceMap(); + Long last = getDataSourceIdByName(SET4, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(last, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -420,8 +442,8 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea */ public void testFive(){ try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long third = this.getDataSourceIdByName(SET3, dataSources); + Map dataSources = this.utils.getDataSourceMap(); + Long third = getDataSourceIdByName(SET3, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(third, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -455,9 +477,4 @@ public class IngestedWithHashAndFileType extends AbstractIntraCaseCommonFilesSea Assert.fail(ex); } } - - @Override - protected String getCaseName() { - return "IngestedWithHashAndFileTypeTests"; - } } diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java index d487c93645..e4c00cf33a 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java @@ -26,6 +26,7 @@ import java.util.Map; import static junit.framework.Assert.assertTrue; import junit.framework.Test; import org.netbeans.junit.NbModuleSuite; +import org.netbeans.junit.NbTestCase; import org.openide.util.Exceptions; import org.python.icu.impl.Assert; import org.sleuthkit.autopsy.casemodule.Case; @@ -38,6 +39,7 @@ import org.sleuthkit.autopsy.ingest.IngestJobSettings; import org.sleuthkit.autopsy.ingest.IngestModuleTemplate; import org.sleuthkit.autopsy.modules.hashdatabase.HashLookupModuleFactory; import org.sleuthkit.autopsy.testutils.IngestUtils; +import static org.sleuthkit.autopsy.testutils.IngestUtils.getIngestModuleTemplate; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.TskCoreException; @@ -49,7 +51,7 @@ import org.sleuthkit.datamodel.TskCoreException; * Add images set 1, set 2, set 3, and set 4 to case. Do not run mime type * module. */ -public class IngestedWithNoFileTypes extends AbstractIntraCaseCommonFilesSearchTest { +public class IngestedWithNoFileTypes extends NbTestCase { public static Test suite() { NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(IngestedWithNoFileTypes.class). @@ -58,15 +60,19 @@ public class IngestedWithNoFileTypes extends AbstractIntraCaseCommonFilesSearchT return conf.suite(); } + private IntraCaseUtils utils; + public IngestedWithNoFileTypes(String name) { super(name); + + this.utils = new IntraCaseUtils(this, "IngestedWithNoFileTypes"); } @Override public void setUp() { - super.setUp(); + this.utils.setUp(); - IngestModuleTemplate hashLookupTemplate = IngestUtils.getIngestModuleTemplate(new HashLookupModuleFactory()); + IngestModuleTemplate hashLookupTemplate = getIngestModuleTemplate(new HashLookupModuleFactory()); ArrayList templates = new ArrayList<>(); templates.add(hashLookupTemplate); @@ -80,10 +86,10 @@ public class IngestedWithNoFileTypes extends AbstractIntraCaseCommonFilesSearchT Assert.fail(ex); } } - + @Override - protected String getCaseName() { - return "IngestedWithNoFileTypes"; + public void tearDown(){ + this.utils.tearDown(); } /** @@ -92,14 +98,14 @@ public class IngestedWithNoFileTypes extends AbstractIntraCaseCommonFilesSearchT */ public void testOne() { try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); + Map dataSources = this.utils.getDataSourceMap(); CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, true, false); CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); - Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + Map objectIdToDataSource = IntraCaseUtils.mapFileInstancesToDataSources(metadata); - List files = getFiles(objectIdToDataSource.keySet()); + List files = IntraCaseUtils.getFiles(objectIdToDataSource.keySet()); assertTrue(files.isEmpty()); @@ -114,15 +120,15 @@ public class IngestedWithNoFileTypes extends AbstractIntraCaseCommonFilesSearchT */ public void testTwo() { try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long third = this.getDataSourceIdByName(SET3, dataSources); + Map dataSources = this.utils.getDataSourceMap(); + Long third = IntraCaseUtils.getDataSourceIdByName(IntraCaseUtils.SET3, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(third, dataSources, true, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); - Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); + Map objectIdToDataSource = IntraCaseUtils.mapFileInstancesToDataSources(metadata); - List files = getFiles(objectIdToDataSource.keySet()); + List files = IntraCaseUtils.getFiles(objectIdToDataSource.keySet()); assertTrue(files.isEmpty()); diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseUtils.java similarity index 72% rename from Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java rename to Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseUtils.java index 5788259127..13c115c0e3 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/AbstractIntraCaseCommonFilesSearchTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseUtils.java @@ -22,11 +22,11 @@ package org.sleuthkit.autopsy.commonfilessearch; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; +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 org.netbeans.junit.NbTestCase; import org.openide.util.Exceptions; @@ -69,36 +69,43 @@ import org.sleuthkit.datamodel.TskCoreException; * set 4 * - file.dat (empty file) */ -public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase { - +class IntraCaseUtils { + private static final String CASE_NAME = "IntraCaseCommonFilesSearchTest"; static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); - protected final Path IMAGE_PATH_1 = Paths.get(this.getDataDir().toString(), "commonfiles_image1_v1.vhd"); - private final Path IMAGE_PATH_2 = Paths.get(this.getDataDir().toString(), "commonfiles_image2_v1.vhd"); - private final Path IMAGE_PATH_3 = Paths.get(this.getDataDir().toString(), "commonfiles_image3_v1.vhd"); - protected final Path IMAGE_PATH_4 = Paths.get(this.getDataDir().toString(), "commonfiles_image4_v1.vhd"); + final Path IMAGE_PATH_1; + final Path IMAGE_PATH_2; + final Path IMAGE_PATH_3; + final Path IMAGE_PATH_4; - protected static final String IMG = "IMG_6175.jpg"; - protected static final String DOC = "BasicStyleGuide.doc"; - protected static final String PDF = "adsf.pdf"; //not a typo - it appears this way in the test image - protected static final String EMPTY = "file.dat"; + static final String IMG = "IMG_6175.jpg"; + static final String DOC = "BasicStyleGuide.doc"; + static final String PDF = "adsf.pdf"; //not a typo - it appears this way in the test image + static final String EMPTY = "file.dat"; - protected static final String SET1 = "commonfiles_image1_v1.vhd"; - protected static final String SET2 = "commonfiles_image2_v1.vhd"; - protected static final String SET3 = "commonfiles_image3_v1.vhd"; - protected static final String SET4 = "commonfiles_image4_v1.vhd"; - - protected DataSourceLoader dataSourceLoader; - - public AbstractIntraCaseCommonFilesSearchTest(String name) { - super(name); + static final String SET1 = "commonfiles_image1_v1.vhd"; + static final String SET2 = "commonfiles_image2_v1.vhd"; + static final String SET3 = "commonfiles_image3_v1.vhd"; + static final String SET4 = "commonfiles_image4_v1.vhd"; + + private final DataSourceLoader dataSourceLoader; + + private final String caseName; + + IntraCaseUtils(NbTestCase nbTestCase, String caseName){ + IMAGE_PATH_1 = Paths.get(nbTestCase.getDataDir().toString(), "commonfiles_image1_v1.vhd"); + IMAGE_PATH_2 = Paths.get(nbTestCase.getDataDir().toString(), "commonfiles_image2_v1.vhd"); + IMAGE_PATH_3 = Paths.get(nbTestCase.getDataDir().toString(), "commonfiles_image3_v1.vhd"); + IMAGE_PATH_4 = Paths.get(nbTestCase.getDataDir().toString(), "commonfiles_image4_v1.vhd"); + + this.dataSourceLoader = new DataSourceLoader(); + + this.caseName = caseName; } - - @Override - public void setUp() { - - CaseUtils.createAsCurrentCase(this.getCaseName()); + + void setUp(){ + CaseUtils.createAsCurrentCase(this.caseName); final ImageDSProcessor imageDSProcessor = new ImageDSProcessor(); @@ -106,12 +113,13 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase IngestUtils.addDataSource(imageDSProcessor, IMAGE_PATH_2); IngestUtils.addDataSource(imageDSProcessor, IMAGE_PATH_3); IngestUtils.addDataSource(imageDSProcessor, IMAGE_PATH_4); - - this.dataSourceLoader = new DataSourceLoader(); } - - @Override - public void tearDown() { + + Map getDataSourceMap() throws NoCurrentCaseException, TskCoreException, SQLException{ + return this.dataSourceLoader.getDataSourceMap(); + } + + void tearDown(){ CaseUtils.closeCurrentCase(false); try { CaseUtils.deleteCaseDir(CASE_DIRECTORY_PATH.toFile()); @@ -121,11 +129,6 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase } } - /** - * Override this to provide a string for subclasses to use in CaseUtils.createCase(...) - */ - protected abstract String getCaseName(); - /** * Verify that the given file appears a precise number times in the given * data source. @@ -138,7 +141,7 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase * @return true if a file with the given name exists the specified number * of times in the given data source */ - protected boolean verifyFileExistanceAndCount(List files, Map objectIdToDataSource, String name, String dataSource, int count) { + static boolean verifyFileExistanceAndCount(List files, Map objectIdToDataSource, String name, String dataSource, int count) { int tally = 0; @@ -169,11 +172,11 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase * @return true if a file with the given name exists once in the given data * source */ - protected boolean verifySingularFileExistance(List files, Map objectIdToDataSource, String name, String dataSource) { + static boolean verifySingularFileExistance(List files, Map objectIdToDataSource, String name, String dataSource) { return verifyFileExistanceAndCount(files, objectIdToDataSource, name, dataSource, 1); } - protected Map mapFileInstancesToDataSources(CommonFilesMetadata metadata) { + static Map mapFileInstancesToDataSources(CommonFilesMetadata metadata) { Map instanceIdToDataSource = new HashMap<>(); for (Map.Entry entry : metadata.getMetadata().entrySet()) { @@ -185,7 +188,7 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase return instanceIdToDataSource; } - protected List getFiles(Set objectIds) { + static List getFiles(Set objectIds) { List files = new ArrayList<>(objectIds.size()); for (Long id : objectIds) { @@ -201,10 +204,10 @@ public abstract class AbstractIntraCaseCommonFilesSearchTest extends NbTestCase return files; } - protected Long getDataSourceIdByName(String name, Map dataSources){ + static Long getDataSourceIdByName(String name, Map dataSources){ if(dataSources.containsValue(name)){ - for(Entry dataSource : dataSources.entrySet()){ + for(Map.Entry dataSource : dataSources.entrySet()){ if(dataSource.getValue().equals(name)){ return dataSource.getKey(); } diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java index bae94316dc..9bd7a02bae 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/UningestedCases.java @@ -24,6 +24,7 @@ import java.util.Map; import static junit.framework.Assert.assertEquals; import junit.framework.Test; import org.netbeans.junit.NbModuleSuite; +import org.netbeans.junit.NbTestCase; import org.openide.util.Exceptions; import org.python.icu.impl.Assert; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; @@ -31,6 +32,8 @@ import org.sleuthkit.autopsy.commonfilesearch.AllDataSourcesCommonFilesAlgorithm import org.sleuthkit.autopsy.commonfilesearch.CommonFilesMetadata; import org.sleuthkit.autopsy.commonfilesearch.CommonFilesMetadataBuilder; import org.sleuthkit.autopsy.commonfilesearch.SingleDataSource; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.SET1; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.getDataSourceIdByName; import org.sleuthkit.datamodel.TskCoreException; /** @@ -42,7 +45,7 @@ import org.sleuthkit.datamodel.TskCoreException; * Add images set 1, set 2, set 3, and set 4 to case. Do not ingest. * */ -public class UningestedCases extends AbstractIntraCaseCommonFilesSearchTest { +public class UningestedCases extends NbTestCase { public static Test suite() { NbModuleSuite.Configuration conf = NbModuleSuite.createConfiguration(UningestedCases.class). @@ -51,8 +54,22 @@ public class UningestedCases extends AbstractIntraCaseCommonFilesSearchTest { return conf.suite(); } + private final IntraCaseUtils utils; + public UningestedCases(String name) { super(name); + + this.utils = new IntraCaseUtils(this, "UningestedCasesTests"); + } + + @Override + public void setUp(){ + this.utils.setUp(); + } + + @Override + public void tearDown(){ + this.utils.tearDown(); } /** @@ -61,7 +78,7 @@ public class UningestedCases extends AbstractIntraCaseCommonFilesSearchTest { */ public void testOne() { try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); + Map dataSources = this.utils.getDataSourceMap(); CommonFilesMetadataBuilder allSourcesBuilder = new AllDataSourcesCommonFilesAlgorithm(dataSources, false, false); CommonFilesMetadata metadata = allSourcesBuilder.findCommonFiles(); @@ -80,8 +97,8 @@ public class UningestedCases extends AbstractIntraCaseCommonFilesSearchTest { */ public void testTwo() { try { - Map dataSources = this.dataSourceLoader.getDataSourceMap(); - Long first = this.getDataSourceIdByName(SET1, dataSources); + Map dataSources = this.utils.getDataSourceMap(); + Long first = getDataSourceIdByName(SET1, dataSources); CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); @@ -94,9 +111,4 @@ public class UningestedCases extends AbstractIntraCaseCommonFilesSearchTest { Assert.fail(ex); } } - - @Override - protected String getCaseName() { - return "UningestedCasesTests"; - } } From faa15d698a9878734a9c2e8bdf481a30c95bfced Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Thu, 24 May 2018 08:43:51 -0600 Subject: [PATCH 28/36] codacy and other code quality stuff --- .../IngestedWithHashAndFileType.java | 181 ++++++++---------- .../IngestedWithNoFileTypes.java | 2 +- .../commonfilessearch/IntraCaseUtils.java | 24 +-- 3 files changed, 96 insertions(+), 111 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java index 2f81c89099..a599763346 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithHashAndFileType.java @@ -34,18 +34,7 @@ import org.sleuthkit.autopsy.commonfilesearch.AllDataSourcesCommonFilesAlgorithm import org.sleuthkit.autopsy.commonfilesearch.CommonFilesMetadata; import org.sleuthkit.autopsy.commonfilesearch.CommonFilesMetadataBuilder; import org.sleuthkit.autopsy.commonfilesearch.SingleDataSource; -import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.DOC; -import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.EMPTY; -import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.IMG; -import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.PDF; -import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.SET1; -import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.SET2; -import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.SET3; -import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.SET4; -import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.getDataSourceIdByName; -import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.getFiles; -import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.mapFileInstancesToDataSources; -import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.verifyFileExistanceAndCount; +import static org.sleuthkit.autopsy.commonfilessearch.IntraCaseUtils.*; import org.sleuthkit.autopsy.ingest.IngestJobSettings; import org.sleuthkit.autopsy.ingest.IngestJobSettings.IngestType; import org.sleuthkit.autopsy.ingest.IngestModuleTemplate; @@ -56,7 +45,7 @@ import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.TskCoreException; /** - * Add set 1, set 2, set 3, and set 4 to case and ingest with hash algorithm. + * Add set 1, set 2, set 3, and set 4 to case and ingest with hash algorithm. */ public class IngestedWithHashAndFileType extends NbTestCase { @@ -66,12 +55,12 @@ public class IngestedWithHashAndFileType extends NbTestCase { enableModules(".*"); return conf.suite(); } - + private final IntraCaseUtils utils; public IngestedWithHashAndFileType(String name) { super(name); - + this.utils = new IntraCaseUtils(this, "IngestedWithHashAndFileTypeTests"); } @@ -81,7 +70,7 @@ public class IngestedWithHashAndFileType extends NbTestCase { IngestModuleTemplate hashLookupTemplate = IngestUtils.getIngestModuleTemplate(new HashLookupModuleFactory()); IngestModuleTemplate mimeTypeLookupTemplate = IngestUtils.getIngestModuleTemplate(new FileTypeIdModuleFactory()); - + ArrayList templates = new ArrayList<>(); templates.add(hashLookupTemplate); templates.add(mimeTypeLookupTemplate); @@ -95,15 +84,15 @@ public class IngestedWithHashAndFileType extends NbTestCase { Assert.fail(ex); } } - + @Override - public void tearDown(){ + public void tearDown() { this.utils.tearDown(); } /** - * Find all matches & all file types. Confirm file.jpg is found on all three and - * file.docx is found on two. + * Find all matches & all file types. Confirm file.jpg is found on all three + * and file.docx is found on two. */ public void testOneA() { try { @@ -115,36 +104,36 @@ public class IngestedWithHashAndFileType extends NbTestCase { Map objectIdToDataSource = IntraCaseUtils.mapFileInstancesToDataSources(metadata); List files = IntraCaseUtils.getFiles(objectIdToDataSource.keySet()); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(IntraCaseUtils.verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); - } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); Assert.fail(ex); } } - + /** - * Find all matches & only image types. Confirm file.jpg is found on all three. + * Find all matches & only image types. Confirm file.jpg is found on all + * three. */ public void testOneB() { try { @@ -156,36 +145,36 @@ public class IngestedWithHashAndFileType extends NbTestCase { Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); List files = getFiles(objectIdToDataSource.keySet()); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); - } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); Assert.fail(ex); } } - + /** - * Find all matches & only image types. Confirm file.jpg is found on all three. + * Find all matches & only image types. Confirm file.jpg is found on all + * three. */ public void testOneC() { try { @@ -197,27 +186,26 @@ public class IngestedWithHashAndFileType extends NbTestCase { Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); List files = getFiles(objectIdToDataSource.keySet()); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); - } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); @@ -226,9 +214,8 @@ public class IngestedWithHashAndFileType extends NbTestCase { } /** - * Find matches on set 1 & all file types. Confirm - * same results. - * + * Find matches on set 1 & all file types. Confirm same results. + * */ public void testTwoA() { try { @@ -237,26 +224,26 @@ public class IngestedWithHashAndFileType extends NbTestCase { CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); - + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); List files = getFiles(objectIdToDataSource.keySet()); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); @@ -267,11 +254,10 @@ public class IngestedWithHashAndFileType extends NbTestCase { Assert.fail(ex); } } - + /** - * Find matches on set 1 & only media types. Confirm - * same results. - * + * Find matches on set 1 & only media types. Confirm same results. + * */ public void testTwoB() { try { @@ -280,26 +266,26 @@ public class IngestedWithHashAndFileType extends NbTestCase { CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, true, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); - + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); List files = getFiles(objectIdToDataSource.keySet()); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); @@ -310,11 +296,10 @@ public class IngestedWithHashAndFileType extends NbTestCase { Assert.fail(ex); } } - + /** - * Find matches on set 1 & all file types. Confirm - * same results. - * + * Find matches on set 1 & all file types. Confirm same results. + * */ public void testTwoC() { try { @@ -323,26 +308,26 @@ public class IngestedWithHashAndFileType extends NbTestCase { CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(first, dataSources, false, true); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); - + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); List files = getFiles(objectIdToDataSource.keySet()); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); @@ -353,125 +338,125 @@ public class IngestedWithHashAndFileType extends NbTestCase { Assert.fail(ex); } } - + /** * Find matches on set 2 & all file types: Confirm file.jpg. - * + * */ - public void testThree(){ + public void testThree() { try { Map dataSources = this.utils.getDataSourceMap(); Long second = getDataSourceIdByName(SET2, dataSources); - + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(second, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); - + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); - + List files = getFiles(objectIdToDataSource.keySet()); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); - + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); Assert.fail(ex); } } - + /** * Find matches on set 4 & all file types: Confirm nothing is found. */ - public void testFour(){ + public void testFour() { try { Map dataSources = this.utils.getDataSourceMap(); Long last = getDataSourceIdByName(SET4, dataSources); - + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(last, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); - + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); - + List files = getFiles(objectIdToDataSource.keySet()); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 0)); - assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 0)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); - + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); Assert.fail(ex); } } - + /** * Find matches on set 3 & all file types: Confirm file.jpg and file.docx. */ - public void testFive(){ + public void testFive() { try { Map dataSources = this.utils.getDataSourceMap(); Long third = getDataSourceIdByName(SET3, dataSources); - + CommonFilesMetadataBuilder singleSourceBuilder = new SingleDataSource(third, dataSources, false, false); CommonFilesMetadata metadata = singleSourceBuilder.findCommonFiles(); - + Map objectIdToDataSource = mapFileInstancesToDataSources(metadata); - + List files = getFiles(objectIdToDataSource.keySet()); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET1, 2)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET2, 1)); - assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET3, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, IMG, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET1, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET3, 1)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, DOC, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, PDF, SET4, 0)); - + assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET1, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET2, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET3, 0)); assertTrue(verifyFileExistanceAndCount(files, objectIdToDataSource, EMPTY, SET4, 0)); - + } catch (NoCurrentCaseException | TskCoreException | SQLException ex) { Exceptions.printStackTrace(ex); Assert.fail(ex); diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java index e4c00cf33a..0090d0f699 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IngestedWithNoFileTypes.java @@ -60,7 +60,7 @@ public class IngestedWithNoFileTypes extends NbTestCase { return conf.suite(); } - private IntraCaseUtils utils; + private final IntraCaseUtils utils; public IngestedWithNoFileTypes(String name) { super(name); diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseUtils.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseUtils.java index 13c115c0e3..2a2a8bd7bf 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseUtils.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseUtils.java @@ -74,10 +74,10 @@ class IntraCaseUtils { private static final String CASE_NAME = "IntraCaseCommonFilesSearchTest"; static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); - final Path IMAGE_PATH_1; - final Path IMAGE_PATH_2; - final Path IMAGE_PATH_3; - final Path IMAGE_PATH_4; + final Path imagePath1; + final Path imagePath2; + final Path imagePath3; + final Path imagePath4; static final String IMG = "IMG_6175.jpg"; static final String DOC = "BasicStyleGuide.doc"; @@ -94,10 +94,10 @@ class IntraCaseUtils { private final String caseName; IntraCaseUtils(NbTestCase nbTestCase, String caseName){ - IMAGE_PATH_1 = Paths.get(nbTestCase.getDataDir().toString(), "commonfiles_image1_v1.vhd"); - IMAGE_PATH_2 = Paths.get(nbTestCase.getDataDir().toString(), "commonfiles_image2_v1.vhd"); - IMAGE_PATH_3 = Paths.get(nbTestCase.getDataDir().toString(), "commonfiles_image3_v1.vhd"); - IMAGE_PATH_4 = Paths.get(nbTestCase.getDataDir().toString(), "commonfiles_image4_v1.vhd"); + imagePath1 = Paths.get(nbTestCase.getDataDir().toString(), "commonfiles_image1_v1.vhd"); + imagePath2 = Paths.get(nbTestCase.getDataDir().toString(), "commonfiles_image2_v1.vhd"); + imagePath3 = Paths.get(nbTestCase.getDataDir().toString(), "commonfiles_image3_v1.vhd"); + imagePath4 = Paths.get(nbTestCase.getDataDir().toString(), "commonfiles_image4_v1.vhd"); this.dataSourceLoader = new DataSourceLoader(); @@ -109,10 +109,10 @@ class IntraCaseUtils { final ImageDSProcessor imageDSProcessor = new ImageDSProcessor(); - IngestUtils.addDataSource(imageDSProcessor, IMAGE_PATH_1); - IngestUtils.addDataSource(imageDSProcessor, IMAGE_PATH_2); - IngestUtils.addDataSource(imageDSProcessor, IMAGE_PATH_3); - IngestUtils.addDataSource(imageDSProcessor, IMAGE_PATH_4); + IngestUtils.addDataSource(imageDSProcessor, imagePath1); + IngestUtils.addDataSource(imageDSProcessor, imagePath2); + IngestUtils.addDataSource(imageDSProcessor, imagePath3); + IngestUtils.addDataSource(imageDSProcessor, imagePath4); } Map getDataSourceMap() throws NoCurrentCaseException, TskCoreException, SQLException{ From 61d8a6a8949511fe998f8e22b50933bcdf65be46 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Fri, 25 May 2018 09:05:30 -0600 Subject: [PATCH 29/36] lower accessibility --- .../autopsy/commonfilessearch/IntraCaseUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseUtils.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseUtils.java index 2a2a8bd7bf..66a68f3a38 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseUtils.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/IntraCaseUtils.java @@ -74,10 +74,10 @@ class IntraCaseUtils { private static final String CASE_NAME = "IntraCaseCommonFilesSearchTest"; static final Path CASE_DIRECTORY_PATH = Paths.get(System.getProperty("java.io.tmpdir"), CASE_NAME); - final Path imagePath1; - final Path imagePath2; - final Path imagePath3; - final Path imagePath4; + private final Path imagePath1; + private final Path imagePath2; + private final Path imagePath3; + private final Path imagePath4; static final String IMG = "IMG_6175.jpg"; static final String DOC = "BasicStyleGuide.doc"; From 1dc1355c1c5219926c413229447f207c57cdc0ba Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Fri, 25 May 2018 15:54:54 -0400 Subject: [PATCH 30/36] Fixing y coordinate for trend lines that don't fit on the graph. --- .../sleuthkit/autopsy/healthmonitor/TimingMetricGraphPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/healthmonitor/TimingMetricGraphPanel.java b/Core/src/org/sleuthkit/autopsy/healthmonitor/TimingMetricGraphPanel.java index 6d995ed9ac..8d4a57b4f6 100644 --- a/Core/src/org/sleuthkit/autopsy/healthmonitor/TimingMetricGraphPanel.java +++ b/Core/src/org/sleuthkit/autopsy/healthmonitor/TimingMetricGraphPanel.java @@ -373,7 +373,7 @@ class TimingMetricGraphPanel extends JPanel { } } else if (y0value > maxValueOnYAxis) { try { - y0value = minValueOnYAxis; + y0value = maxValueOnYAxis; x0value = trendLine.getXGivenY(y0value); } catch (HealthMonitorException ex) { // The exception is caused by a slope of zero on the trend line, which From ffd9da1f0d5fb10191dd56edd68da27b45aa89a0 Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Fri, 1 Jun 2018 12:25:49 -0400 Subject: [PATCH 31/36] refactor other occurance panel for intracase correlation --- .../contentviewer/ArtifactKey.java | 70 ------------------- 1 file changed, 70 deletions(-) delete mode 100644 Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/ArtifactKey.java diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/ArtifactKey.java b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/ArtifactKey.java deleted file mode 100644 index 1594456a97..0000000000 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/ArtifactKey.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Central Repository - * - * Copyright 2015-2017 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.centralrepository.contentviewer; - -import java.util.Objects; - -/** - * Used as a key to ensure we eliminate duplicates from the result set by not overwriting CR correlation instances. - */ -final class ArtifactKey { - - private final String dataSourceID; - private final String filePath; - - ArtifactKey(String theDataSource, String theFilePath) { - dataSourceID = theDataSource; - filePath = theFilePath.toLowerCase(); - } - - - /** - * - * @return the dataSourceID device ID - */ - String getDataSourceID() { - return dataSourceID; - } - - /** - * - * @return the filPath including the filename and extension. - */ - String getFilePath() { - return filePath; - } - - @Override - public boolean equals(Object other) { - if (other instanceof ArtifactKey) { - return ((ArtifactKey) other).getDataSourceID().equals(dataSourceID) && ((ArtifactKey) other).getFilePath().equals(filePath); - } - return false; - - } - - @Override - public int hashCode() { - //int hash = 7; - //hash = 67 * hash + this.dataSourceID.hashCode(); - //hash = 67 * hash + this.filePath.hashCode(); - - return Objects.hash(dataSourceID, filePath); - } -} From 0fb67b7879b58ec1bbe0516273f150ca350ad40a Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Fri, 1 Jun 2018 12:25:57 -0400 Subject: [PATCH 32/36] refactor other occurance panel for intracase correlation --- .../DataContentViewerOtherCases.java | 259 +++++++++++------- 1 file changed, 165 insertions(+), 94 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java index b1ec30b4d7..f6242df119 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java @@ -18,7 +18,9 @@ */ package org.sleuthkit.autopsy.centralrepository.contentviewer; +import java.awt.Color; import java.awt.Component; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedWriter; @@ -31,19 +33,30 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; import java.util.stream.Collectors; +import javax.swing.GroupLayout; import javax.swing.JFileChooser; +import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import static javax.swing.JOptionPane.DEFAULT_OPTION; import static javax.swing.JOptionPane.PLAIN_MESSAGE; import static javax.swing.JOptionPane.ERROR_MESSAGE; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.LayoutStyle; +import javax.swing.ListSelectionModel; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; +import org.openide.awt.Mnemonics; import org.openide.nodes.Node; +import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; import org.openide.util.lookup.ServiceProvider; import org.sleuthkit.autopsy.casemodule.Case; @@ -72,7 +85,7 @@ import org.sleuthkit.datamodel.TskData; @ServiceProvider(service = DataContentViewer.class, position = 8) @Messages({"DataContentViewerOtherCases.title=Other Occurrences", "DataContentViewerOtherCases.toolTip=Displays instances of the selected file/artifact from other occurrences.",}) -public class DataContentViewerOtherCases extends javax.swing.JPanel implements DataContentViewer { +public class DataContentViewerOtherCases extends JPanel implements DataContentViewer { private final static Logger LOGGER = Logger.getLogger(DataContentViewerOtherCases.class.getName()); @@ -451,12 +464,12 @@ public class DataContentViewerOtherCases extends javax.swing.JPanel implements D * * @return A collection of correlated artifact instances from other cases */ - private Map getCorrelatedInstances(CorrelationAttribute corAttr, String dataSourceName, String deviceId) { + private Map getCorrelatedInstances(CorrelationAttribute corAttr, String dataSourceName, String deviceId) { // @@@ Check exception try { final Case openCase = Case.getCurrentCase(); String caseUUID = openCase.getName(); - HashMap artifactInstances = new HashMap<>(); + HashMap artifactInstances = new HashMap<>(); if (EamDb.isEnabled()) { EamDb dbManager = EamDb.getInstance(); @@ -464,8 +477,7 @@ public class DataContentViewerOtherCases extends javax.swing.JPanel implements D .filter(artifactInstance -> !artifactInstance.getCorrelationCase().getCaseUUID().equals(caseUUID) || !artifactInstance.getCorrelationDataSource().getName().equals(dataSourceName) || !artifactInstance.getCorrelationDataSource().getDeviceID().equals(deviceId)) - .collect(Collectors.toMap( - correlationAttr -> new ArtifactKey(correlationAttr.getCorrelationDataSource().getDeviceID(), correlationAttr.getFilePath()), + .collect(Collectors.toMap(correlationAttr -> new UniquePathKey(correlationAttr.getCorrelationDataSource().getDeviceID(), correlationAttr.getFilePath()), correlationAttr -> correlationAttr))); } @@ -507,29 +519,49 @@ public class DataContentViewerOtherCases extends javax.swing.JPanel implements D } - private void addOrUpdateAttributeInstance(final Case openCase, Map artifactInstances, AbstractFile caseDbFile) throws TskCoreException, EamDbException { - CorrelationCase caze = new CorrelationCase(openCase.getNumber(), openCase.getDisplayName()); - CorrelationDataSource dataSource = CorrelationDataSource.fromTSKDataSource(caze, caseDbFile.getDataSource()); - String filePath = caseDbFile.getParentPath() + caseDbFile.getName(); - ArtifactKey instKey = new ArtifactKey(dataSource.getDeviceID(), filePath); - CorrelationAttributeInstance caseDbInstance = new CorrelationAttributeInstance(caze, dataSource, filePath, "", caseDbFile.getKnown()); - TskData.FileKnown knownStatus = caseDbInstance.getKnownStatus(); - // If not known, check Tags for known and set - TskData.FileKnown knownBad = TskData.FileKnown.BAD; - if (!knownStatus.equals(knownBad)) { - List fileMatchTags = openCase.getServices().getTagsManager().getContentTagsByContent(caseDbFile); + /** + * Adds the file to the artifactInstances map if it does not already exist + * + * @param autopsyCase + * @param artifactInstances + * @param newFile + * @throws TskCoreException + * @throws EamDbException + */ + private void addOrUpdateAttributeInstance(final Case autopsyCase, Map artifactInstances, AbstractFile newFile) throws TskCoreException, EamDbException { + + // figure out if the casedb file is known via either hash or tags + TskData.FileKnown localKnown = newFile.getKnown(); + + if (localKnown != TskData.FileKnown.BAD) { + List fileMatchTags = autopsyCase.getServices().getTagsManager().getContentTagsByContent(newFile); for (ContentTag tag : fileMatchTags) { TskData.FileKnown tagKnownStatus = tag.getName().getKnownStatus(); - if (tagKnownStatus.equals(knownBad)) { - caseDbInstance.setKnownStatus(knownBad); + if (tagKnownStatus.equals(TskData.FileKnown.BAD)) { + localKnown = TskData.FileKnown.BAD; break; } } } - // If known, or not in CR, add - if (caseDbInstance.getKnownStatus().equals(knownBad) || !artifactInstances.containsKey(instKey)) { - artifactInstances.put(instKey, caseDbInstance); + // make a key to see if the file is already in the hashset + CorrelationCase correlationCase = EamDb.getInstance().getCase(autopsyCase); + CorrelationDataSource correlationDataSource = CorrelationDataSource.fromTSKDataSource(correlationCase, newFile.getDataSource()); + String filePath = newFile.getParentPath() + newFile.getName(); + UniquePathKey uniquePathKey = new UniquePathKey(correlationDataSource.getDeviceID(), filePath); + + + // add it to the map if the case version is BAD (just in case the CR one didn't get the update) or if it + // is not in the map + if (localKnown == TskData.FileKnown.BAD || !artifactInstances.containsKey(uniquePathKey)) { + // make sure we grab the comment from the existing CR instance + String crComment = ""; + if (artifactInstances.containsKey(uniquePathKey)) { + crComment = artifactInstances.get(uniquePathKey).getComment(); + } + + CorrelationAttributeInstance caseDbInstance = new CorrelationAttributeInstance(correlationCase, correlationDataSource, filePath, crComment, localKnown); + artifactInstances.put(uniquePathKey, caseDbInstance); } } @@ -588,7 +620,7 @@ public class DataContentViewerOtherCases extends javax.swing.JPanel implements D // get the attributes we can correlate on correlationAttributes.addAll(getCorrelationAttributesFromNode(node)); for (CorrelationAttribute corAttr : correlationAttributes) { - Map corAttrInstances = new HashMap<>(0); + Map corAttrInstances = new HashMap<>(0); // get correlation and reference set instances from DB corAttrInstances.putAll(getCorrelatedInstances(corAttr, dataSourceName, deviceId)); @@ -645,131 +677,170 @@ public class DataContentViewerOtherCases extends javax.swing.JPanel implements D // //GEN-BEGIN:initComponents private void initComponents() { - rightClickPopupMenu = new javax.swing.JPopupMenu(); - selectAllMenuItem = new javax.swing.JMenuItem(); - exportToCSVMenuItem = new javax.swing.JMenuItem(); - showCaseDetailsMenuItem = new javax.swing.JMenuItem(); - showCommonalityMenuItem = new javax.swing.JMenuItem(); - CSVFileChooser = new javax.swing.JFileChooser(); - otherCasesPanel = new javax.swing.JPanel(); - tableContainerPanel = new javax.swing.JPanel(); - tableScrollPane = new javax.swing.JScrollPane(); - otherCasesTable = new javax.swing.JTable(); - tableStatusPanel = new javax.swing.JPanel(); - tableStatusPanelLabel = new javax.swing.JLabel(); + rightClickPopupMenu = new JPopupMenu(); + selectAllMenuItem = new JMenuItem(); + exportToCSVMenuItem = new JMenuItem(); + showCaseDetailsMenuItem = new JMenuItem(); + showCommonalityMenuItem = new JMenuItem(); + CSVFileChooser = new JFileChooser(); + otherCasesPanel = new JPanel(); + tableContainerPanel = new JPanel(); + tableScrollPane = new JScrollPane(); + otherCasesTable = new JTable(); + tableStatusPanel = new JPanel(); + tableStatusPanelLabel = new JLabel(); - org.openide.awt.Mnemonics.setLocalizedText(selectAllMenuItem, org.openide.util.NbBundle.getMessage(DataContentViewerOtherCases.class, "DataContentViewerOtherCases.selectAllMenuItem.text")); // NOI18N + Mnemonics.setLocalizedText(selectAllMenuItem, NbBundle.getMessage(DataContentViewerOtherCases.class, "DataContentViewerOtherCases.selectAllMenuItem.text")); // NOI18N rightClickPopupMenu.add(selectAllMenuItem); - org.openide.awt.Mnemonics.setLocalizedText(exportToCSVMenuItem, org.openide.util.NbBundle.getMessage(DataContentViewerOtherCases.class, "DataContentViewerOtherCases.exportToCSVMenuItem.text")); // NOI18N + Mnemonics.setLocalizedText(exportToCSVMenuItem, NbBundle.getMessage(DataContentViewerOtherCases.class, "DataContentViewerOtherCases.exportToCSVMenuItem.text")); // NOI18N rightClickPopupMenu.add(exportToCSVMenuItem); - org.openide.awt.Mnemonics.setLocalizedText(showCaseDetailsMenuItem, org.openide.util.NbBundle.getMessage(DataContentViewerOtherCases.class, "DataContentViewerOtherCases.showCaseDetailsMenuItem.text")); // NOI18N + Mnemonics.setLocalizedText(showCaseDetailsMenuItem, NbBundle.getMessage(DataContentViewerOtherCases.class, "DataContentViewerOtherCases.showCaseDetailsMenuItem.text")); // NOI18N rightClickPopupMenu.add(showCaseDetailsMenuItem); - org.openide.awt.Mnemonics.setLocalizedText(showCommonalityMenuItem, org.openide.util.NbBundle.getMessage(DataContentViewerOtherCases.class, "DataContentViewerOtherCases.showCommonalityMenuItem.text")); // NOI18N + Mnemonics.setLocalizedText(showCommonalityMenuItem, NbBundle.getMessage(DataContentViewerOtherCases.class, "DataContentViewerOtherCases.showCommonalityMenuItem.text")); // NOI18N rightClickPopupMenu.add(showCommonalityMenuItem); - setMinimumSize(new java.awt.Dimension(1500, 10)); + setMinimumSize(new Dimension(1500, 10)); setOpaque(false); - setPreferredSize(new java.awt.Dimension(1500, 44)); + setPreferredSize(new Dimension(1500, 44)); - otherCasesPanel.setPreferredSize(new java.awt.Dimension(1500, 144)); + otherCasesPanel.setPreferredSize(new Dimension(1500, 144)); - tableContainerPanel.setPreferredSize(new java.awt.Dimension(1500, 63)); + tableContainerPanel.setPreferredSize(new Dimension(1500, 63)); - tableScrollPane.setPreferredSize(new java.awt.Dimension(1500, 30)); + tableScrollPane.setPreferredSize(new Dimension(1500, 30)); otherCasesTable.setAutoCreateRowSorter(true); otherCasesTable.setModel(tableModel); - otherCasesTable.setToolTipText(org.openide.util.NbBundle.getMessage(DataContentViewerOtherCases.class, "DataContentViewerOtherCases.table.toolTip.text")); // NOI18N + otherCasesTable.setToolTipText(NbBundle.getMessage(DataContentViewerOtherCases.class, "DataContentViewerOtherCases.table.toolTip.text")); // NOI18N otherCasesTable.setComponentPopupMenu(rightClickPopupMenu); - otherCasesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); + otherCasesTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); tableScrollPane.setViewportView(otherCasesTable); - tableStatusPanel.setPreferredSize(new java.awt.Dimension(1500, 16)); + tableStatusPanel.setPreferredSize(new Dimension(1500, 16)); - tableStatusPanelLabel.setForeground(new java.awt.Color(255, 0, 51)); + tableStatusPanelLabel.setForeground(new Color(255, 0, 51)); - javax.swing.GroupLayout tableStatusPanelLayout = new javax.swing.GroupLayout(tableStatusPanel); + GroupLayout tableStatusPanelLayout = new GroupLayout(tableStatusPanel); tableStatusPanel.setLayout(tableStatusPanelLayout); - tableStatusPanelLayout.setHorizontalGroup( - tableStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + tableStatusPanelLayout.setHorizontalGroup(tableStatusPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) - .addGroup(tableStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(tableStatusPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(tableStatusPanelLayout.createSequentialGroup() .addContainerGap() - .addComponent(tableStatusPanelLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE) + .addComponent(tableStatusPanelLabel, GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE) .addContainerGap())) ); - tableStatusPanelLayout.setVerticalGroup( - tableStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + tableStatusPanelLayout.setVerticalGroup(tableStatusPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGap(0, 16, Short.MAX_VALUE) - .addGroup(tableStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(tableStatusPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(tableStatusPanelLayout.createSequentialGroup() - .addComponent(tableStatusPanelLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(tableStatusPanelLabel, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) ); - javax.swing.GroupLayout tableContainerPanelLayout = new javax.swing.GroupLayout(tableContainerPanel); + GroupLayout tableContainerPanelLayout = new GroupLayout(tableContainerPanel); tableContainerPanel.setLayout(tableContainerPanelLayout); - tableContainerPanelLayout.setHorizontalGroup( - tableContainerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(tableScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(tableStatusPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + tableContainerPanelLayout.setHorizontalGroup(tableContainerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(tableScrollPane, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(tableStatusPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); - tableContainerPanelLayout.setVerticalGroup( - tableContainerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + tableContainerPanelLayout.setVerticalGroup(tableContainerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(tableContainerPanelLayout.createSequentialGroup() - .addComponent(tableScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(tableStatusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(tableScrollPane, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(tableStatusPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); - javax.swing.GroupLayout otherCasesPanelLayout = new javax.swing.GroupLayout(otherCasesPanel); + GroupLayout otherCasesPanelLayout = new GroupLayout(otherCasesPanel); otherCasesPanel.setLayout(otherCasesPanelLayout); - otherCasesPanelLayout.setHorizontalGroup( - otherCasesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + otherCasesPanelLayout.setHorizontalGroup(otherCasesPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGap(0, 1500, Short.MAX_VALUE) - .addGroup(otherCasesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(tableContainerPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(otherCasesPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(tableContainerPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); - otherCasesPanelLayout.setVerticalGroup( - otherCasesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + otherCasesPanelLayout.setVerticalGroup(otherCasesPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGap(0, 60, Short.MAX_VALUE) - .addGroup(otherCasesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(otherCasesPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(otherCasesPanelLayout.createSequentialGroup() - .addComponent(tableContainerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE) + .addComponent(tableContainerPanel, GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE) .addGap(0, 0, 0))) ); - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + GroupLayout layout = new GroupLayout(this); this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(otherCasesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(otherCasesPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(otherCasesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE) + layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(otherCasesPanel, GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE) ); }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JFileChooser CSVFileChooser; - private javax.swing.JMenuItem exportToCSVMenuItem; - private javax.swing.JPanel otherCasesPanel; - private javax.swing.JTable otherCasesTable; - private javax.swing.JPopupMenu rightClickPopupMenu; - private javax.swing.JMenuItem selectAllMenuItem; - private javax.swing.JMenuItem showCaseDetailsMenuItem; - private javax.swing.JMenuItem showCommonalityMenuItem; - private javax.swing.JPanel tableContainerPanel; - private javax.swing.JScrollPane tableScrollPane; - private javax.swing.JPanel tableStatusPanel; - private javax.swing.JLabel tableStatusPanelLabel; + private JFileChooser CSVFileChooser; + private JMenuItem exportToCSVMenuItem; + private JPanel otherCasesPanel; + private JTable otherCasesTable; + private JPopupMenu rightClickPopupMenu; + private JMenuItem selectAllMenuItem; + private JMenuItem showCaseDetailsMenuItem; + private JMenuItem showCommonalityMenuItem; + private JPanel tableContainerPanel; + private JScrollPane tableScrollPane; + private JPanel tableStatusPanel; + private JLabel tableStatusPanelLabel; // End of variables declaration//GEN-END:variables + /** + * Used as a key to ensure we eliminate duplicates from the result set by not overwriting CR correlation instances. + */ + static final class UniquePathKey { + + private final String dataSourceID; + private final String filePath; + + UniquePathKey(String theDataSource, String theFilePath) { + super(); + dataSourceID = theDataSource; + filePath = theFilePath.toLowerCase(); + } + + /** + * + * @return the dataSourceID device ID + */ + String getDataSourceID() { + return dataSourceID; + } + + /** + * + * @return the filPath including the filename and extension. + */ + String getFilePath() { + return filePath; + } + + @Override + public boolean equals(Object other) { + if (other instanceof UniquePathKey) { + return ((UniquePathKey) other).getDataSourceID().equals(dataSourceID) && ((UniquePathKey) other).getFilePath().equals(filePath); + } + return false; + } + + @Override + public int hashCode() { + //int hash = 7; + //hash = 67 * hash + this.dataSourceID.hashCode(); + //hash = 67 * hash + this.filePath.hashCode(); + return Objects.hash(dataSourceID, filePath); + } + } + } From ae2e64ec35d07971b63c83fbfc07c1745da95e6c Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Fri, 1 Jun 2018 12:53:51 -0400 Subject: [PATCH 33/36] Added PMD supression --- .../contentviewer/DataContentViewerOtherCases.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java index f6242df119..4c4f044938 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java @@ -82,6 +82,7 @@ import org.sleuthkit.datamodel.TskData; /** * View correlation results from other cases */ +@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives @ServiceProvider(service = DataContentViewer.class, position = 8) @Messages({"DataContentViewerOtherCases.title=Other Occurrences", "DataContentViewerOtherCases.toolTip=Displays instances of the selected file/artifact from other occurrences.",}) From 47b886902af82f28c315361835aca2f945ef1c49 Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Fri, 1 Jun 2018 14:36:24 -0400 Subject: [PATCH 34/36] do not rely on EamDB for case files --- .../DataContentViewerOtherCases.java | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java index 4c4f044938..2a9fd30a49 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java @@ -78,6 +78,7 @@ import org.sleuthkit.datamodel.TskException; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskData; +import org.sleuthkit.datamodel.TskDataException; /** * View correlation results from other cases @@ -545,23 +546,33 @@ public class DataContentViewerOtherCases extends JPanel implements DataContentVi } } - // make a key to see if the file is already in the hashset - CorrelationCase correlationCase = EamDb.getInstance().getCase(autopsyCase); - CorrelationDataSource correlationDataSource = CorrelationDataSource.fromTSKDataSource(correlationCase, newFile.getDataSource()); + // make a key to see if the file is already in the map String filePath = newFile.getParentPath() + newFile.getName(); - UniquePathKey uniquePathKey = new UniquePathKey(correlationDataSource.getDeviceID(), filePath); + String deviceId; + try { + deviceId = autopsyCase.getSleuthkitCase().getDataSource(newFile.getDataSource().getId()).getDeviceId(); + } catch (TskDataException | TskCoreException ex) { + LOGGER.log(Level.WARNING, "Error getting data source info: " + ex); + return; + } + UniquePathKey uniquePathKey = new UniquePathKey(deviceId, filePath); - - // add it to the map if the case version is BAD (just in case the CR one didn't get the update) or if it - // is not in the map - if (localKnown == TskData.FileKnown.BAD || !artifactInstances.containsKey(uniquePathKey)) { - // make sure we grab the comment from the existing CR instance - String crComment = ""; - if (artifactInstances.containsKey(uniquePathKey)) { - crComment = artifactInstances.get(uniquePathKey).getComment(); + // double check that the CR version is BAD if the caseDB version is BAD. + if (artifactInstances.containsKey(uniquePathKey)) { + if (localKnown == TskData.FileKnown.BAD) { + CorrelationAttributeInstance prevInstance = artifactInstances.get(uniquePathKey); + prevInstance.setKnownStatus(localKnown); } + } + // add the data from the case DB by pushing data into CorrelationAttributeInstance class + else { + // NOTE: If we are in here, it is likely because CR is not enabled. So, we cannot rely + // on any of the methods that query the DB. + CorrelationCase correlationCase = new CorrelationCase(autopsyCase.getName(), autopsyCase.getDisplayName()); - CorrelationAttributeInstance caseDbInstance = new CorrelationAttributeInstance(correlationCase, correlationDataSource, filePath, crComment, localKnown); + CorrelationDataSource correlationDataSource = CorrelationDataSource.fromTSKDataSource(correlationCase, newFile.getDataSource()); + + CorrelationAttributeInstance caseDbInstance = new CorrelationAttributeInstance(correlationCase, correlationDataSource, filePath, "", localKnown); artifactInstances.put(uniquePathKey, caseDbInstance); } } @@ -641,6 +652,7 @@ public class DataContentViewerOtherCases extends JPanel implements DataContentVi } if (correlationAttributes.isEmpty()) { + // @@@ BC: We should have a more descriptive message than this. Mention that the file didn't have a MD5, etc. displayMessageOnTableStatusPanel(Bundle.DataContentViewerOtherCases_table_noArtifacts()); } else if (0 == tableModel.getRowCount()) { displayMessageOnTableStatusPanel(Bundle.DataContentViewerOtherCases_table_isempty()); From 78a6981983af089d638f707625c1944f3aaf0221 Mon Sep 17 00:00:00 2001 From: "U-BASIS\\dgrove" Date: Mon, 4 Jun 2018 00:13:24 -0400 Subject: [PATCH 35/36] Modified comments. --- .../autopsy/modules/embeddedfileextractor/Bundle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/Bundle.properties index c80ccaa863..5469df6f92 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/Bundle.properties @@ -9,8 +9,8 @@ OpenIDE-Module-Name=Embedded File Extraction OpenIDE-Module-Short-Description=Embedded File Extraction Ingest Module EmbeddedFileExtractorIngestModule.SevenZipContentReadStream.seek.exception.invalidOrigin=Invalid seek origin\: {0} EmbeddedFileExtractorIngestModule.SevenZipContentReadStream.read.exception.errReadStream=Error reading content stream. -EmbeddedFileExtractorIngestModule.ArchiveExtractor.encryptionFileLevel=File-level Encryption -EmbeddedFileExtractorIngestModule.ArchiveExtractor.encryptionFull=Full Encryption +EmbeddedFileExtractorIngestModule.ArchiveExtractor.encryptionFileLevel=Content-only Encryption (ZIP File) +EmbeddedFileExtractorIngestModule.ArchiveExtractor.encryptionFull=Full Encryption (ZIP File) EmbeddedFileExtractorIngestModule.ArchiveExtractor.init.errInitModule.details=Error initializing output dir\: {0}\: {1} EmbeddedFileExtractorIngestModule.ArchiveExtractor.isZipBombCheck.warnMsg=Possible ZIP bomb detected in archive\: {0}, item\: {1} EmbeddedFileExtractorIngestModule.ArchiveExtractor.isZipBombCheck.warnDetails=Compression ratio is {0}, skipping item in {1}. From 26cf84bfb2d69efaa0c2071d68f9fce9a9a3f212 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 7 Jun 2018 10:06:50 -0400 Subject: [PATCH 36/36] Update Bundle.properties Changed "ZIP" to more generic term "archive" for comment attribute of encryption detected artifacts for archive files. --- .../autopsy/modules/embeddedfileextractor/Bundle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/Bundle.properties index 5469df6f92..dfda2e6061 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/Bundle.properties @@ -9,8 +9,8 @@ OpenIDE-Module-Name=Embedded File Extraction OpenIDE-Module-Short-Description=Embedded File Extraction Ingest Module EmbeddedFileExtractorIngestModule.SevenZipContentReadStream.seek.exception.invalidOrigin=Invalid seek origin\: {0} EmbeddedFileExtractorIngestModule.SevenZipContentReadStream.read.exception.errReadStream=Error reading content stream. -EmbeddedFileExtractorIngestModule.ArchiveExtractor.encryptionFileLevel=Content-only Encryption (ZIP File) -EmbeddedFileExtractorIngestModule.ArchiveExtractor.encryptionFull=Full Encryption (ZIP File) +EmbeddedFileExtractorIngestModule.ArchiveExtractor.encryptionFileLevel=Content-only Encryption (Archive File) +EmbeddedFileExtractorIngestModule.ArchiveExtractor.encryptionFull=Full Encryption (Archive File) EmbeddedFileExtractorIngestModule.ArchiveExtractor.init.errInitModule.details=Error initializing output dir\: {0}\: {1} EmbeddedFileExtractorIngestModule.ArchiveExtractor.isZipBombCheck.warnMsg=Possible ZIP bomb detected in archive\: {0}, item\: {1} EmbeddedFileExtractorIngestModule.ArchiveExtractor.isZipBombCheck.warnDetails=Compression ratio is {0}, skipping item in {1}.