diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index 64aab0b6e3..655e5c29d1 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -35,7 +35,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.logging.Level; -import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; import static org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil.updateSchemaVersion; import org.sleuthkit.autopsy.coreutils.Logger; @@ -1289,8 +1288,6 @@ abstract class AbstractSqlEamDb implements EamDb { public CorrelationAttributeInstance getCorrelationAttributeInstance(CorrelationAttributeInstance.Type type, CorrelationCase correlationCase, CorrelationDataSource correlationDataSource, String value, String filePath) throws EamDbException, CorrelationAttributeNormalizationException { - String normalizedValue = CorrelationAttributeNormalizer.normalize(type, value); - if (correlationCase == null) { throw new EamDbException("Correlation case is null"); } @@ -1308,6 +1305,8 @@ abstract class AbstractSqlEamDb implements EamDb { CorrelationAttributeInstance correlationAttributeInstance = null; try { + String normalizedValue = CorrelationAttributeNormalizer.normalize(type, value); + String tableName = EamDbUtil.correlationTypeToInstanceTableName(type); String sql = "SELECT id, known_status, comment FROM " diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/InterCaseSearchResultsProcessor.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/InterCaseSearchResultsProcessor.java index 01b83e9029..077e9eb0f6 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/InterCaseSearchResultsProcessor.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/InterCaseSearchResultsProcessor.java @@ -26,7 +26,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; -import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance; import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeNormalizationException; diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDatamodelTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDatamodelTest.java index 8a4b239117..d8b356a2e8 100755 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDatamodelTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDatamodelTest.java @@ -287,9 +287,9 @@ public class CentralRepoDatamodelTest extends TestCase { // Try to update artifact with two CorrelationAttributeInstance instances try { - CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(randomHash(), fileType, case1, dataSource1fromCase1, "badPath", + CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(randomHash(), fileType, case1, dataSource1fromCase1, BAD_PATH, "", TskData.FileKnown.KNOWN); - CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(randomHash(), fileType, case1, dataSource1fromCase2, "badPath", + CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(randomHash(), fileType, case1, dataSource1fromCase2, BAD_PATH, "", TskData.FileKnown.KNOWN); EamDb.getInstance().setAttributeInstanceKnownStatus(attr1, TskData.FileKnown.BAD); @@ -308,7 +308,7 @@ public class CentralRepoDatamodelTest extends TestCase { // Try to update artifact with null known status try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance(randomHash(), fileType, case1, dataSource1fromCase1, "badPath", + CorrelationAttributeInstance attr = new CorrelationAttributeInstance(randomHash(), fileType, case1, dataSource1fromCase1, BAD_PATH, "", TskData.FileKnown.KNOWN); EamDb.getInstance().setAttributeInstanceKnownStatus(attr, null); @@ -322,7 +322,7 @@ public class CentralRepoDatamodelTest extends TestCase { // Try to update artifact with null case try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance(randomHash(), fileType, null, dataSource1fromCase1, "badPath", + CorrelationAttributeInstance attr = new CorrelationAttributeInstance(randomHash(), fileType, null, dataSource1fromCase1, BAD_PATH, "", TskData.FileKnown.KNOWN); EamDb.getInstance().setAttributeInstanceKnownStatus(attr, TskData.FileKnown.BAD); @@ -336,7 +336,7 @@ public class CentralRepoDatamodelTest extends TestCase { // Try to update artifact with null data source try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance(randomHash(), fileType, case1, null, "badPath", + CorrelationAttributeInstance attr = new CorrelationAttributeInstance(randomHash(), fileType, case1, null, BAD_PATH, "", TskData.FileKnown.KNOWN); EamDb.getInstance().setAttributeInstanceKnownStatus(attr, TskData.FileKnown.BAD); @@ -372,6 +372,7 @@ public class CentralRepoDatamodelTest extends TestCase { fail("getArtifactInstancesKnownBad failed to throw exception for null type"); } catch (CorrelationAttributeNormalizationException ex) { // This is the expected behavior + assertTrue("This is the expected behavior.", true); } catch (EamDbException ex) { Exceptions.printStackTrace(ex); fail("should have got CentralRepoValidationException"); @@ -468,6 +469,7 @@ public class CentralRepoDatamodelTest extends TestCase { // This is the expected behavior } } + private static final String BAD_PATH = "badPath"; /** * Test the methods associated with bulk artifacts (addAttributeInstanceBulk and @@ -587,7 +589,7 @@ public class CentralRepoDatamodelTest extends TestCase { // Test preparing artifact with null path // CorrelationAttributeInstance will throw an exception try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance(randomHash(), fileType, case1, dataSource1fromCase1, null); + new CorrelationAttributeInstance(randomHash(), fileType, case1, dataSource1fromCase1, null); fail("CorrelationAttributeInstance failed to throw exception for null path"); } catch (EamDbException ex) { // This is the expected behavior @@ -790,7 +792,7 @@ public class CentralRepoDatamodelTest extends TestCase { // Test adding instance with null case try { - CorrelationAttributeInstance failAttrInst = new CorrelationAttributeInstance("badInstances", fileType, null, dataSource1fromCase2, "badPath"); + CorrelationAttributeInstance failAttrInst = new CorrelationAttributeInstance("badInstances", fileType, null, dataSource1fromCase2, BAD_PATH); EamDb.getInstance().addArtifactInstance(failAttrInst); fail("addArtifact failed to throw exception for null case"); } catch (EamDbException ex) { @@ -802,7 +804,7 @@ public class CentralRepoDatamodelTest extends TestCase { // Test adding instance with invalid case ID try { CorrelationCase badCase = new CorrelationCase("badCaseUuid", "badCaseName"); - CorrelationAttributeInstance failAttrInst2 = new CorrelationAttributeInstance(randomHash(), fileType, badCase, dataSource1fromCase2, "badPath"); + CorrelationAttributeInstance failAttrInst2 = new CorrelationAttributeInstance(randomHash(), fileType, badCase, dataSource1fromCase2, BAD_PATH); EamDb.getInstance().addArtifactInstance(failAttrInst2); fail("addArtifact failed to throw exception for invalid case"); } catch (EamDbException ex) { @@ -813,7 +815,7 @@ public class CentralRepoDatamodelTest extends TestCase { // Test adding instance with null data source try { - CorrelationAttributeInstance failAttrInst3 = new CorrelationAttributeInstance(randomHash(), fileType, case1, null, "badPath"); + CorrelationAttributeInstance failAttrInst3 = new CorrelationAttributeInstance(randomHash(), fileType, case1, null, BAD_PATH); EamDb.getInstance().addArtifactInstance(failAttrInst3); fail("addArtifact failed to throw exception for null data source"); } catch (EamDbException ex) { @@ -825,7 +827,7 @@ public class CentralRepoDatamodelTest extends TestCase { // Test adding instance with invalid data source ID try { CorrelationDataSource badDS = new CorrelationDataSource(case1, "badDSUuid", "badDSName"); - CorrelationAttributeInstance failAttrInst4 = new CorrelationAttributeInstance(randomHash(), fileType, case1, badDS, "badPath"); + CorrelationAttributeInstance failAttrInst4 = new CorrelationAttributeInstance(randomHash(), fileType, case1, badDS, BAD_PATH); EamDb.getInstance().addArtifactInstance(failAttrInst4); fail("addArtifact failed to throw exception for invalid data source"); } catch (EamDbException ex) { diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationAttributeNormalizerTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationAttributeNormalizerTest.java index a5d6c81022..a3e232b57b 100644 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationAttributeNormalizerTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationAttributeNormalizerTest.java @@ -174,7 +174,7 @@ public class CorrelationAttributeNormalizerTest extends NbTestCase { final String badEmailThree = ""; //should fail final String badEmailFour = null; //should fail final String badEmailFive = "asdf"; //should fail - final String badEmailSix = "asdf@asdf"; //TODO looks bad but the lib accepts it... + final String goodEmailSix = "asdf@asdf"; //TODO looks bad but the lib accepts it... final String badEmailSeven = "asdf.asdf"; //should final int EMAIL_TYPE_ID = CorrelationAttributeInstance.EMAIL_TYPE_ID; @@ -209,12 +209,13 @@ public class CorrelationAttributeNormalizerTest extends NbTestCase { } catch (CorrelationAttributeNormalizationException ex) { assertTrue(WE_EXPECT_AN_EXCEPTION_HERE, true); } -// try { //TODO consider a better library? -// CorrelationAttributeNormalizer.normalize(EMAIL_TYPE_ID, badEmailSix); -// fail("This should have thrown an exception."); //TODO do we need a better library? -// } catch (CorrelationAttributeNormalizationException ex) { -// assertTrue("We expect an exception here.", true); -// } + try { //TODO consider a better library? + assertTrue("This email should pass", CorrelationAttributeNormalizer.normalize(EMAIL_TYPE_ID, goodEmailSix).equals(goodEmailSix)); + fail("This should have thrown an exception."); + } catch (CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + fail(ex.getMessage()); + } try { CorrelationAttributeNormalizer.normalize(EMAIL_TYPE_ID, badEmailSeven); fail(THIS_SHOULD_HAVE_THROWN_AN_EXCEPTION);