From a3d03fa0ba41d632b662a38ac51719fac02e3ca0 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Mon, 23 Jul 2018 15:10:08 -0600 Subject: [PATCH] test utils and access modifiers required for testing --- .../InterCaseCommonAttributeInstanceNode.java | 14 +- .../IntraCaseCommonAttributeInstanceNode.java | 4 +- .../commonfilessearch/InterCaseUtils.java | 143 ++++++++++++------ 3 files changed, 104 insertions(+), 57 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/InterCaseCommonAttributeInstanceNode.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/InterCaseCommonAttributeInstanceNode.java index ee9b173d3e..8f4a0d6599 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/InterCaseCommonAttributeInstanceNode.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/InterCaseCommonAttributeInstanceNode.java @@ -57,7 +57,7 @@ public class InterCaseCommonAttributeInstanceNode extends DisplayableItemNode { this.md5Reference = md5Reference; } - public CorrelationAttributeInstance getCentralRepoFile(){ + public CorrelationAttributeInstance getCorrelationAttributeInstance(){ return this.crFile; } @@ -101,24 +101,24 @@ public class InterCaseCommonAttributeInstanceNode extends DisplayableItemNode { sheet.put(sheetSet); } - final CorrelationAttributeInstance centralRepoFile = this.getCentralRepoFile(); + final CorrelationAttributeInstance centralRepoFile = this.getCorrelationAttributeInstance(); final String fullPath = centralRepoFile.getFilePath(); final File file = new File(fullPath); - + final String caseName = centralRepoFile.getCorrelationCase().getDisplayName(); - + final String name = file.getName(); final String parent = file.getParent(); - - final String caseQualifiedDataSource = centralRepoFile.getCorrelationDataSource().getName(); + + final String dataSourceName = centralRepoFile.getCorrelationDataSource().getName(); final String NO_DESCR = Bundle.CommonFilesSearchResultsViewerTable_noDescText(); sheetSet.put(new NodeProperty<>(org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_filesColLbl(), org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_filesColLbl(), NO_DESCR, name)); sheetSet.put(new NodeProperty<>(org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_pathColLbl(), org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_pathColLbl(), NO_DESCR, parent)); sheetSet.put(new NodeProperty<>(org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_hashsetHitsColLbl(), org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_hashsetHitsColLbl(), NO_DESCR, "")); - sheetSet.put(new NodeProperty<>(org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_dataSourceColLbl(), org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_dataSourceColLbl(), NO_DESCR, caseQualifiedDataSource)); + sheetSet.put(new NodeProperty<>(org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_dataSourceColLbl(), org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_dataSourceColLbl(), NO_DESCR, dataSourceName)); sheetSet.put(new NodeProperty<>(org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_mimeTypeColLbl(), org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_mimeTypeColLbl(), NO_DESCR, "")); sheetSet.put(new NodeProperty<>(org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_caseColLbl1(), org.sleuthkit.autopsy.commonfilesearch.Bundle.CommonFilesSearchResultsViewerTable_caseColLbl1(), NO_DESCR, caseName)); diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/IntraCaseCommonAttributeInstanceNode.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/IntraCaseCommonAttributeInstanceNode.java index f977e72d88..b433be2848 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/IntraCaseCommonAttributeInstanceNode.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/IntraCaseCommonAttributeInstanceNode.java @@ -63,11 +63,11 @@ public class IntraCaseCommonAttributeInstanceNode extends FileNode { return visitor.visit(this); } - String getCase(){ + public String getCase(){ return this.caseName; } - String getDataSource() { + public String getDataSource() { return this.dataSource; } diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/InterCaseUtils.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/InterCaseUtils.java index 5bc7ac8b72..c385daa789 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/InterCaseUtils.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/commonfilessearch/InterCaseUtils.java @@ -6,7 +6,7 @@ * 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 not use this testFile except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 @@ -47,47 +47,54 @@ import org.sleuthkit.autopsy.testutils.IngestUtils; import org.sleuthkit.datamodel.TskCoreException; import org.python.icu.impl.Assert; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance; import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationCase; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; +import org.sleuthkit.autopsy.commonfilesearch.AbstractCommonAttributeInstanceNode; import org.sleuthkit.autopsy.commonfilesearch.CommonAttributeSearchResults; import org.sleuthkit.autopsy.commonfilesearch.DataSourceLoader; import org.sleuthkit.autopsy.commonfilesearch.CommonAttributeValue; +import org.sleuthkit.autopsy.commonfilesearch.InterCaseCommonAttributeInstanceNode; +import org.sleuthkit.autopsy.commonfilesearch.InterCaseCommonAttributeSearchResults; +import org.sleuthkit.autopsy.commonfilesearch.IntraCaseCommonAttributeInstanceNode; +import org.sleuthkit.autopsy.datamodel.DisplayableItemNode; +import org.sleuthkit.datamodel.AbstractFile; /** * Utilities for testing intercase correlation feature. * * Description of Test Data: - * (Note: files of the same name and extension are identical; - * files of the same name and differing extension are not identical.) - * - * Case 1 - * +Data Set 1 - * - Hash-0.dat [file of size 0] - * - Hash-A.jpg - * - Hash-A.pdf - * +Data Set2 - * - Hash-0.dat [file of size -0] - * - Hash-A.jpg - * - Hash-A.pdf - * Case 2 - * +Data Set 1 - * - Hash-A.jpg - * - Hash-A.pdf - * +Data Set 2 - * - Hash-A.jpg - * - Hash-A.pdf - * - Hash_D.doc - * Case 3 - * +Data Set 1 - * - Hash-A.jpg - * - Hash-A.pdf - * - Hash-C.jpg [we should never find these!] - * - Hash-C.pdf [we should never find these!] - * - Hash-D.jpg - * +Data Set 2 - * - Hash-C.jpg [we should never find these!] - * - Hash-C.pdf - * - Hash.D-doc + (Note: files of the same name and extension are identical; + files of the same name and differing extension are not identical.) + + Case 1 + +Data Set 1 + - Hash-0.dat [testFile of size 0] + - Hash-A.jpg + - Hash-A.pdf + +Data Set2 + - Hash-0.dat [testFile of size -0] + - Hash-A.jpg + - Hash-A.pdf + Case 2 + +Data Set 1 + - Hash-A.jpg + - Hash-A.pdf + +Data Set 2 + - Hash-A.jpg + - Hash-A.pdf + - Hash_D.doc + Case 3 + +Data Set 1 + - Hash-A.jpg + - Hash-A.pdf + - Hash-C.jpg [we should never find these!] + - Hash-C.pdf [we should never find these!] + - Hash-D.jpg + +Data Set 2 + - Hash-C.jpg [we should never find these!] + - Hash-C.pdf + - Hash.D-doc */ class InterCaseUtils { @@ -291,26 +298,66 @@ class InterCaseUtils { int tally = 0; - for(Map.Entry> file : searchDomain.getValues().entrySet()){ + for(Map.Entry> entry : searchDomain.getValues().entrySet()){ - //Collection fileInstances = file.getValue(); - -// for(IntraCaseCommonAttributeSearchResults fileInstance : fileInstances){ -// -// -// } + for(CommonAttributeValue values : entry.getValue()){ + + for(AbstractCommonAttributeInstanceNode commonAttribute : values.getMetadata()){ + + if(commonAttribute instanceof InterCaseCommonAttributeSearchResults){ + InterCaseCommonAttributeSearchResults results = (InterCaseCommonAttributeSearchResults) commonAttribute; + for (DisplayableItemNode din : results.generateNodes()){ + + if(din instanceof InterCaseCommonAttributeInstanceNode){ + + InterCaseCommonAttributeInstanceNode node = (InterCaseCommonAttributeInstanceNode) din; + CorrelationAttributeInstance instance = node.getCorrelationAttributeInstance(); + + final String fullPath = instance.getFilePath(); + final File testFile = new File(fullPath); + + final String testCaseName = instance.getCorrelationCase().getDisplayName(); + + final String testFileName = testFile.getName(); + + final String testDataSource = instance.getCorrelationDataSource().getName(); + + boolean sameFileName = testFileName.equalsIgnoreCase(fileName); + boolean sameDataSource = testDataSource.equalsIgnoreCase(dataSource); + boolean sameCrCase = testCaseName.equalsIgnoreCase(crCase); + + if( sameFileName && sameDataSource && sameCrCase){ + tally++; + } + } + + if(din instanceof IntraCaseCommonAttributeInstanceNode){ + + IntraCaseCommonAttributeInstanceNode node = (IntraCaseCommonAttributeInstanceNode) din; + AbstractFile file = node.getContent(); + + final String testFileName = file.getName(); + final String testCaseName = node.getCase(); + final String testDataSource = node.getDataSource(); + + boolean sameFileName = testFileName.equalsIgnoreCase(fileName); + boolean sameCaseName = testCaseName.equalsIgnoreCase(crCase); + boolean sameDataSource = testDataSource.equalsIgnoreCase(dataSource); + + if(sameFileName && sameDataSource && sameCaseName){ + tally++; + } + } + } + } else { + Assert.fail("Unable to cast AbstractCommonAttributeInstanceNode to InterCaseCommonAttributeSearchResults."); + } + } + } } - return false; + return tally == instanceCount; } - - static Map mapFileInstancesToDataSource(CommonAttributeSearchResults metadata){ - return IntraCaseUtils.mapFileInstancesToDataSources(metadata); - } - -// static List getFiles(Set md5s){ -// -// } /** * Close the currently open case, delete the case directory, delete the