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