From c9e804cd790fd2c7cab2ed013acccbf1f80d744f Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Thu, 27 Sep 2018 11:29:22 -0400 Subject: [PATCH 01/70] 4242 fix comparisons in CentralRepoDatamodelTest.testArtifacts --- .../datamodel/CentralRepoDatamodelTest.java | 1310 +++++++++-------- 1 file changed, 658 insertions(+), 652 deletions(-) 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 da5bb330fa..944dd7272e 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 @@ -88,109 +88,109 @@ public class CentralRepoDatamodelTest extends TestCase { @Override public void setUp() { -// dbSettingsSqlite = new SqliteEamDbSettings(); -// -// // Delete the test directory, if it exists -// if (testDirectory.toFile().exists()) { -// try { -// FileUtils.deleteDirectory(testDirectory.toFile()); -// } catch (IOException ex) { -// Assert.fail(ex.getMessage()); -// } -// } -// assertFalse("Unable to delete existing test directory", testDirectory.toFile().exists()); -// -// // Create the test directory -// testDirectory.toFile().mkdirs(); -// assertTrue("Unable to create test directory", testDirectory.toFile().exists()); -// -// // Save the current central repo settings -// propertiesMap = ModuleSettings.getConfigSettings(PROPERTIES_FILE); -// -// try { -// dbSettingsSqlite.setDbName(CR_DB_NAME); -// dbSettingsSqlite.setDbDirectory(testDirectory.toString()); -// if (!dbSettingsSqlite.dbDirectoryExists()) { -// dbSettingsSqlite.createDbDirectory(); -// } -// -// assertTrue("Failed to created central repo directory " + dbSettingsSqlite.getDbDirectory(), dbSettingsSqlite.dbDirectoryExists()); -// -// boolean result = dbSettingsSqlite.initializeDatabaseSchema() -// && dbSettingsSqlite.insertDefaultDatabaseContent(); -// -// assertTrue("Failed to initialize central repo database", result); -// -// dbSettingsSqlite.saveSettings(); -// EamDbUtil.setUseCentralRepo(true); -// EamDbPlatformEnum.setSelectedPlatform(EamDbPlatformEnum.SQLITE.name()); -// EamDbPlatformEnum.saveSelectedPlatform(); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail(ex.getMessage()); -// } -// -// Path crDbFilePath = Paths.get(testDirectory.toString(), CR_DB_NAME); -// assertTrue("Failed to create central repo database at " + crDbFilePath, crDbFilePath.toFile().exists()); -// -// // Set up some default objects to be used by the tests -// try { -// case1 = new CorrelationCase("case1_uuid", "case1"); -// case1 = EamDb.getInstance().newCase(case1); -// assertTrue("Failed to create test object case1", case1 != null); -// -// case2 = new CorrelationCase("case2_uuid", "case2"); -// case2 = EamDb.getInstance().newCase(case2); -// assertTrue("Failed to create test object case2", case2 != null); -// -// dataSource1fromCase1 = new CorrelationDataSource(case1, "dataSource1_deviceID", "dataSource1"); -// EamDb.getInstance().newDataSource(dataSource1fromCase1); -// dataSource1fromCase1 = EamDb.getInstance().getDataSource(case1, dataSource1fromCase1.getDeviceID()); -// assertTrue("Failed to create test object dataSource1fromCase1", dataSource1fromCase1 != null); -// -// dataSource2fromCase1 = new CorrelationDataSource(case1, "dataSource2_deviceID", "dataSource2"); -// EamDb.getInstance().newDataSource(dataSource2fromCase1); -// dataSource2fromCase1 = EamDb.getInstance().getDataSource(case1, dataSource2fromCase1.getDeviceID()); -// assertTrue("Failed to create test object dataSource2fromCase1", dataSource2fromCase1 != null); -// -// dataSource1fromCase2 = new CorrelationDataSource(case2, "dataSource3_deviceID", "dataSource3"); -// EamDb.getInstance().newDataSource(dataSource1fromCase2); -// dataSource1fromCase2 = EamDb.getInstance().getDataSource(case2, dataSource1fromCase2.getDeviceID()); -// assertTrue("Failed to create test object dataSource1fromCase2", dataSource1fromCase2 != null); -// -// org1 = new EamOrganization("org1"); -// org1 = EamDb.getInstance().newOrganization(org1); -// -// org2 = new EamOrganization("org2"); -// org2 = EamDb.getInstance().newOrganization(org2); -// -// // Store the file type object for later use -// fileType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID); -// assertTrue("getCorrelationTypeById(FILES_TYPE_ID) returned null", fileType != null); -// usbDeviceType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.USBID_TYPE_ID); -// assertTrue("getCorrelationTypeById(USBID_TYPE_ID) returned null", usbDeviceType != null); -// -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail(ex.getMessage()); -// } + dbSettingsSqlite = new SqliteEamDbSettings(); + + // Delete the test directory, if it exists + if (testDirectory.toFile().exists()) { + try { + FileUtils.deleteDirectory(testDirectory.toFile()); + } catch (IOException ex) { + Assert.fail(ex.getMessage()); + } + } + assertFalse("Unable to delete existing test directory", testDirectory.toFile().exists()); + + // Create the test directory + testDirectory.toFile().mkdirs(); + assertTrue("Unable to create test directory", testDirectory.toFile().exists()); + + // Save the current central repo settings + propertiesMap = ModuleSettings.getConfigSettings(PROPERTIES_FILE); + + try { + dbSettingsSqlite.setDbName(CR_DB_NAME); + dbSettingsSqlite.setDbDirectory(testDirectory.toString()); + if (!dbSettingsSqlite.dbDirectoryExists()) { + dbSettingsSqlite.createDbDirectory(); + } + + assertTrue("Failed to created central repo directory " + dbSettingsSqlite.getDbDirectory(), dbSettingsSqlite.dbDirectoryExists()); + + boolean result = dbSettingsSqlite.initializeDatabaseSchema() + && dbSettingsSqlite.insertDefaultDatabaseContent(); + + assertTrue("Failed to initialize central repo database", result); + + dbSettingsSqlite.saveSettings(); + EamDbUtil.setUseCentralRepo(true); + EamDbPlatformEnum.setSelectedPlatform(EamDbPlatformEnum.SQLITE.name()); + EamDbPlatformEnum.saveSelectedPlatform(); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + Assert.fail(ex.getMessage()); + } + + Path crDbFilePath = Paths.get(testDirectory.toString(), CR_DB_NAME); + assertTrue("Failed to create central repo database at " + crDbFilePath, crDbFilePath.toFile().exists()); + + // Set up some default objects to be used by the tests + try { + case1 = new CorrelationCase("case1_uuid", "case1"); + case1 = EamDb.getInstance().newCase(case1); + assertTrue("Failed to create test object case1", case1 != null); + + case2 = new CorrelationCase("case2_uuid", "case2"); + case2 = EamDb.getInstance().newCase(case2); + assertTrue("Failed to create test object case2", case2 != null); + + dataSource1fromCase1 = new CorrelationDataSource(case1, "dataSource1_deviceID", "dataSource1"); + EamDb.getInstance().newDataSource(dataSource1fromCase1); + dataSource1fromCase1 = EamDb.getInstance().getDataSource(case1, dataSource1fromCase1.getDeviceID()); + assertTrue("Failed to create test object dataSource1fromCase1", dataSource1fromCase1 != null); + + dataSource2fromCase1 = new CorrelationDataSource(case1, "dataSource2_deviceID", "dataSource2"); + EamDb.getInstance().newDataSource(dataSource2fromCase1); + dataSource2fromCase1 = EamDb.getInstance().getDataSource(case1, dataSource2fromCase1.getDeviceID()); + assertTrue("Failed to create test object dataSource2fromCase1", dataSource2fromCase1 != null); + + dataSource1fromCase2 = new CorrelationDataSource(case2, "dataSource3_deviceID", "dataSource3"); + EamDb.getInstance().newDataSource(dataSource1fromCase2); + dataSource1fromCase2 = EamDb.getInstance().getDataSource(case2, dataSource1fromCase2.getDeviceID()); + assertTrue("Failed to create test object dataSource1fromCase2", dataSource1fromCase2 != null); + + org1 = new EamOrganization("org1"); + org1 = EamDb.getInstance().newOrganization(org1); + + org2 = new EamOrganization("org2"); + org2 = EamDb.getInstance().newOrganization(org2); + + // Store the file type object for later use + fileType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID); + assertTrue("getCorrelationTypeById(FILES_TYPE_ID) returned null", fileType != null); + usbDeviceType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.USBID_TYPE_ID); + assertTrue("getCorrelationTypeById(USBID_TYPE_ID) returned null", usbDeviceType != null); + + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + Assert.fail(ex.getMessage()); + } } @Override public void tearDown() { -// -// // Restore the original properties -// ModuleSettings.setConfigSettings(PROPERTIES_FILE, propertiesMap); -// -// // Close and delete the test case and central repo db -// try { -// EamDb.getInstance().shutdownConnections(); -// FileUtils.deleteDirectory(testDirectory.toFile()); -// } catch (EamDbException | IOException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail(ex.getMessage()); -// } -// assertFalse("Error deleting test directory " + testDirectory.toString(), testDirectory.toFile().exists()); + + // Restore the original properties + ModuleSettings.setConfigSettings(PROPERTIES_FILE, propertiesMap); + + // Close and delete the test case and central repo db + try { + EamDb.getInstance().shutdownConnections(); + FileUtils.deleteDirectory(testDirectory.toFile()); + } catch (EamDbException | IOException ex) { + Exceptions.printStackTrace(ex); + Assert.fail(ex.getMessage()); + } + assertFalse("Error deleting test directory " + testDirectory.toString(), testDirectory.toFile().exists()); } /** @@ -659,559 +659,565 @@ public class CentralRepoDatamodelTest extends TestCase { * with null type - Test with null value */ public void testArtifacts() { -// -// //the hash value of all 0s has not been inserted -// final String unusedHashValue = "00000000000000000000000000000000"; -// -// String inAllDataSourcesHash = "6cddb0e31787b79cfdcc0676b98a71ce"; -// String inAllDataSourcesPath = "C:\\files\\path0.txt"; -// String inDataSource1twiceHash = "b2f5ff47436671b6e533d8dc3614845d"; -// String inDataSource1twicePath1 = "C:\\files\\path1.txt"; -// String inDataSource1twicePath2 = "C:\\files\\path2.txt"; -// String onlyInDataSource3Hash = "2af54305f183778d87de0c70c591fae4"; -// String onlyInDataSource3Path = "C:\\files\\path3.txt"; -// String callbackTestFilePath1 = "C:\\files\\processinstancecallback\\path1.txt"; -// String callbackTestFilePath2 = "C:\\files\\processinstancecallback\\path2.txt"; -// String callbackTestFileHash = "fb9dd8f04dacd3e82f4917f1a002223c"; -// -// // These will all go in dataSource1fromCase1 -// String emailValue = "test@gmail.com"; -// String emailPath = "C:\\files\\emailPath.txt"; -// String phoneValue = "202-555-1234"; -// String phonePath = "C:\\files\\phonePath.txt"; -// String domainValue = "www.mozilla.com"; -// String domainPath = "C:\\files\\domainPath.txt"; -// String devIdValue = "94B21234"; -// String devIdPath = "C:\\files\\devIdPath.txt"; -// -// // Store the email type -// CorrelationAttributeInstance.Type emailType; //used again for other portions of this test -// try { -// emailType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.EMAIL_TYPE_ID); -// assertEquals("Unexpected Correlation Type retrieved for Email type id", CorrelationAttributeInstance.EMAIL_TYPE_ID, emailType.getId()); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error thrown while attempting to get email attribute " + ex.getMessage()); -// return; -// } -// -// // Test adding attribute with one instance -// try { -// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(onlyInDataSource3Hash, fileType, case2, dataSource1fromCase2, onlyInDataSource3Path); -// EamDb.getInstance().addArtifactInstance(attr); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error thrown while attempting to add file attribute from single datasource the first time " + ex.getMessage()); -// } -// -// // Test adding attribute with an instance in each data source -// try { -// CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case1, dataSource1fromCase1, inAllDataSourcesPath); -// EamDb.getInstance().addArtifactInstance(attr1); -// CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case1, dataSource2fromCase1, inAllDataSourcesPath); -// EamDb.getInstance().addArtifactInstance(attr2); -// CorrelationAttributeInstance attr3 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case2, dataSource1fromCase2, inAllDataSourcesPath); -// EamDb.getInstance().addArtifactInstance(attr3); -// -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error thrown while attempting to add file attribute from all 3 datasources " + ex.getMessage()); -// } -// -// // Test adding attribute with two instances in one data source -// try { -// CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(inDataSource1twiceHash, fileType, case1, dataSource1fromCase1, inDataSource1twicePath1); -// EamDb.getInstance().addArtifactInstance(attr1); -// CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(inDataSource1twiceHash, fileType, case1, dataSource1fromCase1, inDataSource1twicePath2); -// EamDb.getInstance().addArtifactInstance(attr2); -// -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error thrown while attempting to add file attribute from single datasource the second time " + ex.getMessage()); -// } -// -// // Test adding the other types -// // Test adding an email artifact -// try { -// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(emailValue, emailType, case1, dataSource1fromCase1, emailPath); -// EamDb.getInstance().addArtifactInstance(attr); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error thrown while attempting to add email attribute from single datasource " + ex.getMessage()); -// } -// -// // Test adding a phone artifact -// try { -// CorrelationAttributeInstance attr = new CorrelationAttributeInstance( -// phoneValue, -// EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.PHONE_TYPE_ID), -// case1, dataSource1fromCase1, phonePath); -// -// EamDb.getInstance().addArtifactInstance(attr); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error thrown while attempting to add phone attribute from single datasource " + ex.getMessage()); -// } -// -// // Test adding a domain artifact -// try { -// CorrelationAttributeInstance.Type type = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.DOMAIN_TYPE_ID); -// assertEquals("Unexpected Correlation Type retrieved for Domain type id", CorrelationAttributeInstance.DOMAIN_TYPE_ID, type.getId()); -// CorrelationAttributeInstance attr = new CorrelationAttributeInstance( -// domainValue, -// type, -// case1, dataSource1fromCase1, domainPath); -// EamDb.getInstance().addArtifactInstance(attr); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error thrown while attempting to add domain attribute from single datasource " + ex.getMessage()); -// } -// -// // Test adding a device ID artifact -// try { -// CorrelationAttributeInstance attr = new CorrelationAttributeInstance( -// devIdValue, -// EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.USBID_TYPE_ID), -// case1, dataSource1fromCase1, devIdPath); -// -// EamDb.getInstance().addArtifactInstance(attr); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error thrown while attempting to add device ID attribute from single datasource " + ex.getMessage()); -// } -// -// // Test CorrelationAttributeInstance creation -// try { -// new CorrelationAttributeInstance(fileType, randomHash()); -// } catch (CorrelationAttributeNormalizationException | EamDbException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Creating correlation attribute instance " + ex.getMessage()); -// } -// -// // Test adding instance with null case -// try { -// CorrelationAttributeInstance failAttrInst = new CorrelationAttributeInstance("badInstances", fileType, null, dataSource1fromCase2, BAD_PATH); -// EamDb.getInstance().addArtifactInstance(failAttrInst); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null case and was not"); -// } catch (EamDbException ex) { -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null case, EamDbException was thrown instead " + ex.getMessage()); -// } catch (CorrelationAttributeNormalizationException ex) { -// // This is the expected behavior -// } -// -// // Test adding instance with invalid case ID -// try { -// CorrelationCase badCase = new CorrelationCase("badCaseUuid", "badCaseName"); -// CorrelationAttributeInstance failAttrInst2 = new CorrelationAttributeInstance(randomHash(), fileType, badCase, dataSource1fromCase2, BAD_PATH); -// EamDb.getInstance().addArtifactInstance(failAttrInst2); -// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid case ID and was not"); -// } catch (EamDbException ex) { -// // This is the expected behavior -// } catch (CorrelationAttributeNormalizationException ex) { -// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid case ID, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); -// } -// -// // Test adding instance with null data source -// try { -// CorrelationAttributeInstance failAttrInst3 = new CorrelationAttributeInstance(randomHash(), fileType, case1, null, BAD_PATH); -// EamDb.getInstance().addArtifactInstance(failAttrInst3); -// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null data source and was not"); -// } catch (EamDbException ex) { -// // This is the expected behavior -// } catch (CorrelationAttributeNormalizationException ex) { -// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null data source, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); -// } -// -// // Test adding instance with invalid data source ID -// try { -// CorrelationDataSource badDS = new CorrelationDataSource(case1, "badDSUuid", "badDSName"); -// CorrelationAttributeInstance failAttrInst4 = new CorrelationAttributeInstance(randomHash(), fileType, case1, badDS, BAD_PATH); -// EamDb.getInstance().addArtifactInstance(failAttrInst4); -// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid data source ID and was not"); -// } catch (EamDbException ex) { -// // This is the expected behavior -// } catch (CorrelationAttributeNormalizationException ex) { -// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid data source ID, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); -// } -// -// // Test adding instance with null path -// // This will fail in the CorrelationAttributeInstance constructor -// try { -// new CorrelationAttributeInstance(randomHash(), fileType, case1, dataSource1fromCase1, null); -// fail("Error EamDbException was expected to be thrown making a CorrelationAttributeInstance with null path and was not"); -// } catch (EamDbException ex) { -// // This is the expected behavior -// } catch (CorrelationAttributeNormalizationException ex) { -// fail("Error EamDbException was expected to be thrown making a CorrelationAttributeInstance with null path, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); -// } -// -// // Test adding instance with null known status -// try { -// CorrelationAttributeInstance failAttrInst5 = new CorrelationAttributeInstance("badInstances", fileType, case1, dataSource1fromCase1, null, "comment", null); -// EamDb.getInstance().addArtifactInstance(failAttrInst5); -// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null known status and was not"); -// } catch (EamDbException ex) { -// // This is the expected behavior -// } catch (CorrelationAttributeNormalizationException ex) { -// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null known status, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); -// } -// -// // Test CorrelationAttribute failure cases -// // Test null type -// try { -// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(null, randomHash()); -// EamDb.getInstance().addArtifactInstance(attr); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null type and was not"); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null type, EamDbException was thrown instead " + ex.getMessage()); -// } catch (CorrelationAttributeNormalizationException ex) { -// // This is the expected behavior -// } -// -// // Test null value -// // This will fail in the CorrelationAttribute constructor -// try { -// new CorrelationAttributeInstance(fileType, null); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown making a CorrelationAttributeInstance with null type and was not"); -// } catch (CorrelationAttributeNormalizationException ex) { -// // This is the expected behavior -// } catch (EamDbException ex) { -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown making a CorrelationAttributeInstance with null type, EamDbException was thrown instead " + ex.getMessage()); -// } -// -// // Test getting instances with expected results -// try { -// List instances = EamDb.getInstance().getArtifactInstancesByTypeValue(fileType, inAllDataSourcesHash); -// assertEquals("Unexpected number of fileType instances gotten by type value for hash that should be in all 3 data sources", 3, instances.size()); -// -// // This test works because all the instances of this hash were set to the same path -// for (CorrelationAttributeInstance inst : instances) { -// assertTrue("getArtifactInstancesByTypeValue returned file instance with unexpected path " + inst.getFilePath() + " expected " + inAllDataSourcesPath, -// inAllDataSourcesPath.equalsIgnoreCase(inst.getFilePath())); -// } -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error exception thrown while getting attributes by type value " + ex.getMessage()); -// } -// -// // Test getting instances with mismatched data / data-type and expect an exception -// try { -// EamDb.getInstance().getArtifactInstancesByTypeValue(emailType, inAllDataSourcesHash); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get email type attributes with a hash value"); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get email type attributes with a hash value, EamDbException was thrown instead " + ex.getMessage()); -// } catch (CorrelationAttributeNormalizationException ex) { -// //this is expected -// } -// -// // Test getting instances with null type -// try { -// EamDb.getInstance().getArtifactInstancesByTypeValue(null, inAllDataSourcesHash); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get null type attributes with a hash value"); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get null type attributes with a hash value, EamDbException was thrown instead " + ex.getMessage()); -// } catch (CorrelationAttributeNormalizationException ex) { -// // This is the expected behavior -// } -// -// // Test getting instances with null value -// try { -// EamDb.getInstance().getArtifactInstancesByTypeValue(fileType, null); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get file type attributes with a null value"); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get file type attributes with a null value, EamDbException was thrown instead " + ex.getMessage()); -// } catch (CorrelationAttributeNormalizationException ex) { -// //this is expected -// } -// -// // Test getting instances with path that should produce results -// try { -// List instances = EamDb.getInstance().getArtifactInstancesByPath(fileType, inAllDataSourcesPath); -// assertEquals("Unexpected number of fileType instances retrieved when getting file type attributes by path that should be in all 3 data sources", 3, instances.size()); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error EamDbException thrown while getting attributes when getting file type attributes by path" + ex.getMessage()); -// } -// -// // Test getting instances with path that should not produce results -// try { -// List instances = EamDb.getInstance().getArtifactInstancesByPath(fileType, "xyz"); -// assertEquals("Unexpected number of fileType instances retrieved when getting file type attributes by path that should not be in any data sources", 0, instances.size()); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error EamDbException thrown while getting attributes when getting file type attributes by path for path that should not exist" + ex.getMessage()); -// } -// -// // Test getting instances with null type -// try { -// EamDb.getInstance().getArtifactInstancesByPath(null, inAllDataSourcesPath); -// fail("Error EamDbException was expected to be thrown when getting null type attributes by path"); -// } catch (EamDbException ex) { -// // This is the expected behavior -// } -// -// // Test getting instances with null path -// try { -// EamDb.getInstance().getArtifactInstancesByPath(fileType, null); -// fail("Error EamDbException was expected to be thrown when getting file type attributes with null path"); -// } catch (EamDbException ex) { -// // This is the expected behavior -// } -// -// // Test getting instance count with path that should produce results -// try { -// long count = EamDb.getInstance().getCountArtifactInstancesByTypeValue(fileType, inAllDataSourcesHash); -// assertEquals("Unexpected number of fileType instances retrieved when getting count of file type value for hash that should be in all 3 data sources", 3, count); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Exception thrown while getting count of file type value for hash that should exist" + ex.getMessage()); -// } -// -// // Test getting instance count with path that should not produce results -// try { -// long count = EamDb.getInstance().getCountArtifactInstancesByTypeValue(fileType, unusedHashValue); -// assertEquals("Unexpected number of fileType instances retrieved when getting count of file type value for hash that should not be in any data sources", 0, count); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Exception thrown while getting count of file type value for hash that should not exist" + ex.getMessage()); -// } -// -// // Test getting instance count with null type -// try { -// EamDb.getInstance().getCountArtifactInstancesByTypeValue(null, inAllDataSourcesHash); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of null type attributes with a hash value"); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of null type attributes with a hash value, EamDbException was thrown instead " + ex.getMessage()); -// } catch (CorrelationAttributeNormalizationException ex) { -// // This is the expected behavior -// } -// -// // Test getting instance count with null value -// try { -// EamDb.getInstance().getCountArtifactInstancesByTypeValue(fileType, null); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of file type attributes with a null hash value"); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of null type attributes with a null hash value, EamDbException was thrown instead " + ex.getMessage()); -// } catch (CorrelationAttributeNormalizationException ex) { -// // This is the expected behavior -// } -// -// // Test getting frequency of value that is in all three data sources -// try { -// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, inAllDataSourcesHash); -// int freq = EamDb.getInstance().getFrequencyPercentage(attr); -// assertEquals("Unexpected frequency value of file type returned for value that should exist in all data sources", 100, freq); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Exception thrown while getting frequency of file type value for hash that should exist in all data sources" + ex.getMessage()); -// } -// -// // Test getting frequency of value that appears twice in a single data source -// try { -// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, inDataSource1twiceHash); -// int freq = EamDb.getInstance().getFrequencyPercentage(attr); -// assertEquals("Unexpected frequency value of file type returned for value that should exist in one of three data sources", 33, freq); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Exception thrown while getting frequency of file type value for hash that should exist in one of three data sources" + ex.getMessage()); -// } -// -// // Test getting frequency of non-file type -// try { -// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(emailType, emailValue); -// int freq = EamDb.getInstance().getFrequencyPercentage(attr); -// assertEquals("Unexpected frequency value of email type returned for value that should exist in one of three data sources", 33, freq); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Exception thrown while getting frequency of eamil type value for value that should exist in one of three data sources" + ex.getMessage()); -// } -// -// // Test getting frequency of non-existent value -// try { -// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, unusedHashValue); -// int freq = EamDb.getInstance().getFrequencyPercentage(attr); -// assertEquals("Unexpected frequency value of file type returned for value that should not exist in any data sources", 0, freq); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Exception thrown while getting frequency of eamil type value for value that should not exist in any data sources" + ex.getMessage()); -// } -// -// // Test getting frequency with null type -// try { -// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(null, "randomValue"); -// EamDb.getInstance().getFrequencyPercentage(attr); -// fail("Error Exception was expected to be thrown when getting frequency of null type attribute"); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// // This is the expected behavior -// } -// -// // Test getting frequency with null attribute -// try { -// EamDb.getInstance().getFrequencyPercentage(null); -// fail("Error EamDbException was expected to be thrown when getting frequency of null attribute"); -// } catch (EamDbException ex) { -// // This is the expected behavior -// } catch (CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// fail("Error EamDbException was expected to be thrown when getting frequency of null attribute, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); -// fail(ex.getMessage()); -// } -// -// // Test updating a correlation attribute instance comment -// try { -// String comment = "new comment"; -// -// CorrelationAttributeInstance correlationAttribute = EamDb.getInstance().getCorrelationAttributeInstance( -// usbDeviceType, case1, dataSource1fromCase1, devIdValue, devIdPath); -// assertNotNull("Correlation Attribute returned was null when it should not have been", correlationAttribute); -// -// correlationAttribute.setComment(comment); -// EamDb.getInstance().updateAttributeInstanceComment(correlationAttribute); -// -// // Get a fresh copy to verify the update. -// correlationAttribute = EamDb.getInstance().getCorrelationAttributeInstance( -// usbDeviceType, case1, dataSource1fromCase1, devIdValue, devIdPath); -// assertEquals("Comment was not successfully set to expected value", -// comment, correlationAttribute.getComment()); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Exception thrown when setting and getting comment for attribute " + ex.getMessage()); -// } -// -// // Test getting count for dataSource1fromCase1 (includes all types) -// try { -// long count = EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(case1.getCaseUUID(), dataSource1fromCase1.getDeviceID()); -// assertEquals("Unexpected count of artifact instances retrieved when getting count for case 1, data source 1", 7, count); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error EamDbException thrown when getting count of artifact instances for case 1, data source 1" + ex.getMessage()); -// } -// -// // Test getting count with null case UUID -// try { -// long count = EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(null, dataSource1fromCase1.getDeviceID()); -// assertEquals("Unexpected count of artifact instances retrieved when getting count for null case, data source 1", 0, count); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error EamDbException thrown when getting count of artifact instances for null case, data source 1" + ex.getMessage()); -// } -// -// // Test getting count with null device ID -// try { -// long count = EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(case1.getCaseUUID(), null); -// assertEquals("Unexpected count of artifact instances retrieved when getting count for case 1, null data source", 0, count); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error EamDbException thrown when getting count of artifact instances for case 1, null data source" + ex.getMessage()); -// } -// -// // Test getting data source count for entry that is in all three -// try { -// long count = EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, inAllDataSourcesHash); -// assertEquals("Unexpected count of data sources retrieved when getting count for file types with a hash that should exist in all three data sources", 3, count); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Exception thrown when getting count of data sources for file types with a hash that should exist in all three data sources" + ex.getMessage()); -// } -// -// // Test getting data source count for entry that is in one data source twice -// try { -// long count = EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, inDataSource1twiceHash); -// assertEquals("Unexpected count of data sources retrieved when getting count for file types with a hash that should exist in a single data source twice", 1, count); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Exception thrown when getting count of data sources for file types with a hash that should exist in a single data source twice" + ex.getMessage()); -// } -// -// // Test getting data source count for entry that is not in any data sources -// try { -// long count = EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, unusedHashValue); -// assertEquals("Unexpected count of data sources retrieved when getting count for file types with a hash that should not exist in any data source", 0, count); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Exception thrown when getting count of data sources for file types with a hash that should not exist in any data source" + ex.getMessage()); -// } -// -// // Test getting data source count for null type -// try { -// EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(null, unusedHashValue); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing null type attribute"); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing null type attribute, EamDbException was thrown instead " + ex.getMessage()); -// } catch (CorrelationAttributeNormalizationException ex) { -// // This is the expected behavior -// } -// -// // Test getting data source count for null value -// try { -// EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, null); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing file type attribute with null hash"); -// } catch (EamDbException ex) { -// Exceptions.printStackTrace(ex); -// fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing file type attribute with null hash, EamDbException was thrown instead " + ex.getMessage()); -// } catch (CorrelationAttributeNormalizationException ex) { -// //this is expected -// } -// -// // Test running processinstance which queries all rows from instances table -// try { -// // Add two instances to the central repository and use the callback query to verify we can see them -// CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath1); -// CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath2); -// EamDb DbManager = EamDb.getInstance(); -// DbManager.addArtifactInstance(attr1); -// DbManager.addArtifactInstance(attr2); -// AttributeInstanceTableCallback instancetableCallback = new AttributeInstanceTableCallback(); -// DbManager.processInstanceTable(fileType, instancetableCallback); -// int count1 = instancetableCallback.getCounter(); -// int count2 = instancetableCallback.getCounterNamingConvention(); -// assertEquals("Unexpected value for Process Instance count with filepath naming convention", 2, count2); -// assertTrue("Unexpected value for Process Instance count with filepath without naming convention: " + count1 + " - expected greater than 0", count1 > 0); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Exception thrown when calling processInstanceTable " + ex.getMessage()); -// } -// -// try { -// //test null inputs -// EamDb.getInstance().processInstanceTable(null, null); -// fail("Error EamDbException was expected to be thrown when calling processInstanceTable with null inputs"); -// } catch (EamDbException ex) { -// // This is the expected behavior -// } -// -// // Test running processinstance which queries all rows from instances table -// try { -// // Add two instances to the central repository and use the callback query to verify we can see them -// CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath1); -// CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath2); -// EamDb DbManager = EamDb.getInstance(); -// DbManager.addArtifactInstance(attr1); -// DbManager.addArtifactInstance(attr2); -// AttributeInstanceTableCallback instancetableCallback = new AttributeInstanceTableCallback(); -// DbManager.processInstanceTableWhere(fileType, "value='" + callbackTestFileHash + "'", instancetableCallback); -// int count1 = instancetableCallback.getCounter(); -// int count2 = instancetableCallback.getCounterNamingConvention(); -// assertEquals("Unexpected value for Process Instance Where count with filepath naming convention", 2, count2); -// assertTrue("Unexpected value for Process Instance Where count with filepath without naming convention: " + count1 + " - expected greater than 0", count1 > 0); -// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { -// Exceptions.printStackTrace(ex); -// Assert.fail("Error Exception thrown when calling processInstanceTableWhere " + ex.getMessage()); -// } -// try { -// //test null inputs -// EamDb.getInstance().processInstanceTableWhere(null, null, null); -// fail("Error EamDbException was expected to be thrown when calling processInstanceTableWhere with null inputs"); -// } catch (EamDbException ex) { -// // This is the expected behavior -// } + + //the hash value of all 0s has not been inserted + final String unusedHashValue = "00000000000000000000000000000000"; + + String inAllDataSourcesHash = "6cddb0e31787b79cfdcc0676b98a71ce"; + String inAllDataSourcesPath = "C:\\files\\path0.txt"; + String inDataSource1twiceHash = "b2f5ff47436671b6e533d8dc3614845d"; + String inDataSource1twicePath1 = "C:\\files\\path1.txt"; + String inDataSource1twicePath2 = "C:\\files\\path2.txt"; + String onlyInDataSource3Hash = "2af54305f183778d87de0c70c591fae4"; + String onlyInDataSource3Path = "C:\\files\\path3.txt"; + String callbackTestFilePath1 = "C:\\files\\processinstancecallback\\path1.txt"; + String callbackTestFilePath2 = "C:\\files\\processinstancecallback\\path2.txt"; + String callbackTestFileHash = "fb9dd8f04dacd3e82f4917f1a002223c"; + + // These will all go in dataSource1fromCase1 + String emailValue = "test@gmail.com"; + String emailPath = "C:\\files\\emailPath.txt"; + String phoneValue = "202-555-1234"; + String phonePath = "C:\\files\\phonePath.txt"; + String domainValue = "www.mozilla.com"; + String domainPath = "C:\\files\\domainPath.txt"; + String devIdValue = "94B21234"; + String devIdPath = "C:\\files\\devIdPath.txt"; + + // Store the email type + CorrelationAttributeInstance.Type emailType; //used again for other portions of this test + try { + emailType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.EMAIL_TYPE_ID); + assertEquals("Unexpected Correlation Type retrieved for Email type id", CorrelationAttributeInstance.EMAIL_TYPE_ID, emailType.getId()); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error thrown while attempting to get email attribute " + ex.getMessage()); + return; + } + + // Test adding attribute with one instance + try { + CorrelationAttributeInstance attr = new CorrelationAttributeInstance(onlyInDataSource3Hash, fileType, case2, dataSource1fromCase2, onlyInDataSource3Path); + EamDb.getInstance().addArtifactInstance(attr); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error thrown while attempting to add file attribute from single datasource the first time " + ex.getMessage()); + } + + // Test adding attribute with an instance in each data source + try { + CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case1, dataSource1fromCase1, inAllDataSourcesPath); + EamDb.getInstance().addArtifactInstance(attr1); + CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case1, dataSource2fromCase1, inAllDataSourcesPath); + EamDb.getInstance().addArtifactInstance(attr2); + CorrelationAttributeInstance attr3 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case2, dataSource1fromCase2, inAllDataSourcesPath); + EamDb.getInstance().addArtifactInstance(attr3); + + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error thrown while attempting to add file attribute from all 3 datasources " + ex.getMessage()); + } + + // Test adding attribute with two instances in one data source + try { + CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(inDataSource1twiceHash, fileType, case1, dataSource1fromCase1, inDataSource1twicePath1); + EamDb.getInstance().addArtifactInstance(attr1); + CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(inDataSource1twiceHash, fileType, case1, dataSource1fromCase1, inDataSource1twicePath2); + EamDb.getInstance().addArtifactInstance(attr2); + + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error thrown while attempting to add file attribute from single datasource the second time " + ex.getMessage()); + } + + // Test adding the other types + // Test adding an email artifact + try { + CorrelationAttributeInstance attr = new CorrelationAttributeInstance(emailValue, emailType, case1, dataSource1fromCase1, emailPath); + EamDb.getInstance().addArtifactInstance(attr); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error thrown while attempting to add email attribute from single datasource " + ex.getMessage()); + } + + // Test adding a phone artifact + try { + CorrelationAttributeInstance attr = new CorrelationAttributeInstance( + phoneValue, + EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.PHONE_TYPE_ID), + case1, dataSource1fromCase1, phonePath); + + EamDb.getInstance().addArtifactInstance(attr); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error thrown while attempting to add phone attribute from single datasource " + ex.getMessage()); + } + + // Test adding a domain artifact + try { + CorrelationAttributeInstance.Type type = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.DOMAIN_TYPE_ID); + assertEquals("Unexpected Correlation Type retrieved for Domain type id", CorrelationAttributeInstance.DOMAIN_TYPE_ID, type.getId()); + CorrelationAttributeInstance attr = new CorrelationAttributeInstance( + domainValue, + type, + case1, dataSource1fromCase1, domainPath); + EamDb.getInstance().addArtifactInstance(attr); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error thrown while attempting to add domain attribute from single datasource " + ex.getMessage()); + } + + // Test adding a device ID artifact + try { + CorrelationAttributeInstance attr = new CorrelationAttributeInstance( + devIdValue, + EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.USBID_TYPE_ID), + case1, dataSource1fromCase1, devIdPath); + + EamDb.getInstance().addArtifactInstance(attr); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error thrown while attempting to add device ID attribute from single datasource " + ex.getMessage()); + } + + // Test CorrelationAttributeInstance creation + try { + new CorrelationAttributeInstance(fileType, randomHash()); + } catch (CorrelationAttributeNormalizationException | EamDbException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Creating correlation attribute instance " + ex.getMessage()); + } + + // Test adding instance with null case + try { + CorrelationAttributeInstance failAttrInst = new CorrelationAttributeInstance("badInstances", fileType, null, dataSource1fromCase2, BAD_PATH); + EamDb.getInstance().addArtifactInstance(failAttrInst); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null case and was not"); + } catch (EamDbException ex) { + fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null case, EamDbException was thrown instead " + ex.getMessage()); + } catch (CorrelationAttributeNormalizationException ex) { + // This is the expected behavior + } + + // Test adding instance with invalid case ID + try { + CorrelationCase badCase = new CorrelationCase("badCaseUuid", "badCaseName"); + CorrelationAttributeInstance failAttrInst2 = new CorrelationAttributeInstance(randomHash(), fileType, badCase, dataSource1fromCase2, BAD_PATH); + EamDb.getInstance().addArtifactInstance(failAttrInst2); + fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid case ID and was not"); + } catch (EamDbException ex) { + // This is the expected behavior + } catch (CorrelationAttributeNormalizationException ex) { + fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid case ID, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); + } + + // Test adding instance with null data source + try { + CorrelationAttributeInstance failAttrInst3 = new CorrelationAttributeInstance(randomHash(), fileType, case1, null, BAD_PATH); + EamDb.getInstance().addArtifactInstance(failAttrInst3); + fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null data source and was not"); + } catch (EamDbException ex) { + // This is the expected behavior + } catch (CorrelationAttributeNormalizationException ex) { + fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null data source, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); + } + + // Test adding instance with invalid data source ID + try { + CorrelationDataSource badDS = new CorrelationDataSource(case1, "badDSUuid", "badDSName"); + CorrelationAttributeInstance failAttrInst4 = new CorrelationAttributeInstance(randomHash(), fileType, case1, badDS, BAD_PATH); + EamDb.getInstance().addArtifactInstance(failAttrInst4); + fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid data source ID and was not"); + } catch (EamDbException ex) { + // This is the expected behavior + } catch (CorrelationAttributeNormalizationException ex) { + fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid data source ID, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); + } + + // Test adding instance with null path + // This will fail in the CorrelationAttributeInstance constructor + try { + new CorrelationAttributeInstance(randomHash(), fileType, case1, dataSource1fromCase1, null); + fail("Error EamDbException was expected to be thrown making a CorrelationAttributeInstance with null path and was not"); + } catch (EamDbException ex) { + // This is the expected behavior + } catch (CorrelationAttributeNormalizationException ex) { + fail("Error EamDbException was expected to be thrown making a CorrelationAttributeInstance with null path, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); + } + + // Test adding instance with null known status + try { + CorrelationAttributeInstance failAttrInst5 = new CorrelationAttributeInstance("badInstances", fileType, case1, dataSource1fromCase1, null, "comment", null); + EamDb.getInstance().addArtifactInstance(failAttrInst5); + fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null known status and was not"); + } catch (EamDbException ex) { + // This is the expected behavior + } catch (CorrelationAttributeNormalizationException ex) { + fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null known status, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); + } + + // Test CorrelationAttribute failure cases + // Test null type + try { + CorrelationAttributeInstance attr = new CorrelationAttributeInstance(null, randomHash()); + EamDb.getInstance().addArtifactInstance(attr); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null type and was not"); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null type, EamDbException was thrown instead " + ex.getMessage()); + } catch (CorrelationAttributeNormalizationException ex) { + // This is the expected behavior + } + + // Test null value + // This will fail in the CorrelationAttribute constructor + try { + new CorrelationAttributeInstance(fileType, null); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown making a CorrelationAttributeInstance with null type and was not"); + } catch (CorrelationAttributeNormalizationException ex) { + // This is the expected behavior + } catch (EamDbException ex) { + fail("Error CorrelationAttributeNormalizationException was expected to be thrown making a CorrelationAttributeInstance with null type, EamDbException was thrown instead " + ex.getMessage()); + } + + // Test getting instances with expected results + try { + List instances = EamDb.getInstance().getArtifactInstancesByTypeValue(fileType, inAllDataSourcesHash); + assertEquals("Unexpected number of fileType instances gotten by type value for hash that should be in all 3 data sources", 3, instances.size()); + + // This test works because all the instances of this hash were set to the same path + for (CorrelationAttributeInstance inst : instances) { + assertTrue("getArtifactInstancesByTypeValue returned file instance with unexpected path " + inst.getFilePath() + " expected " + inAllDataSourcesPath, + inAllDataSourcesPath.equalsIgnoreCase(inst.getFilePath())); + } + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error exception thrown while getting attributes by type value " + ex.getMessage()); + } + + // Test getting instances with mismatched data / data-type and expect an exception + try { + EamDb.getInstance().getArtifactInstancesByTypeValue(emailType, inAllDataSourcesHash); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get email type attributes with a hash value"); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get email type attributes with a hash value, EamDbException was thrown instead " + ex.getMessage()); + } catch (CorrelationAttributeNormalizationException ex) { + //this is expected + } + + // Test getting instances with null type + try { + EamDb.getInstance().getArtifactInstancesByTypeValue(null, inAllDataSourcesHash); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get null type attributes with a hash value"); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get null type attributes with a hash value, EamDbException was thrown instead " + ex.getMessage()); + } catch (CorrelationAttributeNormalizationException ex) { + // This is the expected behavior + } + + // Test getting instances with null value + try { + EamDb.getInstance().getArtifactInstancesByTypeValue(fileType, null); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get file type attributes with a null value"); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get file type attributes with a null value, EamDbException was thrown instead " + ex.getMessage()); + } catch (CorrelationAttributeNormalizationException ex) { + //this is expected + } + + // Test getting instances with path that should produce results + try { + List instances = EamDb.getInstance().getArtifactInstancesByPath(fileType, inAllDataSourcesPath); + assertEquals("Unexpected number of fileType instances retrieved when getting file type attributes by path that should be in all 3 data sources", 3, instances.size()); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error EamDbException thrown while getting attributes when getting file type attributes by path" + ex.getMessage()); + } + + // Test getting instances with path that should not produce results + try { + List instances = EamDb.getInstance().getArtifactInstancesByPath(fileType, "xyz"); + assertEquals("Unexpected number of fileType instances retrieved when getting file type attributes by path that should not be in any data sources", 0, instances.size()); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error EamDbException thrown while getting attributes when getting file type attributes by path for path that should not exist" + ex.getMessage()); + } + + // Test getting instances with null type + try { + EamDb.getInstance().getArtifactInstancesByPath(null, inAllDataSourcesPath); + fail("Error EamDbException was expected to be thrown when getting null type attributes by path"); + } catch (EamDbException ex) { + // This is the expected behavior + } + + // Test getting instances with null path + try { + EamDb.getInstance().getArtifactInstancesByPath(fileType, null); + fail("Error EamDbException was expected to be thrown when getting file type attributes with null path"); + } catch (EamDbException ex) { + // This is the expected behavior + } + + // Test getting instance count with path that should produce results + try { + long count = EamDb.getInstance().getCountArtifactInstancesByTypeValue(fileType, inAllDataSourcesHash); + assertEquals("Unexpected number of fileType instances retrieved when getting count of file type value for hash that should be in all 3 data sources", 3, count); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Exception thrown while getting count of file type value for hash that should exist" + ex.getMessage()); + } + + // Test getting instance count with path that should not produce results + try { + long count = EamDb.getInstance().getCountArtifactInstancesByTypeValue(fileType, unusedHashValue); + assertEquals("Unexpected number of fileType instances retrieved when getting count of file type value for hash that should not be in any data sources", 0, count); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Exception thrown while getting count of file type value for hash that should not exist" + ex.getMessage()); + } + + // Test getting instance count with null type + try { + EamDb.getInstance().getCountArtifactInstancesByTypeValue(null, inAllDataSourcesHash); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of null type attributes with a hash value"); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of null type attributes with a hash value, EamDbException was thrown instead " + ex.getMessage()); + } catch (CorrelationAttributeNormalizationException ex) { + // This is the expected behavior + } + + // Test getting instance count with null value + try { + EamDb.getInstance().getCountArtifactInstancesByTypeValue(fileType, null); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of file type attributes with a null hash value"); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of null type attributes with a null hash value, EamDbException was thrown instead " + ex.getMessage()); + } catch (CorrelationAttributeNormalizationException ex) { + // This is the expected behavior + } + + // Test getting frequency of value that is in all three data sources + try { + CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, inAllDataSourcesHash); + int freq = EamDb.getInstance().getFrequencyPercentage(attr); + assertEquals("Unexpected frequency value of file type returned for value that should exist in all data sources", 100, freq); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Exception thrown while getting frequency of file type value for hash that should exist in all data sources" + ex.getMessage()); + } + + // Test getting frequency of value that appears twice in a single data source + try { + CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, inDataSource1twiceHash); + int freq = EamDb.getInstance().getFrequencyPercentage(attr); + assertEquals("Unexpected frequency value of file type returned for value that should exist in one of three data sources", 33, freq); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Exception thrown while getting frequency of file type value for hash that should exist in one of three data sources" + ex.getMessage()); + } + + // Test getting frequency of non-file type + try { + CorrelationAttributeInstance attr = new CorrelationAttributeInstance(emailType, emailValue); + int freq = EamDb.getInstance().getFrequencyPercentage(attr); + assertEquals("Unexpected frequency value of email type returned for value that should exist in one of three data sources", 33, freq); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Exception thrown while getting frequency of eamil type value for value that should exist in one of three data sources" + ex.getMessage()); + } + + // Test getting frequency of non-existent value + try { + CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, unusedHashValue); + int freq = EamDb.getInstance().getFrequencyPercentage(attr); + assertEquals("Unexpected frequency value of file type returned for value that should not exist in any data sources", 0, freq); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Exception thrown while getting frequency of eamil type value for value that should not exist in any data sources" + ex.getMessage()); + } + + // Test getting frequency with null type + try { + CorrelationAttributeInstance attr = new CorrelationAttributeInstance(null, "randomValue"); + EamDb.getInstance().getFrequencyPercentage(attr); + fail("Error Exception was expected to be thrown when getting frequency of null type attribute"); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + // This is the expected behavior + } + + // Test getting frequency with null attribute + try { + EamDb.getInstance().getFrequencyPercentage(null); + fail("Error EamDbException was expected to be thrown when getting frequency of null attribute"); + } catch (EamDbException ex) { + // This is the expected behavior + } catch (CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + fail("Error EamDbException was expected to be thrown when getting frequency of null attribute, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); + fail(ex.getMessage()); + } + + // Test updating a correlation attribute instance comment + try { + String comment = "new comment"; + + CorrelationAttributeInstance correlationAttribute = EamDb.getInstance().getCorrelationAttributeInstance( + usbDeviceType, case1, dataSource1fromCase1, devIdValue, devIdPath); + assertNotNull("Correlation Attribute returned was null when it should not have been", correlationAttribute); + + correlationAttribute.setComment(comment); + EamDb.getInstance().updateAttributeInstanceComment(correlationAttribute); + + // Get a fresh copy to verify the update. + correlationAttribute = EamDb.getInstance().getCorrelationAttributeInstance( + usbDeviceType, case1, dataSource1fromCase1, devIdValue, devIdPath); + assertEquals("Comment was not successfully set to expected value", + comment, correlationAttribute.getComment()); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Exception thrown when setting and getting comment for attribute " + ex.getMessage()); + } + + // Test getting count for dataSource1fromCase1 (includes all types) + try { + long count = EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(case1.getCaseUUID(), dataSource1fromCase1.getDeviceID()); + assertEquals("Unexpected count of artifact instances retrieved when getting count for case 1, data source 1", 7, count); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error EamDbException thrown when getting count of artifact instances for case 1, data source 1" + ex.getMessage()); + } + + // Test getting count with null case UUID + try { + long count = EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(null, dataSource1fromCase1.getDeviceID()); + assertEquals("Unexpected count of artifact instances retrieved when getting count for null case, data source 1", 0, count); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error EamDbException thrown when getting count of artifact instances for null case, data source 1" + ex.getMessage()); + } + + // Test getting count with null device ID + try { + long count = EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(case1.getCaseUUID(), null); + assertEquals("Unexpected count of artifact instances retrieved when getting count for case 1, null data source", 0, count); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error EamDbException thrown when getting count of artifact instances for case 1, null data source" + ex.getMessage()); + } + + // Test getting data source count for entry that is in all three + try { + long count = EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, inAllDataSourcesHash); + assertEquals("Unexpected count of data sources retrieved when getting count for file types with a hash that should exist in all three data sources", 3, count); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Exception thrown when getting count of data sources for file types with a hash that should exist in all three data sources" + ex.getMessage()); + } + + // Test getting data source count for entry that is in one data source twice + try { + long count = EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, inDataSource1twiceHash); + assertEquals("Unexpected count of data sources retrieved when getting count for file types with a hash that should exist in a single data source twice", 1, count); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Exception thrown when getting count of data sources for file types with a hash that should exist in a single data source twice" + ex.getMessage()); + } + + // Test getting data source count for entry that is not in any data sources + try { + long count = EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, unusedHashValue); + assertEquals("Unexpected count of data sources retrieved when getting count for file types with a hash that should not exist in any data source", 0, count); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Exception thrown when getting count of data sources for file types with a hash that should not exist in any data source" + ex.getMessage()); + } + + // Test getting data source count for null type + try { + EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(null, unusedHashValue); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing null type attribute"); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing null type attribute, EamDbException was thrown instead " + ex.getMessage()); + } catch (CorrelationAttributeNormalizationException ex) { + // This is the expected behavior + } + + // Test getting data source count for null value + try { + EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, null); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing file type attribute with null hash"); + } catch (EamDbException ex) { + Exceptions.printStackTrace(ex); + fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing file type attribute with null hash, EamDbException was thrown instead " + ex.getMessage()); + } catch (CorrelationAttributeNormalizationException ex) { + //this is expected + } + + // Test running processinstance which queries all rows from instances table + try { + // Add two instances to the central repository and use the callback query to verify we can see them + CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath1); + CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath2); + EamDb DbManager = EamDb.getInstance(); + DbManager.addArtifactInstance(attr1); + DbManager.addArtifactInstance(attr2); + AttributeInstanceTableCallback instancetableCallback = new AttributeInstanceTableCallback(); + DbManager.processInstanceTable(fileType, instancetableCallback); + int count1 = instancetableCallback.getCounter(); + int count2 = instancetableCallback.getCounterNamingConvention(); + //expects 2 rows to match the naming convention to of been processed, expects at least one row not matching the naming convention to be processed + //if the test code is changed to add additional Correlation Attributes which also have "processinstancecallback" in their path the first of these comparisons will need to change + assertEquals("Counter for items matching naming convention from AttributeInstaceTableCallback indicates an unexepected number of results when processed with DbManager.processInstanceTable", 2, count2); + assertTrue("Counter for items which do not match naming convention from AttributeInstaceTableCallback indicates an unexepected number of results when processed with DbManager.processInstanceTable. Count indicated: " + count1 + " - expected a number greater than 0", count1 > 0); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Exception thrown when calling processInstanceTable " + ex.getMessage()); + } + + try { + //test null inputs + EamDb.getInstance().processInstanceTable(null, null); + fail("Error EamDbException was expected to be thrown when calling processInstanceTable with null inputs"); + } catch (EamDbException ex) { + // This is the expected behavior + } + + // Test running processinstance which queries all rows from instances table + try { + // Add two instances to the central repository and use the callback query to verify we can see them + CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath1); + CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath2); + EamDb DbManager = EamDb.getInstance(); + //these redundant addArtifactInstance calls allow code to be rearranged if necessary + DbManager.addArtifactInstance(attr1); + DbManager.addArtifactInstance(attr2); + AttributeInstanceTableCallback instancetableCallback = new AttributeInstanceTableCallback(); + DbManager.processInstanceTableWhere(fileType, "value='" + callbackTestFileHash + "'", instancetableCallback); + int count1 = instancetableCallback.getCounter(); + //naming convention counts + int count2 = instancetableCallback.getCounterNamingConvention(); + //this has only processed the rows where the value is equal to the specified value, which should only be the two rows with the naming convention checked for + //if the test code is changed to add additional Correlation Attributes with the same callbackTestFileHash value that is used here these comparisons will need to change + assertEquals("Counter for items matching naming convention from AttributeInstaceTableCallback indicates an unexepected number of results when processed with DbManager.processInstanceTableWhere", 2, count2); + assertEquals("Counter for items which do not match naming convention from AttributeInstaceTableCallback indicates an unexepected number of results when processed with DbManager.processInstanceTableWhere", 0, count1); + } catch (EamDbException | CorrelationAttributeNormalizationException ex) { + Exceptions.printStackTrace(ex); + Assert.fail("Error Exception thrown when calling processInstanceTableWhere " + ex.getMessage()); + } + try { + //test null inputs + EamDb.getInstance().processInstanceTableWhere(null, null, null); + fail("Error EamDbException was expected to be thrown when calling processInstanceTableWhere with null inputs"); + } catch (EamDbException ex) { + // This is the expected behavior + } } /** From f44031d344980691e68c2f243d22a427bbb4c885 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Thu, 27 Sep 2018 11:31:43 -0400 Subject: [PATCH 02/70] 4242 return now fixed test to commented out state awaiting 4241 changes --- .../datamodel/CentralRepoDatamodelTest.java | 1316 ++++++++--------- 1 file changed, 658 insertions(+), 658 deletions(-) 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 944dd7272e..2a7f76b5e2 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 @@ -88,109 +88,109 @@ public class CentralRepoDatamodelTest extends TestCase { @Override public void setUp() { - dbSettingsSqlite = new SqliteEamDbSettings(); - - // Delete the test directory, if it exists - if (testDirectory.toFile().exists()) { - try { - FileUtils.deleteDirectory(testDirectory.toFile()); - } catch (IOException ex) { - Assert.fail(ex.getMessage()); - } - } - assertFalse("Unable to delete existing test directory", testDirectory.toFile().exists()); - - // Create the test directory - testDirectory.toFile().mkdirs(); - assertTrue("Unable to create test directory", testDirectory.toFile().exists()); - - // Save the current central repo settings - propertiesMap = ModuleSettings.getConfigSettings(PROPERTIES_FILE); - - try { - dbSettingsSqlite.setDbName(CR_DB_NAME); - dbSettingsSqlite.setDbDirectory(testDirectory.toString()); - if (!dbSettingsSqlite.dbDirectoryExists()) { - dbSettingsSqlite.createDbDirectory(); - } - - assertTrue("Failed to created central repo directory " + dbSettingsSqlite.getDbDirectory(), dbSettingsSqlite.dbDirectoryExists()); - - boolean result = dbSettingsSqlite.initializeDatabaseSchema() - && dbSettingsSqlite.insertDefaultDatabaseContent(); - - assertTrue("Failed to initialize central repo database", result); - - dbSettingsSqlite.saveSettings(); - EamDbUtil.setUseCentralRepo(true); - EamDbPlatformEnum.setSelectedPlatform(EamDbPlatformEnum.SQLITE.name()); - EamDbPlatformEnum.saveSelectedPlatform(); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - Assert.fail(ex.getMessage()); - } - - Path crDbFilePath = Paths.get(testDirectory.toString(), CR_DB_NAME); - assertTrue("Failed to create central repo database at " + crDbFilePath, crDbFilePath.toFile().exists()); - - // Set up some default objects to be used by the tests - try { - case1 = new CorrelationCase("case1_uuid", "case1"); - case1 = EamDb.getInstance().newCase(case1); - assertTrue("Failed to create test object case1", case1 != null); - - case2 = new CorrelationCase("case2_uuid", "case2"); - case2 = EamDb.getInstance().newCase(case2); - assertTrue("Failed to create test object case2", case2 != null); - - dataSource1fromCase1 = new CorrelationDataSource(case1, "dataSource1_deviceID", "dataSource1"); - EamDb.getInstance().newDataSource(dataSource1fromCase1); - dataSource1fromCase1 = EamDb.getInstance().getDataSource(case1, dataSource1fromCase1.getDeviceID()); - assertTrue("Failed to create test object dataSource1fromCase1", dataSource1fromCase1 != null); - - dataSource2fromCase1 = new CorrelationDataSource(case1, "dataSource2_deviceID", "dataSource2"); - EamDb.getInstance().newDataSource(dataSource2fromCase1); - dataSource2fromCase1 = EamDb.getInstance().getDataSource(case1, dataSource2fromCase1.getDeviceID()); - assertTrue("Failed to create test object dataSource2fromCase1", dataSource2fromCase1 != null); - - dataSource1fromCase2 = new CorrelationDataSource(case2, "dataSource3_deviceID", "dataSource3"); - EamDb.getInstance().newDataSource(dataSource1fromCase2); - dataSource1fromCase2 = EamDb.getInstance().getDataSource(case2, dataSource1fromCase2.getDeviceID()); - assertTrue("Failed to create test object dataSource1fromCase2", dataSource1fromCase2 != null); - - org1 = new EamOrganization("org1"); - org1 = EamDb.getInstance().newOrganization(org1); - - org2 = new EamOrganization("org2"); - org2 = EamDb.getInstance().newOrganization(org2); - - // Store the file type object for later use - fileType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID); - assertTrue("getCorrelationTypeById(FILES_TYPE_ID) returned null", fileType != null); - usbDeviceType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.USBID_TYPE_ID); - assertTrue("getCorrelationTypeById(USBID_TYPE_ID) returned null", usbDeviceType != null); - - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - Assert.fail(ex.getMessage()); - } +// dbSettingsSqlite = new SqliteEamDbSettings(); +// +// // Delete the test directory, if it exists +// if (testDirectory.toFile().exists()) { +// try { +// FileUtils.deleteDirectory(testDirectory.toFile()); +// } catch (IOException ex) { +// Assert.fail(ex.getMessage()); +// } +// } +// assertFalse("Unable to delete existing test directory", testDirectory.toFile().exists()); +// +// // Create the test directory +// testDirectory.toFile().mkdirs(); +// assertTrue("Unable to create test directory", testDirectory.toFile().exists()); +// +// // Save the current central repo settings +// propertiesMap = ModuleSettings.getConfigSettings(PROPERTIES_FILE); +// +// try { +// dbSettingsSqlite.setDbName(CR_DB_NAME); +// dbSettingsSqlite.setDbDirectory(testDirectory.toString()); +// if (!dbSettingsSqlite.dbDirectoryExists()) { +// dbSettingsSqlite.createDbDirectory(); +// } +// +// assertTrue("Failed to created central repo directory " + dbSettingsSqlite.getDbDirectory(), dbSettingsSqlite.dbDirectoryExists()); +// +// boolean result = dbSettingsSqlite.initializeDatabaseSchema() +// && dbSettingsSqlite.insertDefaultDatabaseContent(); +// +// assertTrue("Failed to initialize central repo database", result); +// +// dbSettingsSqlite.saveSettings(); +// EamDbUtil.setUseCentralRepo(true); +// EamDbPlatformEnum.setSelectedPlatform(EamDbPlatformEnum.SQLITE.name()); +// EamDbPlatformEnum.saveSelectedPlatform(); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail(ex.getMessage()); +// } +// +// Path crDbFilePath = Paths.get(testDirectory.toString(), CR_DB_NAME); +// assertTrue("Failed to create central repo database at " + crDbFilePath, crDbFilePath.toFile().exists()); +// +// // Set up some default objects to be used by the tests +// try { +// case1 = new CorrelationCase("case1_uuid", "case1"); +// case1 = EamDb.getInstance().newCase(case1); +// assertTrue("Failed to create test object case1", case1 != null); +// +// case2 = new CorrelationCase("case2_uuid", "case2"); +// case2 = EamDb.getInstance().newCase(case2); +// assertTrue("Failed to create test object case2", case2 != null); +// +// dataSource1fromCase1 = new CorrelationDataSource(case1, "dataSource1_deviceID", "dataSource1"); +// EamDb.getInstance().newDataSource(dataSource1fromCase1); +// dataSource1fromCase1 = EamDb.getInstance().getDataSource(case1, dataSource1fromCase1.getDeviceID()); +// assertTrue("Failed to create test object dataSource1fromCase1", dataSource1fromCase1 != null); +// +// dataSource2fromCase1 = new CorrelationDataSource(case1, "dataSource2_deviceID", "dataSource2"); +// EamDb.getInstance().newDataSource(dataSource2fromCase1); +// dataSource2fromCase1 = EamDb.getInstance().getDataSource(case1, dataSource2fromCase1.getDeviceID()); +// assertTrue("Failed to create test object dataSource2fromCase1", dataSource2fromCase1 != null); +// +// dataSource1fromCase2 = new CorrelationDataSource(case2, "dataSource3_deviceID", "dataSource3"); +// EamDb.getInstance().newDataSource(dataSource1fromCase2); +// dataSource1fromCase2 = EamDb.getInstance().getDataSource(case2, dataSource1fromCase2.getDeviceID()); +// assertTrue("Failed to create test object dataSource1fromCase2", dataSource1fromCase2 != null); +// +// org1 = new EamOrganization("org1"); +// org1 = EamDb.getInstance().newOrganization(org1); +// +// org2 = new EamOrganization("org2"); +// org2 = EamDb.getInstance().newOrganization(org2); +// +// // Store the file type object for later use +// fileType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID); +// assertTrue("getCorrelationTypeById(FILES_TYPE_ID) returned null", fileType != null); +// usbDeviceType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.USBID_TYPE_ID); +// assertTrue("getCorrelationTypeById(USBID_TYPE_ID) returned null", usbDeviceType != null); +// +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail(ex.getMessage()); +// } } @Override public void tearDown() { - - // Restore the original properties - ModuleSettings.setConfigSettings(PROPERTIES_FILE, propertiesMap); - - // Close and delete the test case and central repo db - try { - EamDb.getInstance().shutdownConnections(); - FileUtils.deleteDirectory(testDirectory.toFile()); - } catch (EamDbException | IOException ex) { - Exceptions.printStackTrace(ex); - Assert.fail(ex.getMessage()); - } - assertFalse("Error deleting test directory " + testDirectory.toString(), testDirectory.toFile().exists()); +// +// // Restore the original properties +// ModuleSettings.setConfigSettings(PROPERTIES_FILE, propertiesMap); +// +// // Close and delete the test case and central repo db +// try { +// EamDb.getInstance().shutdownConnections(); +// FileUtils.deleteDirectory(testDirectory.toFile()); +// } catch (EamDbException | IOException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail(ex.getMessage()); +// } +// assertFalse("Error deleting test directory " + testDirectory.toString(), testDirectory.toFile().exists()); } /** @@ -659,565 +659,565 @@ public class CentralRepoDatamodelTest extends TestCase { * with null type - Test with null value */ public void testArtifacts() { - - //the hash value of all 0s has not been inserted - final String unusedHashValue = "00000000000000000000000000000000"; - - String inAllDataSourcesHash = "6cddb0e31787b79cfdcc0676b98a71ce"; - String inAllDataSourcesPath = "C:\\files\\path0.txt"; - String inDataSource1twiceHash = "b2f5ff47436671b6e533d8dc3614845d"; - String inDataSource1twicePath1 = "C:\\files\\path1.txt"; - String inDataSource1twicePath2 = "C:\\files\\path2.txt"; - String onlyInDataSource3Hash = "2af54305f183778d87de0c70c591fae4"; - String onlyInDataSource3Path = "C:\\files\\path3.txt"; - String callbackTestFilePath1 = "C:\\files\\processinstancecallback\\path1.txt"; - String callbackTestFilePath2 = "C:\\files\\processinstancecallback\\path2.txt"; - String callbackTestFileHash = "fb9dd8f04dacd3e82f4917f1a002223c"; - - // These will all go in dataSource1fromCase1 - String emailValue = "test@gmail.com"; - String emailPath = "C:\\files\\emailPath.txt"; - String phoneValue = "202-555-1234"; - String phonePath = "C:\\files\\phonePath.txt"; - String domainValue = "www.mozilla.com"; - String domainPath = "C:\\files\\domainPath.txt"; - String devIdValue = "94B21234"; - String devIdPath = "C:\\files\\devIdPath.txt"; - - // Store the email type - CorrelationAttributeInstance.Type emailType; //used again for other portions of this test - try { - emailType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.EMAIL_TYPE_ID); - assertEquals("Unexpected Correlation Type retrieved for Email type id", CorrelationAttributeInstance.EMAIL_TYPE_ID, emailType.getId()); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error thrown while attempting to get email attribute " + ex.getMessage()); - return; - } - - // Test adding attribute with one instance - try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance(onlyInDataSource3Hash, fileType, case2, dataSource1fromCase2, onlyInDataSource3Path); - EamDb.getInstance().addArtifactInstance(attr); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error thrown while attempting to add file attribute from single datasource the first time " + ex.getMessage()); - } - - // Test adding attribute with an instance in each data source - try { - CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case1, dataSource1fromCase1, inAllDataSourcesPath); - EamDb.getInstance().addArtifactInstance(attr1); - CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case1, dataSource2fromCase1, inAllDataSourcesPath); - EamDb.getInstance().addArtifactInstance(attr2); - CorrelationAttributeInstance attr3 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case2, dataSource1fromCase2, inAllDataSourcesPath); - EamDb.getInstance().addArtifactInstance(attr3); - - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error thrown while attempting to add file attribute from all 3 datasources " + ex.getMessage()); - } - - // Test adding attribute with two instances in one data source - try { - CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(inDataSource1twiceHash, fileType, case1, dataSource1fromCase1, inDataSource1twicePath1); - EamDb.getInstance().addArtifactInstance(attr1); - CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(inDataSource1twiceHash, fileType, case1, dataSource1fromCase1, inDataSource1twicePath2); - EamDb.getInstance().addArtifactInstance(attr2); - - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error thrown while attempting to add file attribute from single datasource the second time " + ex.getMessage()); - } - - // Test adding the other types - // Test adding an email artifact - try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance(emailValue, emailType, case1, dataSource1fromCase1, emailPath); - EamDb.getInstance().addArtifactInstance(attr); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error thrown while attempting to add email attribute from single datasource " + ex.getMessage()); - } - - // Test adding a phone artifact - try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance( - phoneValue, - EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.PHONE_TYPE_ID), - case1, dataSource1fromCase1, phonePath); - - EamDb.getInstance().addArtifactInstance(attr); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error thrown while attempting to add phone attribute from single datasource " + ex.getMessage()); - } - - // Test adding a domain artifact - try { - CorrelationAttributeInstance.Type type = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.DOMAIN_TYPE_ID); - assertEquals("Unexpected Correlation Type retrieved for Domain type id", CorrelationAttributeInstance.DOMAIN_TYPE_ID, type.getId()); - CorrelationAttributeInstance attr = new CorrelationAttributeInstance( - domainValue, - type, - case1, dataSource1fromCase1, domainPath); - EamDb.getInstance().addArtifactInstance(attr); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error thrown while attempting to add domain attribute from single datasource " + ex.getMessage()); - } - - // Test adding a device ID artifact - try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance( - devIdValue, - EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.USBID_TYPE_ID), - case1, dataSource1fromCase1, devIdPath); - - EamDb.getInstance().addArtifactInstance(attr); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error thrown while attempting to add device ID attribute from single datasource " + ex.getMessage()); - } - - // Test CorrelationAttributeInstance creation - try { - new CorrelationAttributeInstance(fileType, randomHash()); - } catch (CorrelationAttributeNormalizationException | EamDbException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Creating correlation attribute instance " + ex.getMessage()); - } - - // Test adding instance with null case - try { - CorrelationAttributeInstance failAttrInst = new CorrelationAttributeInstance("badInstances", fileType, null, dataSource1fromCase2, BAD_PATH); - EamDb.getInstance().addArtifactInstance(failAttrInst); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null case and was not"); - } catch (EamDbException ex) { - fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null case, EamDbException was thrown instead " + ex.getMessage()); - } catch (CorrelationAttributeNormalizationException ex) { - // This is the expected behavior - } - - // Test adding instance with invalid case ID - try { - CorrelationCase badCase = new CorrelationCase("badCaseUuid", "badCaseName"); - CorrelationAttributeInstance failAttrInst2 = new CorrelationAttributeInstance(randomHash(), fileType, badCase, dataSource1fromCase2, BAD_PATH); - EamDb.getInstance().addArtifactInstance(failAttrInst2); - fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid case ID and was not"); - } catch (EamDbException ex) { - // This is the expected behavior - } catch (CorrelationAttributeNormalizationException ex) { - fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid case ID, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); - } - - // Test adding instance with null data source - try { - CorrelationAttributeInstance failAttrInst3 = new CorrelationAttributeInstance(randomHash(), fileType, case1, null, BAD_PATH); - EamDb.getInstance().addArtifactInstance(failAttrInst3); - fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null data source and was not"); - } catch (EamDbException ex) { - // This is the expected behavior - } catch (CorrelationAttributeNormalizationException ex) { - fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null data source, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); - } - - // Test adding instance with invalid data source ID - try { - CorrelationDataSource badDS = new CorrelationDataSource(case1, "badDSUuid", "badDSName"); - CorrelationAttributeInstance failAttrInst4 = new CorrelationAttributeInstance(randomHash(), fileType, case1, badDS, BAD_PATH); - EamDb.getInstance().addArtifactInstance(failAttrInst4); - fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid data source ID and was not"); - } catch (EamDbException ex) { - // This is the expected behavior - } catch (CorrelationAttributeNormalizationException ex) { - fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid data source ID, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); - } - - // Test adding instance with null path - // This will fail in the CorrelationAttributeInstance constructor - try { - new CorrelationAttributeInstance(randomHash(), fileType, case1, dataSource1fromCase1, null); - fail("Error EamDbException was expected to be thrown making a CorrelationAttributeInstance with null path and was not"); - } catch (EamDbException ex) { - // This is the expected behavior - } catch (CorrelationAttributeNormalizationException ex) { - fail("Error EamDbException was expected to be thrown making a CorrelationAttributeInstance with null path, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); - } - - // Test adding instance with null known status - try { - CorrelationAttributeInstance failAttrInst5 = new CorrelationAttributeInstance("badInstances", fileType, case1, dataSource1fromCase1, null, "comment", null); - EamDb.getInstance().addArtifactInstance(failAttrInst5); - fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null known status and was not"); - } catch (EamDbException ex) { - // This is the expected behavior - } catch (CorrelationAttributeNormalizationException ex) { - fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null known status, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); - } - - // Test CorrelationAttribute failure cases - // Test null type - try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance(null, randomHash()); - EamDb.getInstance().addArtifactInstance(attr); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null type and was not"); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null type, EamDbException was thrown instead " + ex.getMessage()); - } catch (CorrelationAttributeNormalizationException ex) { - // This is the expected behavior - } - - // Test null value - // This will fail in the CorrelationAttribute constructor - try { - new CorrelationAttributeInstance(fileType, null); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown making a CorrelationAttributeInstance with null type and was not"); - } catch (CorrelationAttributeNormalizationException ex) { - // This is the expected behavior - } catch (EamDbException ex) { - fail("Error CorrelationAttributeNormalizationException was expected to be thrown making a CorrelationAttributeInstance with null type, EamDbException was thrown instead " + ex.getMessage()); - } - - // Test getting instances with expected results - try { - List instances = EamDb.getInstance().getArtifactInstancesByTypeValue(fileType, inAllDataSourcesHash); - assertEquals("Unexpected number of fileType instances gotten by type value for hash that should be in all 3 data sources", 3, instances.size()); - - // This test works because all the instances of this hash were set to the same path - for (CorrelationAttributeInstance inst : instances) { - assertTrue("getArtifactInstancesByTypeValue returned file instance with unexpected path " + inst.getFilePath() + " expected " + inAllDataSourcesPath, - inAllDataSourcesPath.equalsIgnoreCase(inst.getFilePath())); - } - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error exception thrown while getting attributes by type value " + ex.getMessage()); - } - - // Test getting instances with mismatched data / data-type and expect an exception - try { - EamDb.getInstance().getArtifactInstancesByTypeValue(emailType, inAllDataSourcesHash); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get email type attributes with a hash value"); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get email type attributes with a hash value, EamDbException was thrown instead " + ex.getMessage()); - } catch (CorrelationAttributeNormalizationException ex) { - //this is expected - } - - // Test getting instances with null type - try { - EamDb.getInstance().getArtifactInstancesByTypeValue(null, inAllDataSourcesHash); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get null type attributes with a hash value"); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get null type attributes with a hash value, EamDbException was thrown instead " + ex.getMessage()); - } catch (CorrelationAttributeNormalizationException ex) { - // This is the expected behavior - } - - // Test getting instances with null value - try { - EamDb.getInstance().getArtifactInstancesByTypeValue(fileType, null); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get file type attributes with a null value"); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get file type attributes with a null value, EamDbException was thrown instead " + ex.getMessage()); - } catch (CorrelationAttributeNormalizationException ex) { - //this is expected - } - - // Test getting instances with path that should produce results - try { - List instances = EamDb.getInstance().getArtifactInstancesByPath(fileType, inAllDataSourcesPath); - assertEquals("Unexpected number of fileType instances retrieved when getting file type attributes by path that should be in all 3 data sources", 3, instances.size()); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error EamDbException thrown while getting attributes when getting file type attributes by path" + ex.getMessage()); - } - - // Test getting instances with path that should not produce results - try { - List instances = EamDb.getInstance().getArtifactInstancesByPath(fileType, "xyz"); - assertEquals("Unexpected number of fileType instances retrieved when getting file type attributes by path that should not be in any data sources", 0, instances.size()); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error EamDbException thrown while getting attributes when getting file type attributes by path for path that should not exist" + ex.getMessage()); - } - - // Test getting instances with null type - try { - EamDb.getInstance().getArtifactInstancesByPath(null, inAllDataSourcesPath); - fail("Error EamDbException was expected to be thrown when getting null type attributes by path"); - } catch (EamDbException ex) { - // This is the expected behavior - } - - // Test getting instances with null path - try { - EamDb.getInstance().getArtifactInstancesByPath(fileType, null); - fail("Error EamDbException was expected to be thrown when getting file type attributes with null path"); - } catch (EamDbException ex) { - // This is the expected behavior - } - - // Test getting instance count with path that should produce results - try { - long count = EamDb.getInstance().getCountArtifactInstancesByTypeValue(fileType, inAllDataSourcesHash); - assertEquals("Unexpected number of fileType instances retrieved when getting count of file type value for hash that should be in all 3 data sources", 3, count); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Exception thrown while getting count of file type value for hash that should exist" + ex.getMessage()); - } - - // Test getting instance count with path that should not produce results - try { - long count = EamDb.getInstance().getCountArtifactInstancesByTypeValue(fileType, unusedHashValue); - assertEquals("Unexpected number of fileType instances retrieved when getting count of file type value for hash that should not be in any data sources", 0, count); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Exception thrown while getting count of file type value for hash that should not exist" + ex.getMessage()); - } - - // Test getting instance count with null type - try { - EamDb.getInstance().getCountArtifactInstancesByTypeValue(null, inAllDataSourcesHash); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of null type attributes with a hash value"); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of null type attributes with a hash value, EamDbException was thrown instead " + ex.getMessage()); - } catch (CorrelationAttributeNormalizationException ex) { - // This is the expected behavior - } - - // Test getting instance count with null value - try { - EamDb.getInstance().getCountArtifactInstancesByTypeValue(fileType, null); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of file type attributes with a null hash value"); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of null type attributes with a null hash value, EamDbException was thrown instead " + ex.getMessage()); - } catch (CorrelationAttributeNormalizationException ex) { - // This is the expected behavior - } - - // Test getting frequency of value that is in all three data sources - try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, inAllDataSourcesHash); - int freq = EamDb.getInstance().getFrequencyPercentage(attr); - assertEquals("Unexpected frequency value of file type returned for value that should exist in all data sources", 100, freq); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Exception thrown while getting frequency of file type value for hash that should exist in all data sources" + ex.getMessage()); - } - - // Test getting frequency of value that appears twice in a single data source - try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, inDataSource1twiceHash); - int freq = EamDb.getInstance().getFrequencyPercentage(attr); - assertEquals("Unexpected frequency value of file type returned for value that should exist in one of three data sources", 33, freq); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Exception thrown while getting frequency of file type value for hash that should exist in one of three data sources" + ex.getMessage()); - } - - // Test getting frequency of non-file type - try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance(emailType, emailValue); - int freq = EamDb.getInstance().getFrequencyPercentage(attr); - assertEquals("Unexpected frequency value of email type returned for value that should exist in one of three data sources", 33, freq); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Exception thrown while getting frequency of eamil type value for value that should exist in one of three data sources" + ex.getMessage()); - } - - // Test getting frequency of non-existent value - try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, unusedHashValue); - int freq = EamDb.getInstance().getFrequencyPercentage(attr); - assertEquals("Unexpected frequency value of file type returned for value that should not exist in any data sources", 0, freq); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Exception thrown while getting frequency of eamil type value for value that should not exist in any data sources" + ex.getMessage()); - } - - // Test getting frequency with null type - try { - CorrelationAttributeInstance attr = new CorrelationAttributeInstance(null, "randomValue"); - EamDb.getInstance().getFrequencyPercentage(attr); - fail("Error Exception was expected to be thrown when getting frequency of null type attribute"); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - // This is the expected behavior - } - - // Test getting frequency with null attribute - try { - EamDb.getInstance().getFrequencyPercentage(null); - fail("Error EamDbException was expected to be thrown when getting frequency of null attribute"); - } catch (EamDbException ex) { - // This is the expected behavior - } catch (CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - fail("Error EamDbException was expected to be thrown when getting frequency of null attribute, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); - fail(ex.getMessage()); - } - - // Test updating a correlation attribute instance comment - try { - String comment = "new comment"; - - CorrelationAttributeInstance correlationAttribute = EamDb.getInstance().getCorrelationAttributeInstance( - usbDeviceType, case1, dataSource1fromCase1, devIdValue, devIdPath); - assertNotNull("Correlation Attribute returned was null when it should not have been", correlationAttribute); - - correlationAttribute.setComment(comment); - EamDb.getInstance().updateAttributeInstanceComment(correlationAttribute); - - // Get a fresh copy to verify the update. - correlationAttribute = EamDb.getInstance().getCorrelationAttributeInstance( - usbDeviceType, case1, dataSource1fromCase1, devIdValue, devIdPath); - assertEquals("Comment was not successfully set to expected value", - comment, correlationAttribute.getComment()); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Exception thrown when setting and getting comment for attribute " + ex.getMessage()); - } - - // Test getting count for dataSource1fromCase1 (includes all types) - try { - long count = EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(case1.getCaseUUID(), dataSource1fromCase1.getDeviceID()); - assertEquals("Unexpected count of artifact instances retrieved when getting count for case 1, data source 1", 7, count); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error EamDbException thrown when getting count of artifact instances for case 1, data source 1" + ex.getMessage()); - } - - // Test getting count with null case UUID - try { - long count = EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(null, dataSource1fromCase1.getDeviceID()); - assertEquals("Unexpected count of artifact instances retrieved when getting count for null case, data source 1", 0, count); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error EamDbException thrown when getting count of artifact instances for null case, data source 1" + ex.getMessage()); - } - - // Test getting count with null device ID - try { - long count = EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(case1.getCaseUUID(), null); - assertEquals("Unexpected count of artifact instances retrieved when getting count for case 1, null data source", 0, count); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error EamDbException thrown when getting count of artifact instances for case 1, null data source" + ex.getMessage()); - } - - // Test getting data source count for entry that is in all three - try { - long count = EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, inAllDataSourcesHash); - assertEquals("Unexpected count of data sources retrieved when getting count for file types with a hash that should exist in all three data sources", 3, count); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Exception thrown when getting count of data sources for file types with a hash that should exist in all three data sources" + ex.getMessage()); - } - - // Test getting data source count for entry that is in one data source twice - try { - long count = EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, inDataSource1twiceHash); - assertEquals("Unexpected count of data sources retrieved when getting count for file types with a hash that should exist in a single data source twice", 1, count); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Exception thrown when getting count of data sources for file types with a hash that should exist in a single data source twice" + ex.getMessage()); - } - - // Test getting data source count for entry that is not in any data sources - try { - long count = EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, unusedHashValue); - assertEquals("Unexpected count of data sources retrieved when getting count for file types with a hash that should not exist in any data source", 0, count); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Exception thrown when getting count of data sources for file types with a hash that should not exist in any data source" + ex.getMessage()); - } - - // Test getting data source count for null type - try { - EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(null, unusedHashValue); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing null type attribute"); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing null type attribute, EamDbException was thrown instead " + ex.getMessage()); - } catch (CorrelationAttributeNormalizationException ex) { - // This is the expected behavior - } - - // Test getting data source count for null value - try { - EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, null); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing file type attribute with null hash"); - } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); - fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing file type attribute with null hash, EamDbException was thrown instead " + ex.getMessage()); - } catch (CorrelationAttributeNormalizationException ex) { - //this is expected - } - - // Test running processinstance which queries all rows from instances table - try { - // Add two instances to the central repository and use the callback query to verify we can see them - CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath1); - CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath2); - EamDb DbManager = EamDb.getInstance(); - DbManager.addArtifactInstance(attr1); - DbManager.addArtifactInstance(attr2); - AttributeInstanceTableCallback instancetableCallback = new AttributeInstanceTableCallback(); - DbManager.processInstanceTable(fileType, instancetableCallback); - int count1 = instancetableCallback.getCounter(); - int count2 = instancetableCallback.getCounterNamingConvention(); - //expects 2 rows to match the naming convention to of been processed, expects at least one row not matching the naming convention to be processed - //if the test code is changed to add additional Correlation Attributes which also have "processinstancecallback" in their path the first of these comparisons will need to change - assertEquals("Counter for items matching naming convention from AttributeInstaceTableCallback indicates an unexepected number of results when processed with DbManager.processInstanceTable", 2, count2); - assertTrue("Counter for items which do not match naming convention from AttributeInstaceTableCallback indicates an unexepected number of results when processed with DbManager.processInstanceTable. Count indicated: " + count1 + " - expected a number greater than 0", count1 > 0); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Exception thrown when calling processInstanceTable " + ex.getMessage()); - } - - try { - //test null inputs - EamDb.getInstance().processInstanceTable(null, null); - fail("Error EamDbException was expected to be thrown when calling processInstanceTable with null inputs"); - } catch (EamDbException ex) { - // This is the expected behavior - } - - // Test running processinstance which queries all rows from instances table - try { - // Add two instances to the central repository and use the callback query to verify we can see them - CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath1); - CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath2); - EamDb DbManager = EamDb.getInstance(); - //these redundant addArtifactInstance calls allow code to be rearranged if necessary - DbManager.addArtifactInstance(attr1); - DbManager.addArtifactInstance(attr2); - AttributeInstanceTableCallback instancetableCallback = new AttributeInstanceTableCallback(); - DbManager.processInstanceTableWhere(fileType, "value='" + callbackTestFileHash + "'", instancetableCallback); - int count1 = instancetableCallback.getCounter(); - //naming convention counts - int count2 = instancetableCallback.getCounterNamingConvention(); - //this has only processed the rows where the value is equal to the specified value, which should only be the two rows with the naming convention checked for - //if the test code is changed to add additional Correlation Attributes with the same callbackTestFileHash value that is used here these comparisons will need to change - assertEquals("Counter for items matching naming convention from AttributeInstaceTableCallback indicates an unexepected number of results when processed with DbManager.processInstanceTableWhere", 2, count2); - assertEquals("Counter for items which do not match naming convention from AttributeInstaceTableCallback indicates an unexepected number of results when processed with DbManager.processInstanceTableWhere", 0, count1); - } catch (EamDbException | CorrelationAttributeNormalizationException ex) { - Exceptions.printStackTrace(ex); - Assert.fail("Error Exception thrown when calling processInstanceTableWhere " + ex.getMessage()); - } - try { - //test null inputs - EamDb.getInstance().processInstanceTableWhere(null, null, null); - fail("Error EamDbException was expected to be thrown when calling processInstanceTableWhere with null inputs"); - } catch (EamDbException ex) { - // This is the expected behavior - } +// +// //the hash value of all 0s has not been inserted +// final String unusedHashValue = "00000000000000000000000000000000"; +// +// String inAllDataSourcesHash = "6cddb0e31787b79cfdcc0676b98a71ce"; +// String inAllDataSourcesPath = "C:\\files\\path0.txt"; +// String inDataSource1twiceHash = "b2f5ff47436671b6e533d8dc3614845d"; +// String inDataSource1twicePath1 = "C:\\files\\path1.txt"; +// String inDataSource1twicePath2 = "C:\\files\\path2.txt"; +// String onlyInDataSource3Hash = "2af54305f183778d87de0c70c591fae4"; +// String onlyInDataSource3Path = "C:\\files\\path3.txt"; +// String callbackTestFilePath1 = "C:\\files\\processinstancecallback\\path1.txt"; +// String callbackTestFilePath2 = "C:\\files\\processinstancecallback\\path2.txt"; +// String callbackTestFileHash = "fb9dd8f04dacd3e82f4917f1a002223c"; +// +// // These will all go in dataSource1fromCase1 +// String emailValue = "test@gmail.com"; +// String emailPath = "C:\\files\\emailPath.txt"; +// String phoneValue = "202-555-1234"; +// String phonePath = "C:\\files\\phonePath.txt"; +// String domainValue = "www.mozilla.com"; +// String domainPath = "C:\\files\\domainPath.txt"; +// String devIdValue = "94B21234"; +// String devIdPath = "C:\\files\\devIdPath.txt"; +// +// // Store the email type +// CorrelationAttributeInstance.Type emailType; //used again for other portions of this test +// try { +// emailType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.EMAIL_TYPE_ID); +// assertEquals("Unexpected Correlation Type retrieved for Email type id", CorrelationAttributeInstance.EMAIL_TYPE_ID, emailType.getId()); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error thrown while attempting to get email attribute " + ex.getMessage()); +// return; +// } +// +// // Test adding attribute with one instance +// try { +// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(onlyInDataSource3Hash, fileType, case2, dataSource1fromCase2, onlyInDataSource3Path); +// EamDb.getInstance().addArtifactInstance(attr); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error thrown while attempting to add file attribute from single datasource the first time " + ex.getMessage()); +// } +// +// // Test adding attribute with an instance in each data source +// try { +// CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case1, dataSource1fromCase1, inAllDataSourcesPath); +// EamDb.getInstance().addArtifactInstance(attr1); +// CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case1, dataSource2fromCase1, inAllDataSourcesPath); +// EamDb.getInstance().addArtifactInstance(attr2); +// CorrelationAttributeInstance attr3 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case2, dataSource1fromCase2, inAllDataSourcesPath); +// EamDb.getInstance().addArtifactInstance(attr3); +// +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error thrown while attempting to add file attribute from all 3 datasources " + ex.getMessage()); +// } +// +// // Test adding attribute with two instances in one data source +// try { +// CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(inDataSource1twiceHash, fileType, case1, dataSource1fromCase1, inDataSource1twicePath1); +// EamDb.getInstance().addArtifactInstance(attr1); +// CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(inDataSource1twiceHash, fileType, case1, dataSource1fromCase1, inDataSource1twicePath2); +// EamDb.getInstance().addArtifactInstance(attr2); +// +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error thrown while attempting to add file attribute from single datasource the second time " + ex.getMessage()); +// } +// +// // Test adding the other types +// // Test adding an email artifact +// try { +// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(emailValue, emailType, case1, dataSource1fromCase1, emailPath); +// EamDb.getInstance().addArtifactInstance(attr); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error thrown while attempting to add email attribute from single datasource " + ex.getMessage()); +// } +// +// // Test adding a phone artifact +// try { +// CorrelationAttributeInstance attr = new CorrelationAttributeInstance( +// phoneValue, +// EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.PHONE_TYPE_ID), +// case1, dataSource1fromCase1, phonePath); +// +// EamDb.getInstance().addArtifactInstance(attr); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error thrown while attempting to add phone attribute from single datasource " + ex.getMessage()); +// } +// +// // Test adding a domain artifact +// try { +// CorrelationAttributeInstance.Type type = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.DOMAIN_TYPE_ID); +// assertEquals("Unexpected Correlation Type retrieved for Domain type id", CorrelationAttributeInstance.DOMAIN_TYPE_ID, type.getId()); +// CorrelationAttributeInstance attr = new CorrelationAttributeInstance( +// domainValue, +// type, +// case1, dataSource1fromCase1, domainPath); +// EamDb.getInstance().addArtifactInstance(attr); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error thrown while attempting to add domain attribute from single datasource " + ex.getMessage()); +// } +// +// // Test adding a device ID artifact +// try { +// CorrelationAttributeInstance attr = new CorrelationAttributeInstance( +// devIdValue, +// EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.USBID_TYPE_ID), +// case1, dataSource1fromCase1, devIdPath); +// +// EamDb.getInstance().addArtifactInstance(attr); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error thrown while attempting to add device ID attribute from single datasource " + ex.getMessage()); +// } +// +// // Test CorrelationAttributeInstance creation +// try { +// new CorrelationAttributeInstance(fileType, randomHash()); +// } catch (CorrelationAttributeNormalizationException | EamDbException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Creating correlation attribute instance " + ex.getMessage()); +// } +// +// // Test adding instance with null case +// try { +// CorrelationAttributeInstance failAttrInst = new CorrelationAttributeInstance("badInstances", fileType, null, dataSource1fromCase2, BAD_PATH); +// EamDb.getInstance().addArtifactInstance(failAttrInst); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null case and was not"); +// } catch (EamDbException ex) { +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null case, EamDbException was thrown instead " + ex.getMessage()); +// } catch (CorrelationAttributeNormalizationException ex) { +// // This is the expected behavior +// } +// +// // Test adding instance with invalid case ID +// try { +// CorrelationCase badCase = new CorrelationCase("badCaseUuid", "badCaseName"); +// CorrelationAttributeInstance failAttrInst2 = new CorrelationAttributeInstance(randomHash(), fileType, badCase, dataSource1fromCase2, BAD_PATH); +// EamDb.getInstance().addArtifactInstance(failAttrInst2); +// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid case ID and was not"); +// } catch (EamDbException ex) { +// // This is the expected behavior +// } catch (CorrelationAttributeNormalizationException ex) { +// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid case ID, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); +// } +// +// // Test adding instance with null data source +// try { +// CorrelationAttributeInstance failAttrInst3 = new CorrelationAttributeInstance(randomHash(), fileType, case1, null, BAD_PATH); +// EamDb.getInstance().addArtifactInstance(failAttrInst3); +// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null data source and was not"); +// } catch (EamDbException ex) { +// // This is the expected behavior +// } catch (CorrelationAttributeNormalizationException ex) { +// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null data source, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); +// } +// +// // Test adding instance with invalid data source ID +// try { +// CorrelationDataSource badDS = new CorrelationDataSource(case1, "badDSUuid", "badDSName"); +// CorrelationAttributeInstance failAttrInst4 = new CorrelationAttributeInstance(randomHash(), fileType, case1, badDS, BAD_PATH); +// EamDb.getInstance().addArtifactInstance(failAttrInst4); +// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid data source ID and was not"); +// } catch (EamDbException ex) { +// // This is the expected behavior +// } catch (CorrelationAttributeNormalizationException ex) { +// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with invalid data source ID, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); +// } +// +// // Test adding instance with null path +// // This will fail in the CorrelationAttributeInstance constructor +// try { +// new CorrelationAttributeInstance(randomHash(), fileType, case1, dataSource1fromCase1, null); +// fail("Error EamDbException was expected to be thrown making a CorrelationAttributeInstance with null path and was not"); +// } catch (EamDbException ex) { +// // This is the expected behavior +// } catch (CorrelationAttributeNormalizationException ex) { +// fail("Error EamDbException was expected to be thrown making a CorrelationAttributeInstance with null path, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); +// } +// +// // Test adding instance with null known status +// try { +// CorrelationAttributeInstance failAttrInst5 = new CorrelationAttributeInstance("badInstances", fileType, case1, dataSource1fromCase1, null, "comment", null); +// EamDb.getInstance().addArtifactInstance(failAttrInst5); +// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null known status and was not"); +// } catch (EamDbException ex) { +// // This is the expected behavior +// } catch (CorrelationAttributeNormalizationException ex) { +// fail("Error EamDbException was expected to be thrown making and adding a CorrelationAttributeInstance with null known status, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); +// } +// +// // Test CorrelationAttribute failure cases +// // Test null type +// try { +// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(null, randomHash()); +// EamDb.getInstance().addArtifactInstance(attr); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null type and was not"); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown making and adding a CorrelationAttributeInstance with null type, EamDbException was thrown instead " + ex.getMessage()); +// } catch (CorrelationAttributeNormalizationException ex) { +// // This is the expected behavior +// } +// +// // Test null value +// // This will fail in the CorrelationAttribute constructor +// try { +// new CorrelationAttributeInstance(fileType, null); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown making a CorrelationAttributeInstance with null type and was not"); +// } catch (CorrelationAttributeNormalizationException ex) { +// // This is the expected behavior +// } catch (EamDbException ex) { +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown making a CorrelationAttributeInstance with null type, EamDbException was thrown instead " + ex.getMessage()); +// } +// +// // Test getting instances with expected results +// try { +// List instances = EamDb.getInstance().getArtifactInstancesByTypeValue(fileType, inAllDataSourcesHash); +// assertEquals("Unexpected number of fileType instances gotten by type value for hash that should be in all 3 data sources", 3, instances.size()); +// +// // This test works because all the instances of this hash were set to the same path +// for (CorrelationAttributeInstance inst : instances) { +// assertTrue("getArtifactInstancesByTypeValue returned file instance with unexpected path " + inst.getFilePath() + " expected " + inAllDataSourcesPath, +// inAllDataSourcesPath.equalsIgnoreCase(inst.getFilePath())); +// } +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error exception thrown while getting attributes by type value " + ex.getMessage()); +// } +// +// // Test getting instances with mismatched data / data-type and expect an exception +// try { +// EamDb.getInstance().getArtifactInstancesByTypeValue(emailType, inAllDataSourcesHash); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get email type attributes with a hash value"); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get email type attributes with a hash value, EamDbException was thrown instead " + ex.getMessage()); +// } catch (CorrelationAttributeNormalizationException ex) { +// //this is expected +// } +// +// // Test getting instances with null type +// try { +// EamDb.getInstance().getArtifactInstancesByTypeValue(null, inAllDataSourcesHash); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get null type attributes with a hash value"); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get null type attributes with a hash value, EamDbException was thrown instead " + ex.getMessage()); +// } catch (CorrelationAttributeNormalizationException ex) { +// // This is the expected behavior +// } +// +// // Test getting instances with null value +// try { +// EamDb.getInstance().getArtifactInstancesByTypeValue(fileType, null); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get file type attributes with a null value"); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get file type attributes with a null value, EamDbException was thrown instead " + ex.getMessage()); +// } catch (CorrelationAttributeNormalizationException ex) { +// //this is expected +// } +// +// // Test getting instances with path that should produce results +// try { +// List instances = EamDb.getInstance().getArtifactInstancesByPath(fileType, inAllDataSourcesPath); +// assertEquals("Unexpected number of fileType instances retrieved when getting file type attributes by path that should be in all 3 data sources", 3, instances.size()); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error EamDbException thrown while getting attributes when getting file type attributes by path" + ex.getMessage()); +// } +// +// // Test getting instances with path that should not produce results +// try { +// List instances = EamDb.getInstance().getArtifactInstancesByPath(fileType, "xyz"); +// assertEquals("Unexpected number of fileType instances retrieved when getting file type attributes by path that should not be in any data sources", 0, instances.size()); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error EamDbException thrown while getting attributes when getting file type attributes by path for path that should not exist" + ex.getMessage()); +// } +// +// // Test getting instances with null type +// try { +// EamDb.getInstance().getArtifactInstancesByPath(null, inAllDataSourcesPath); +// fail("Error EamDbException was expected to be thrown when getting null type attributes by path"); +// } catch (EamDbException ex) { +// // This is the expected behavior +// } +// +// // Test getting instances with null path +// try { +// EamDb.getInstance().getArtifactInstancesByPath(fileType, null); +// fail("Error EamDbException was expected to be thrown when getting file type attributes with null path"); +// } catch (EamDbException ex) { +// // This is the expected behavior +// } +// +// // Test getting instance count with path that should produce results +// try { +// long count = EamDb.getInstance().getCountArtifactInstancesByTypeValue(fileType, inAllDataSourcesHash); +// assertEquals("Unexpected number of fileType instances retrieved when getting count of file type value for hash that should be in all 3 data sources", 3, count); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Exception thrown while getting count of file type value for hash that should exist" + ex.getMessage()); +// } +// +// // Test getting instance count with path that should not produce results +// try { +// long count = EamDb.getInstance().getCountArtifactInstancesByTypeValue(fileType, unusedHashValue); +// assertEquals("Unexpected number of fileType instances retrieved when getting count of file type value for hash that should not be in any data sources", 0, count); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Exception thrown while getting count of file type value for hash that should not exist" + ex.getMessage()); +// } +// +// // Test getting instance count with null type +// try { +// EamDb.getInstance().getCountArtifactInstancesByTypeValue(null, inAllDataSourcesHash); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of null type attributes with a hash value"); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of null type attributes with a hash value, EamDbException was thrown instead " + ex.getMessage()); +// } catch (CorrelationAttributeNormalizationException ex) { +// // This is the expected behavior +// } +// +// // Test getting instance count with null value +// try { +// EamDb.getInstance().getCountArtifactInstancesByTypeValue(fileType, null); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of file type attributes with a null hash value"); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown attempting to get count of null type attributes with a null hash value, EamDbException was thrown instead " + ex.getMessage()); +// } catch (CorrelationAttributeNormalizationException ex) { +// // This is the expected behavior +// } +// +// // Test getting frequency of value that is in all three data sources +// try { +// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, inAllDataSourcesHash); +// int freq = EamDb.getInstance().getFrequencyPercentage(attr); +// assertEquals("Unexpected frequency value of file type returned for value that should exist in all data sources", 100, freq); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Exception thrown while getting frequency of file type value for hash that should exist in all data sources" + ex.getMessage()); +// } +// +// // Test getting frequency of value that appears twice in a single data source +// try { +// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, inDataSource1twiceHash); +// int freq = EamDb.getInstance().getFrequencyPercentage(attr); +// assertEquals("Unexpected frequency value of file type returned for value that should exist in one of three data sources", 33, freq); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Exception thrown while getting frequency of file type value for hash that should exist in one of three data sources" + ex.getMessage()); +// } +// +// // Test getting frequency of non-file type +// try { +// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(emailType, emailValue); +// int freq = EamDb.getInstance().getFrequencyPercentage(attr); +// assertEquals("Unexpected frequency value of email type returned for value that should exist in one of three data sources", 33, freq); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Exception thrown while getting frequency of eamil type value for value that should exist in one of three data sources" + ex.getMessage()); +// } +// +// // Test getting frequency of non-existent value +// try { +// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, unusedHashValue); +// int freq = EamDb.getInstance().getFrequencyPercentage(attr); +// assertEquals("Unexpected frequency value of file type returned for value that should not exist in any data sources", 0, freq); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Exception thrown while getting frequency of eamil type value for value that should not exist in any data sources" + ex.getMessage()); +// } +// +// // Test getting frequency with null type +// try { +// CorrelationAttributeInstance attr = new CorrelationAttributeInstance(null, "randomValue"); +// EamDb.getInstance().getFrequencyPercentage(attr); +// fail("Error Exception was expected to be thrown when getting frequency of null type attribute"); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// // This is the expected behavior +// } +// +// // Test getting frequency with null attribute +// try { +// EamDb.getInstance().getFrequencyPercentage(null); +// fail("Error EamDbException was expected to be thrown when getting frequency of null attribute"); +// } catch (EamDbException ex) { +// // This is the expected behavior +// } catch (CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// fail("Error EamDbException was expected to be thrown when getting frequency of null attribute, CorrelationAttributeNormalizationException was thrown instead " + ex.getMessage()); +// fail(ex.getMessage()); +// } +// +// // Test updating a correlation attribute instance comment +// try { +// String comment = "new comment"; +// +// CorrelationAttributeInstance correlationAttribute = EamDb.getInstance().getCorrelationAttributeInstance( +// usbDeviceType, case1, dataSource1fromCase1, devIdValue, devIdPath); +// assertNotNull("Correlation Attribute returned was null when it should not have been", correlationAttribute); +// +// correlationAttribute.setComment(comment); +// EamDb.getInstance().updateAttributeInstanceComment(correlationAttribute); +// +// // Get a fresh copy to verify the update. +// correlationAttribute = EamDb.getInstance().getCorrelationAttributeInstance( +// usbDeviceType, case1, dataSource1fromCase1, devIdValue, devIdPath); +// assertEquals("Comment was not successfully set to expected value", +// comment, correlationAttribute.getComment()); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Exception thrown when setting and getting comment for attribute " + ex.getMessage()); +// } +// +// // Test getting count for dataSource1fromCase1 (includes all types) +// try { +// long count = EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(case1.getCaseUUID(), dataSource1fromCase1.getDeviceID()); +// assertEquals("Unexpected count of artifact instances retrieved when getting count for case 1, data source 1", 7, count); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error EamDbException thrown when getting count of artifact instances for case 1, data source 1" + ex.getMessage()); +// } +// +// // Test getting count with null case UUID +// try { +// long count = EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(null, dataSource1fromCase1.getDeviceID()); +// assertEquals("Unexpected count of artifact instances retrieved when getting count for null case, data source 1", 0, count); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error EamDbException thrown when getting count of artifact instances for null case, data source 1" + ex.getMessage()); +// } +// +// // Test getting count with null device ID +// try { +// long count = EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(case1.getCaseUUID(), null); +// assertEquals("Unexpected count of artifact instances retrieved when getting count for case 1, null data source", 0, count); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error EamDbException thrown when getting count of artifact instances for case 1, null data source" + ex.getMessage()); +// } +// +// // Test getting data source count for entry that is in all three +// try { +// long count = EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, inAllDataSourcesHash); +// assertEquals("Unexpected count of data sources retrieved when getting count for file types with a hash that should exist in all three data sources", 3, count); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Exception thrown when getting count of data sources for file types with a hash that should exist in all three data sources" + ex.getMessage()); +// } +// +// // Test getting data source count for entry that is in one data source twice +// try { +// long count = EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, inDataSource1twiceHash); +// assertEquals("Unexpected count of data sources retrieved when getting count for file types with a hash that should exist in a single data source twice", 1, count); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Exception thrown when getting count of data sources for file types with a hash that should exist in a single data source twice" + ex.getMessage()); +// } +// +// // Test getting data source count for entry that is not in any data sources +// try { +// long count = EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, unusedHashValue); +// assertEquals("Unexpected count of data sources retrieved when getting count for file types with a hash that should not exist in any data source", 0, count); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Exception thrown when getting count of data sources for file types with a hash that should not exist in any data source" + ex.getMessage()); +// } +// +// // Test getting data source count for null type +// try { +// EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(null, unusedHashValue); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing null type attribute"); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing null type attribute, EamDbException was thrown instead " + ex.getMessage()); +// } catch (CorrelationAttributeNormalizationException ex) { +// // This is the expected behavior +// } +// +// // Test getting data source count for null value +// try { +// EamDb.getInstance().getCountUniqueCaseDataSourceTuplesHavingTypeValue(fileType, null); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing file type attribute with null hash"); +// } catch (EamDbException ex) { +// Exceptions.printStackTrace(ex); +// fail("Error CorrelationAttributeNormalizationException was expected to be thrown when getting number of datasources containing file type attribute with null hash, EamDbException was thrown instead " + ex.getMessage()); +// } catch (CorrelationAttributeNormalizationException ex) { +// //this is expected +// } +// +// // Test running processinstance which queries all rows from instances table +// try { +// // Add two instances to the central repository and use the callback query to verify we can see them +// CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath1); +// CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath2); +// EamDb DbManager = EamDb.getInstance(); +// DbManager.addArtifactInstance(attr1); +// DbManager.addArtifactInstance(attr2); +// AttributeInstanceTableCallback instancetableCallback = new AttributeInstanceTableCallback(); +// DbManager.processInstanceTable(fileType, instancetableCallback); +// int count1 = instancetableCallback.getCounter(); +// int count2 = instancetableCallback.getCounterNamingConvention(); +// //expects 2 rows to match the naming convention to of been processed, expects at least one row not matching the naming convention to be processed +// //if the test code is changed to add additional Correlation Attributes which also have "processinstancecallback" in their path the first of these comparisons will need to change +// assertEquals("Counter for items matching naming convention from AttributeInstaceTableCallback indicates an unexepected number of results when processed with DbManager.processInstanceTable", 2, count2); +// assertTrue("Counter for items which do not match naming convention from AttributeInstaceTableCallback indicates an unexepected number of results when processed with DbManager.processInstanceTable. Count indicated: " + count1 + " - expected a number greater than 0", count1 > 0); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Exception thrown when calling processInstanceTable " + ex.getMessage()); +// } +// +// try { +// //test null inputs +// EamDb.getInstance().processInstanceTable(null, null); +// fail("Error EamDbException was expected to be thrown when calling processInstanceTable with null inputs"); +// } catch (EamDbException ex) { +// // This is the expected behavior +// } +// +// // Test running processinstance which queries all rows from instances table +// try { +// // Add two instances to the central repository and use the callback query to verify we can see them +// CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath1); +// CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath2); +// EamDb DbManager = EamDb.getInstance(); +// //these redundant addArtifactInstance calls allow code to be rearranged if necessary +// DbManager.addArtifactInstance(attr1); +// DbManager.addArtifactInstance(attr2); +// AttributeInstanceTableCallback instancetableCallback = new AttributeInstanceTableCallback(); +// DbManager.processInstanceTableWhere(fileType, "value='" + callbackTestFileHash + "'", instancetableCallback); +// int count1 = instancetableCallback.getCounter(); +// //naming convention counts +// int count2 = instancetableCallback.getCounterNamingConvention(); +// //this has only processed the rows where the value is equal to the specified value, which should only be the two rows with the naming convention checked for +// //if the test code is changed to add additional Correlation Attributes with the same callbackTestFileHash value that is used here these comparisons will need to change +// assertEquals("Counter for items matching naming convention from AttributeInstaceTableCallback indicates an unexepected number of results when processed with DbManager.processInstanceTableWhere", 2, count2); +// assertEquals("Counter for items which do not match naming convention from AttributeInstaceTableCallback indicates an unexepected number of results when processed with DbManager.processInstanceTableWhere", 0, count1); +// } catch (EamDbException | CorrelationAttributeNormalizationException ex) { +// Exceptions.printStackTrace(ex); +// Assert.fail("Error Exception thrown when calling processInstanceTableWhere " + ex.getMessage()); +// } +// try { +// //test null inputs +// EamDb.getInstance().processInstanceTableWhere(null, null, null); +// fail("Error EamDbException was expected to be thrown when calling processInstanceTableWhere with null inputs"); +// } catch (EamDbException ex) { +// // This is the expected behavior +// } } /** From d4fefb4dc1d21d84137903ebddbcc1d19a036d04 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 31 Oct 2018 13:19:19 -0400 Subject: [PATCH 03/70] First cut at creating a report module --- .../autopsy/report/Bundle.properties | 7 + .../autopsy/report/ReportCaseUco.java | 202 ++++++++++++++++++ 2 files changed, 209 insertions(+) create mode 100755 Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java diff --git a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties index 8efbfd9178..e888990083 100644 --- a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties @@ -45,6 +45,13 @@ ReportBodyFile.progress.processing=Now processing {0}... ReportBodyFile.getName.text=TSK Body File ReportBodyFile.getDesc.text=Body file format report with MAC times for every file. This format can be used for a timeline view. ReportBodyFile.getFilePath.text=BodyFile.txt +ReportCaseUco.progress.querying=Querying files... +ReportCaseUco.ingestWarning.text=Warning, this report was run before ingest services completed\! +ReportCaseUco.progress.loading=Loading files... +ReportCaseUco.progress.processing=Now processing {0}... +ReportCaseUco.getName.text=CASE/UCO +ReportCaseUco.getDesc.text=CASE/UCO format report with basic property fields for every file. +ReportCaseUco.getFilePath.text=CaseUco.txt ReportKML.progress.querying=Querying files... ReportKML.progress.loading=Loading files... ReportKML.getName.text=Google Earth KML diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java b/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java new file mode 100755 index 0000000000..1044080d8e --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java @@ -0,0 +1,202 @@ + /* + * + * Autopsy Forensic Browser + * + * Copyright 2012-2018 Basis Technology Corp. + * + * Copyright 2012 42six Solutions. + * Contact: aebadirad 42six com + * Project Contact/Architect: 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.report; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; +import java.util.logging.Level; +import javax.swing.JPanel; + +import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.ingest.IngestManager; +import org.sleuthkit.autopsy.report.ReportProgressPanel.ReportStatus; +import org.sleuthkit.datamodel.*; + +/** + * ReportCaseUco generates a report in the CASE/UCO format. It saves basic + * file info like full path, name, MIME type, times, and hash. + */ +class ReportCaseUco implements GeneralReportModule { + + private static final Logger logger = Logger.getLogger(ReportCaseUco.class.getName()); + private static ReportCaseUco instance = null; + + private Case currentCase; + private SleuthkitCase skCase; + + private String reportPath; + + // Hidden constructor for the report + private ReportCaseUco() { + } + + // Get the default implementation of this report + public static synchronized ReportCaseUco getDefault() { + if (instance == null) { + instance = new ReportCaseUco(); + } + return instance; + } + + /** + * Generates a CASE/UCO format report. + * + * @param baseReportDir path to save the report + * @param progressPanel panel to update the report's progress + */ + @Override + @SuppressWarnings("deprecation") + public void generateReport(String baseReportDir, ReportProgressPanel progressPanel) { + // Start the progress bar and setup the report + try { + currentCase = Case.getCurrentCaseThrows(); + } catch (NoCurrentCaseException ex) { + logger.log(Level.SEVERE, "Exception while getting open case.", ex); + return; + } + progressPanel.setIndeterminate(false); + progressPanel.start(); + progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportCaseUco.progress.querying")); + reportPath = baseReportDir + getRelativeFilePath(); //NON-NLS + + skCase = currentCase.getSleuthkitCase(); + + // Run query to get all files + try { + // exclude non-fs files/dirs and . and .. files + final String query = "type = " + TskData.TSK_DB_FILES_TYPE_ENUM.FS.getFileType() //NON-NLS + + " AND name != '.' AND name != '..'"; //NON-NLS + + progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportCaseUco.progress.loading")); + List fs = skCase.findAllFilesWhere(query); + + // Check if ingest has finished + String ingestwarning = ""; + if (IngestManager.getInstance().isIngestRunning()) { + ingestwarning = NbBundle.getMessage(this.getClass(), "ReportCaseUco.ingestWarning.text"); + } + + int size = fs.size(); + progressPanel.setMaximumProgress(size / 100); + + BufferedWriter out = null; + try { + // MD5|name|inode|mode_as_string|UID|GID|size|atime|mtime|ctime|crtime + out = new BufferedWriter(new FileWriter(reportPath, true)); + out.write(ingestwarning); + // Loop files and write info to report + int count = 0; + for (AbstractFile file : fs) { + if (progressPanel.getStatus() == ReportStatus.CANCELED) { + break; + } + if (count++ == 100) { + progressPanel.increment(); + progressPanel.updateStatusLabel( + NbBundle.getMessage(this.getClass(), "ReportCaseUco.progress.processing", + file.getName())); + count = 0; + } + + if (file.getMd5Hash() != null) { + out.write(file.getMd5Hash()); + } + out.write("|"); + if (file.getUniquePath() != null) { + out.write(file.getUniquePath()); + } + out.write("|"); + out.write(Long.toString(file.getMetaAddr())); + out.write("|"); + String modeString = file.getModesAsString(); + if (modeString != null) { + out.write(modeString); + } + out.write("|"); + out.write(Long.toString(file.getUid())); + out.write("|"); + out.write(Long.toString(file.getGid())); + out.write("|"); + out.write(Long.toString(file.getSize())); + out.write("|"); + out.write(Long.toString(file.getAtime())); + out.write("|"); + out.write(Long.toString(file.getMtime())); + out.write("|"); + out.write(Long.toString(file.getCtime())); + out.write("|"); + out.write(Long.toString(file.getCrtime())); + out.write("\n"); + } + } catch (IOException ex) { + logger.log(Level.WARNING, "Could not write the temp body file report.", ex); //NON-NLS + } finally { + try { + if (out != null) { + out.flush(); + out.close(); + Case.getCurrentCaseThrows().addReport(reportPath, + NbBundle.getMessage(this.getClass(), + "ReportCaseUco.generateReport.srcModuleName.text"), ""); + + } + } catch (IOException ex) { + logger.log(Level.WARNING, "Could not flush and close the BufferedWriter.", ex); //NON-NLS + } catch (TskCoreException | NoCurrentCaseException ex) { + String errorMessage = String.format("Error adding %s to case as a report", reportPath); //NON-NLS + logger.log(Level.SEVERE, errorMessage, ex); + } + } + progressPanel.complete(ReportStatus.COMPLETE); + } catch (TskCoreException ex) { + logger.log(Level.WARNING, "Failed to get the unique path.", ex); //NON-NLS + } + } + + @Override + public String getName() { + String name = NbBundle.getMessage(this.getClass(), "ReportCaseUco.getName.text"); + return name; + } + + @Override + public String getRelativeFilePath() { + return NbBundle.getMessage(this.getClass(), "ReportCaseUco.getFilePath.text"); + } + + @Override + public String getDescription() { + String desc = NbBundle.getMessage(this.getClass(), "ReportCaseUco.getDesc.text"); + return desc; + } + + @Override + public JPanel getConfigurationPanel() { + return null; // No configuration panel + } +} From 2193fad8a6cb92984570b11e653eb5d9eacba2ce Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 31 Oct 2018 16:30:14 -0400 Subject: [PATCH 04/70] More changes --- Core/ivy.xml | 2 + .../autopsy/report/ReportCaseUco.java | 60 +++++++++---------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/Core/ivy.xml b/Core/ivy.xml index f20453a141..3189cc9323 100644 --- a/Core/ivy.xml +++ b/Core/ivy.xml @@ -29,6 +29,8 @@ + + diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java b/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java index 1044080d8e..395b3b35da 100755 --- a/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java @@ -25,10 +25,15 @@ package org.sleuthkit.autopsy.report; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; import java.util.logging.Level; import javax.swing.JPanel; - +import com.fasterxml.jackson.core.JsonEncoding; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; @@ -50,7 +55,10 @@ class ReportCaseUco implements GeneralReportModule { private SleuthkitCase skCase; private String reportPath; - + + private JsonFactory jsonGeneratorFactory; + private JsonGenerator masterCatalog; + // Hidden constructor for the report private ReportCaseUco() { } @@ -82,7 +90,21 @@ class ReportCaseUco implements GeneralReportModule { progressPanel.setIndeterminate(false); progressPanel.start(); progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportCaseUco.progress.querying")); + + // Create the JSON generator + jsonGeneratorFactory = new JsonFactory(); + jsonGeneratorFactory.setRootValueSeparator("\r\n"); reportPath = baseReportDir + getRelativeFilePath(); //NON-NLS + Path catalogPath = Paths.get(reportPath); + try { + Files.createDirectories(catalogPath.getParent()); + java.io.File catalogFile = catalogPath.toFile(); + masterCatalog = jsonGeneratorFactory.createGenerator(catalogFile, JsonEncoding.UTF8); + } catch (IOException ex) { + logger.log(Level.SEVERE, "Error while initializing CASE/UCO report", ex); //NON-NLS + // ELTODO what else needs to be done here? + return; + } skCase = currentCase.getSleuthkitCase(); @@ -103,7 +125,7 @@ class ReportCaseUco implements GeneralReportModule { int size = fs.size(); progressPanel.setMaximumProgress(size / 100); - + BufferedWriter out = null; try { // MD5|name|inode|mode_as_string|UID|GID|size|atime|mtime|ctime|crtime @@ -123,38 +145,10 @@ class ReportCaseUco implements GeneralReportModule { count = 0; } - if (file.getMd5Hash() != null) { - out.write(file.getMd5Hash()); - } - out.write("|"); - if (file.getUniquePath() != null) { - out.write(file.getUniquePath()); - } - out.write("|"); - out.write(Long.toString(file.getMetaAddr())); - out.write("|"); - String modeString = file.getModesAsString(); - if (modeString != null) { - out.write(modeString); - } - out.write("|"); - out.write(Long.toString(file.getUid())); - out.write("|"); - out.write(Long.toString(file.getGid())); - out.write("|"); - out.write(Long.toString(file.getSize())); - out.write("|"); - out.write(Long.toString(file.getAtime())); - out.write("|"); - out.write(Long.toString(file.getMtime())); - out.write("|"); - out.write(Long.toString(file.getCtime())); - out.write("|"); - out.write(Long.toString(file.getCrtime())); - out.write("\n"); + } } catch (IOException ex) { - logger.log(Level.WARNING, "Could not write the temp body file report.", ex); //NON-NLS + logger.log(Level.WARNING, "Could not write the temp CASE/UCO report.", ex); //NON-NLS } finally { try { if (out != null) { From 72bdae97df9c5b77523240254492529b8f1b6d9a Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Fri, 2 Nov 2018 09:21:34 -0400 Subject: [PATCH 05/70] Added dependecies --- Core/nbproject/project.properties | 1 + Core/nbproject/project.xml | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Core/nbproject/project.properties b/Core/nbproject/project.properties index 1b0a695edd..e185baab75 100644 --- a/Core/nbproject/project.properties +++ b/Core/nbproject/project.properties @@ -4,6 +4,7 @@ file.reference.commons-compress-1.14.jar=release/modules/ext/commons-compress-1. file.reference.commons-dbcp2-2.1.1.jar=release\\modules\\ext\\commons-dbcp2-2.1.1.jar file.reference.commons-pool2-2.4.2.jar=release\\modules\\ext\\commons-pool2-2.4.2.jar file.reference.dd-plist-1.20.jar=release/modules/ext/dd-plist-1.20.jar +file.reference.jackson-core-2.9.7.jar=C:\\cygwin64\\home\\elivis\\autopsy\\Core\\release\\modules\\ext\\jackson-core-2.9.7.jar file.reference.jdom-2.0.5-contrib.jar=release/modules/ext/jdom-2.0.5-contrib.jar file.reference.jdom-2.0.5.jar=release/modules/ext/jdom-2.0.5.jar file.reference.jgraphx-v3.8.0.jar=release/modules/ext/jgraphx-v3.8.0.jar diff --git a/Core/nbproject/project.xml b/Core/nbproject/project.xml index d142e0b8c9..3ee4009128 100644 --- a/Core/nbproject/project.xml +++ b/Core/nbproject/project.xml @@ -338,7 +338,6 @@ org.sleuthkit.autopsy.modules.vmextractor org.sleuthkit.autopsy.progress org.sleuthkit.autopsy.report - org.sleuthkit.autopsy.tabulardatareader org.sleuthkit.datamodel @@ -357,6 +356,10 @@ ext/cxf-rt-transports-http-3.0.16.jar release/modules/ext/cxf-rt-transports-http-3.0.16.jar + + ext/sleuthkit-postgresql-4.6.3.jar + release/modules/ext/sleuthkit-postgresql-4.6.3.jar + ext/commons-validator-1.6.jar release/modules/ext/commons-validator-1.6.jar @@ -393,10 +396,6 @@ ext/sevenzipjbinding.jar release/modules/ext/sevenzipjbinding.jar - - ext/sleuthkit-postgresql-4.6.3.jar - release/modules/ext/sleuthkit-postgresql-4.6.3.jar - ext/mchange-commons-java-0.2.9.jar release/modules/ext/mchange-commons-java-0.2.9.jar @@ -433,6 +432,10 @@ ext/curator-client-2.8.0.jar release/modules/ext/curator-client-2.8.0.jar + + ext/jackson-core-2.9.7.jar + release/modules/ext/jackson-core-2.9.7.jar + ext/cxf-rt-frontend-jaxrs-3.0.16.jar release/modules/ext/cxf-rt-frontend-jaxrs-3.0.16.jar From 688bef2096c0e328330719c4943c52efa2620f4e Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Fri, 2 Nov 2018 11:12:46 -0400 Subject: [PATCH 06/70] Added JSON initialization and closing --- .../autopsy/report/Bundle.properties | 1 - .../autopsy/report/ReportCaseUco.java | 72 ++++++++----------- 2 files changed, 29 insertions(+), 44 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties index e888990083..fc46085825 100644 --- a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties @@ -51,7 +51,6 @@ ReportCaseUco.progress.loading=Loading files... ReportCaseUco.progress.processing=Now processing {0}... ReportCaseUco.getName.text=CASE/UCO ReportCaseUco.getDesc.text=CASE/UCO format report with basic property fields for every file. -ReportCaseUco.getFilePath.text=CaseUco.txt ReportKML.progress.querying=Querying files... ReportKML.progress.loading=Loading files... ReportKML.getName.text=Google Earth KML diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java b/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java index 395b3b35da..52a29118f8 100755 --- a/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java @@ -34,6 +34,7 @@ import javax.swing.JPanel; import com.fasterxml.jackson.core.JsonEncoding; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; +import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; @@ -58,6 +59,7 @@ class ReportCaseUco implements GeneralReportModule { private JsonFactory jsonGeneratorFactory; private JsonGenerator masterCatalog; + private static final String REPORT_FILE_NAME = "CaseUco.txt"; // Hidden constructor for the report private ReportCaseUco() { @@ -95,13 +97,11 @@ class ReportCaseUco implements GeneralReportModule { jsonGeneratorFactory = new JsonFactory(); jsonGeneratorFactory.setRootValueSeparator("\r\n"); reportPath = baseReportDir + getRelativeFilePath(); //NON-NLS - Path catalogPath = Paths.get(reportPath); + java.io.File reportFile = Paths.get(reportPath).toFile(); try { - Files.createDirectories(catalogPath.getParent()); - java.io.File catalogFile = catalogPath.toFile(); - masterCatalog = jsonGeneratorFactory.createGenerator(catalogFile, JsonEncoding.UTF8); + Files.createDirectories(Paths.get(reportFile.getParent())); } catch (IOException ex) { - logger.log(Level.SEVERE, "Error while initializing CASE/UCO report", ex); //NON-NLS + logger.log(Level.SEVERE, "Unable to create directory for CASE/UCO report", ex); //NON-NLS // ELTODO what else needs to be done here? return; } @@ -122,53 +122,39 @@ class ReportCaseUco implements GeneralReportModule { if (IngestManager.getInstance().isIngestRunning()) { ingestwarning = NbBundle.getMessage(this.getClass(), "ReportCaseUco.ingestWarning.text"); } + // ELTODO what to do with this warning? int size = fs.size(); progressPanel.setMaximumProgress(size / 100); - BufferedWriter out = null; - try { - // MD5|name|inode|mode_as_string|UID|GID|size|atime|mtime|ctime|crtime - out = new BufferedWriter(new FileWriter(reportPath, true)); - out.write(ingestwarning); - // Loop files and write info to report - int count = 0; - for (AbstractFile file : fs) { - if (progressPanel.getStatus() == ReportStatus.CANCELED) { - break; - } - if (count++ == 100) { - progressPanel.increment(); - progressPanel.updateStatusLabel( - NbBundle.getMessage(this.getClass(), "ReportCaseUco.progress.processing", - file.getName())); - count = 0; - } - + masterCatalog = jsonGeneratorFactory.createGenerator(reportFile, JsonEncoding.UTF8); + // Loop files and write info to report + int count = 0; + for (AbstractFile file : fs) { + if (progressPanel.getStatus() == ReportStatus.CANCELED) { + break; } - } catch (IOException ex) { - logger.log(Level.WARNING, "Could not write the temp CASE/UCO report.", ex); //NON-NLS - } finally { - try { - if (out != null) { - out.flush(); - out.close(); - Case.getCurrentCaseThrows().addReport(reportPath, - NbBundle.getMessage(this.getClass(), - "ReportCaseUco.generateReport.srcModuleName.text"), ""); - - } - } catch (IOException ex) { - logger.log(Level.WARNING, "Could not flush and close the BufferedWriter.", ex); //NON-NLS - } catch (TskCoreException | NoCurrentCaseException ex) { - String errorMessage = String.format("Error adding %s to case as a report", reportPath); //NON-NLS - logger.log(Level.SEVERE, errorMessage, ex); + if (count++ == 100) { + progressPanel.increment(); + progressPanel.updateStatusLabel( + NbBundle.getMessage(this.getClass(), "ReportCaseUco.progress.processing", + file.getName())); + count = 0; } + } progressPanel.complete(ReportStatus.COMPLETE); } catch (TskCoreException ex) { - logger.log(Level.WARNING, "Failed to get the unique path.", ex); //NON-NLS + logger.log(Level.SEVERE, "Failed to get the unique path.", ex); //NON-NLS + } catch (IOException ex) { + logger.log(Level.SEVERE, "Failed to create JSON output for the CASE/UCO report", ex); //NON-NLS + } finally { + try { + masterCatalog.close(); + } catch (IOException ex) { + logger.log(Level.WARNING, "Failed to close JSON output file", ex); //NON-NLS + } } } @@ -180,7 +166,7 @@ class ReportCaseUco implements GeneralReportModule { @Override public String getRelativeFilePath() { - return NbBundle.getMessage(this.getClass(), "ReportCaseUco.getFilePath.text"); + return REPORT_FILE_NAME; } @Override From f7187deaa8c9d5f752de7cbb54dcfd71d0780066 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Fri, 2 Nov 2018 11:28:03 -0400 Subject: [PATCH 07/70] Resolved merge conflicts --- Core/nbproject/project.properties | 2 +- Core/nbproject/project.xml | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Core/nbproject/project.properties b/Core/nbproject/project.properties index 4d4ed48d7c..529eede29a 100644 --- a/Core/nbproject/project.properties +++ b/Core/nbproject/project.properties @@ -4,7 +4,7 @@ file.reference.commons-compress-1.14.jar=release/modules/ext/commons-compress-1. file.reference.commons-dbcp2-2.1.1.jar=release\\modules\\ext\\commons-dbcp2-2.1.1.jar file.reference.commons-pool2-2.4.2.jar=release\\modules\\ext\\commons-pool2-2.4.2.jar file.reference.dd-plist-1.20.jar=release/modules/ext/dd-plist-1.20.jar -file.reference.jackson-core-2.9.7.jar=C:\\cygwin64\\home\\elivis\\autopsy\\Core\\release\\modules\\ext\\jackson-core-2.9.7.jar +file.reference.jackson-core-2.9.7.jar=release/modules/ext/jackson-core-2.9.7.jar file.reference.jdom-2.0.5-contrib.jar=release/modules/ext/jdom-2.0.5-contrib.jar file.reference.jdom-2.0.5.jar=release/modules/ext/jdom-2.0.5.jar file.reference.jgraphx-v3.8.0.jar=release/modules/ext/jgraphx-v3.8.0.jar diff --git a/Core/nbproject/project.xml b/Core/nbproject/project.xml index c81dd49204..2ddde8e977 100644 --- a/Core/nbproject/project.xml +++ b/Core/nbproject/project.xml @@ -356,10 +356,6 @@ ext/cxf-rt-transports-http-3.0.16.jar release/modules/ext/cxf-rt-transports-http-3.0.16.jar - - ext/sleuthkit-postgresql-4.6.3.jar - release/modules/ext/sleuthkit-postgresql-4.6.3.jar - ext/commons-validator-1.6.jar release/modules/ext/commons-validator-1.6.jar @@ -397,13 +393,10 @@ release/modules/ext/sevenzipjbinding.jar -<<<<<<< HEAD -======= ext/sleuthkit-postgresql-4.6.4.jar release/modules/ext/sleuthkit-postgresql-4.6.4.jar ->>>>>>> 99cef00b523307020a96d534d4cded3cf14eae98 ext/mchange-commons-java-0.2.9.jar release/modules/ext/mchange-commons-java-0.2.9.jar From 35c00ec3882ed258f0144063264e4c920d0eff3e Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Fri, 2 Nov 2018 17:07:03 -0400 Subject: [PATCH 08/70] First cut at saving files --- .../autopsy/report/ReportCaseUco.java | 65 ++++++++++++++----- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java b/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java index 52a29118f8..c8aa328983 100755 --- a/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java @@ -22,18 +22,16 @@ */ package org.sleuthkit.autopsy.report; -import java.io.BufferedWriter; -import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; import java.util.logging.Level; import javax.swing.JPanel; import com.fasterxml.jackson.core.JsonEncoding; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; +import java.sql.ResultSet; +import java.sql.SQLException; import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.casemodule.Case; @@ -110,13 +108,16 @@ class ReportCaseUco implements GeneralReportModule { // Run query to get all files try { + masterCatalog = jsonGeneratorFactory.createGenerator(reportFile, JsonEncoding.UTF8); + // exclude non-fs files/dirs and . and .. files - final String query = "type = " + TskData.TSK_DB_FILES_TYPE_ENUM.FS.getFileType() //NON-NLS + final String query = "select obj_id, name, size, ctime, crtime, atime, mtime, md5, parent_path, mime_type, extension from tsk_files where type = " + TskData.TSK_DB_FILES_TYPE_ENUM.FS.getFileType() //NON-NLS + " AND name != '.' AND name != '..'"; //NON-NLS progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportCaseUco.progress.loading")); - List fs = skCase.findAllFilesWhere(query); + SleuthkitCase.CaseDbQuery queryResult = skCase.executeQuery(query); + ResultSet resultSet = queryResult.getResultSet(); // Check if ingest has finished String ingestwarning = ""; if (IngestManager.getInstance().isIngestRunning()) { @@ -124,24 +125,38 @@ class ReportCaseUco implements GeneralReportModule { } // ELTODO what to do with this warning? - int size = fs.size(); - progressPanel.setMaximumProgress(size / 100); + int numFiles = 1000; // ELTODO resultSet.size(); + progressPanel.setMaximumProgress(numFiles / 100); - masterCatalog = jsonGeneratorFactory.createGenerator(reportFile, JsonEncoding.UTF8); - // Loop files and write info to report int count = 0; - for (AbstractFile file : fs) { + while (resultSet.next()) { + if (progressPanel.getStatus() == ReportStatus.CANCELED) { break; } - if (count++ == 100) { + + Long objectId = resultSet.getLong(1); + String dataSourceName = resultSet.getString(2); + long size = resultSet.getLong("size"); + long ctime = resultSet.getLong("ctime"); + long crtime = resultSet.getLong("crtime"); + long atime = resultSet.getLong("atime"); + long mtime = resultSet.getLong("mtime"); + String md5Hash = resultSet.getString("md5"); + String parent_path = resultSet.getString("parent_path"); + String mime_type = resultSet.getString("mime_type"); + String extension = resultSet.getString("extension"); + + addFile(objectId, dataSourceName, parent_path, md5Hash, mime_type, masterCatalog); + + /* ELTODO if (count++ == 100) { progressPanel.increment(); progressPanel.updateStatusLabel( NbBundle.getMessage(this.getClass(), "ReportCaseUco.progress.processing", file.getName())); count = 0; - } + }*/ } progressPanel.complete(ReportStatus.COMPLETE); @@ -149,6 +164,8 @@ class ReportCaseUco implements GeneralReportModule { logger.log(Level.SEVERE, "Failed to get the unique path.", ex); //NON-NLS } catch (IOException ex) { logger.log(Level.SEVERE, "Failed to create JSON output for the CASE/UCO report", ex); //NON-NLS + } catch (SQLException ex) { + logger.log(Level.WARNING, "Unable to read result set", ex); //NON-NLS } finally { try { masterCatalog.close(); @@ -158,9 +175,26 @@ class ReportCaseUco implements GeneralReportModule { } } + private void addFile(Long objectId, String dataSourceName, String parent_path, String md5Hash, String mime_type, JsonGenerator catalog) throws IOException { + catalog.writeStartObject(); + catalog.writeStringField("@id", "file-"+objectId); + catalog.writeStringField("@type", "Trace"); + catalog.writeFieldName("propertyBundle"); + catalog.writeStartArray(); + catalog.writeStartObject(); + catalog.writeStringField("@type", "File"); + catalog.writeStringField("fileName", dataSourceName); + catalog.writeStringField("filePath", parent_path); + + catalog.writeEndObject(); + catalog.writeEndArray(); + catalog.writeEndObject(); + } + @Override public String getName() { - String name = NbBundle.getMessage(this.getClass(), "ReportCaseUco.getName.text"); + //String name = NbBundle.getMessage(this.getClass(), "ReportCaseUco.getName.text"); + String name = "CASE/UCO"; return name; } @@ -171,7 +205,8 @@ class ReportCaseUco implements GeneralReportModule { @Override public String getDescription() { - String desc = NbBundle.getMessage(this.getClass(), "ReportCaseUco.getDesc.text"); + //String desc = NbBundle.getMessage(this.getClass(), "ReportCaseUco.getDesc.text"); + String desc = "CASE/UCO Report"; return desc; } From 2db0e6a602210b74151abc211eadabaa401e6cf9 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Mon, 5 Nov 2018 10:23:50 -0500 Subject: [PATCH 09/70] Changed layer.xml so that report is instanciated --- Core/src/org/sleuthkit/autopsy/core/layer.xml | 5 +++++ Core/src/org/sleuthkit/autopsy/report/Bundle.properties | 1 + Core/src/org/sleuthkit/autopsy/report/ReportCaseUco.java | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/core/layer.xml b/Core/src/org/sleuthkit/autopsy/core/layer.xml index 8bdde0f317..d87c169930 100644 --- a/Core/src/org/sleuthkit/autopsy/core/layer.xml +++ b/Core/src/org/sleuthkit/autopsy/core/layer.xml @@ -337,6 +337,11 @@ + + + + +