mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-09 06:39:33 +00:00
validation modifications and test code modifications
This commit is contained in:
parent
4c48fd4454
commit
cebb79822e
@ -117,7 +117,15 @@ final public class CorrelationAttributeNormalizer {
|
||||
if(validator.isValid(data)){
|
||||
return data.toLowerCase();
|
||||
} else {
|
||||
throw new CorrelationAttributeNormalizationException(String.format("Data was expected to be a valid domain: %s", data));
|
||||
if(data == null){
|
||||
throw new CorrelationAttributeNormalizationException("Data was expected to be a valid domain: null");
|
||||
}
|
||||
final String validIpAddressRegex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$";
|
||||
if(data.matches(validIpAddressRegex)){
|
||||
return data;
|
||||
} else {
|
||||
throw new CorrelationAttributeNormalizationException(String.format("Data was expected to be a valid domain: %s", data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,19 +154,10 @@ final public class CorrelationAttributeNormalizer {
|
||||
}
|
||||
|
||||
/**
|
||||
* USB ID is of the form: hhhh:hhhh where h is a hex digit. Convert to lower case.
|
||||
* Vacuous - will be replaced with something reasonable later.
|
||||
*/
|
||||
private static String normalizeUsbId(String data) throws CorrelationAttributeNormalizationException {
|
||||
final String errorMessage = "Data was expected to be a valid USB device ID: %s";
|
||||
if(data == null){
|
||||
throw new CorrelationAttributeNormalizationException(String.format(errorMessage, data));
|
||||
}
|
||||
|
||||
String validUsbIdRegex = "^(0[Xx])?[A-Fa-f0-9]{4}[:\\\\\\ \\-.]?(0[Xx])?[A-Fa-f0-9]{4}$";
|
||||
if(data.matches(validUsbIdRegex)){
|
||||
return data.toLowerCase();
|
||||
} else {
|
||||
throw new CorrelationAttributeNormalizationException(String.format(errorMessage, data));
|
||||
}
|
||||
//TODO replace with correct usb id validation at a later date
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
package org.sleuthkit.autopsy.centralrepository.datamodel;
|
||||
|
||||
import junit.framework.Test;
|
||||
import org.junit.Assert;
|
||||
import org.netbeans.junit.NbModuleSuite;
|
||||
import org.netbeans.junit.NbTestCase;
|
||||
import org.openide.util.Exceptions;
|
||||
@ -294,69 +295,21 @@ public class CorrelationAttributeNormalizerTest extends NbTestCase {
|
||||
|
||||
public void testValidateUsbId() {
|
||||
final String goodIdOne = "0202:AAFF"; //should pass and be lowered
|
||||
final String goodIdTwo = "0202:aaff"; //should pass
|
||||
//TODO add all this back when theres is something to validate
|
||||
/*final String goodIdTwo = "0202:aaff"; //should pass
|
||||
final String badIdThree = "0202:axxf"; //should fail
|
||||
final String badIdFour = ""; //should fail
|
||||
final String badIdFive = null; //should fail
|
||||
final String goodIdSix = "0202 AAFF"; //should pass
|
||||
final String goodIdSeven = "0202AAFF"; //should pass
|
||||
final String goodIdEight = "0202-AAFF"; //should pass
|
||||
final String goodIdEight = "0202-AAFF"; //should pass*/
|
||||
|
||||
final int USBID_TYPE_ID = CorrelationAttribute.USBID_TYPE_ID;
|
||||
|
||||
try {
|
||||
assertTrue(THIS_USB_ID_SHOULD_PASS, CorrelationAttributeNormalizer.normalize(USBID_TYPE_ID, goodIdOne).equals(goodIdOne.toLowerCase()));
|
||||
assertTrue(THIS_USB_ID_SHOULD_PASS, CorrelationAttributeNormalizer.normalize(USBID_TYPE_ID, goodIdOne).equals(goodIdOne));
|
||||
} catch (CorrelationAttributeNormalizationException ex) {
|
||||
Exceptions.printStackTrace(ex);
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
try {
|
||||
assertTrue(THIS_USB_ID_SHOULD_PASS, CorrelationAttributeNormalizer.normalize(USBID_TYPE_ID, goodIdTwo).equals(goodIdTwo));
|
||||
} catch (CorrelationAttributeNormalizationException ex) {
|
||||
Exceptions.printStackTrace(ex);
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
try {
|
||||
assertTrue("This USB ID should fail.", CorrelationAttributeNormalizer.normalize(USBID_TYPE_ID, badIdThree).equals(badIdThree));
|
||||
fail(THIS_SHOULD_HAVE_THROWN_AN_EXCEPTION);
|
||||
} catch (CorrelationAttributeNormalizationException ex) {
|
||||
assertTrue(WE_EXPECT_AN_EXCEPTION_HERE, true);
|
||||
}
|
||||
try {
|
||||
CorrelationAttributeNormalizer.normalize(USBID_TYPE_ID, badIdFour);
|
||||
fail(THIS_SHOULD_HAVE_THROWN_AN_EXCEPTION);
|
||||
} catch (CorrelationAttributeNormalizationException ex) {
|
||||
assertTrue(WE_EXPECT_AN_EXCEPTION_HERE, true);
|
||||
}
|
||||
try {
|
||||
CorrelationAttributeNormalizer.normalize(USBID_TYPE_ID, badIdFive);
|
||||
fail(THIS_SHOULD_HAVE_THROWN_AN_EXCEPTION);
|
||||
} catch (CorrelationAttributeNormalizationException ex) {
|
||||
assertTrue(WE_EXPECT_AN_EXCEPTION_HERE, true);
|
||||
}
|
||||
try {
|
||||
CorrelationAttributeNormalizer.normalize(USBID_TYPE_ID, badIdFive);
|
||||
fail(THIS_SHOULD_HAVE_THROWN_AN_EXCEPTION);
|
||||
} catch (CorrelationAttributeNormalizationException ex) {
|
||||
assertTrue(WE_EXPECT_AN_EXCEPTION_HERE, true);
|
||||
}
|
||||
try {
|
||||
assertTrue(THIS_USB_ID_SHOULD_PASS, CorrelationAttributeNormalizer.normalize(USBID_TYPE_ID, goodIdSix).equals(goodIdSix.toLowerCase()));
|
||||
} catch (CorrelationAttributeNormalizationException ex) {
|
||||
Exceptions.printStackTrace(ex);
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
try {
|
||||
assertTrue(THIS_USB_ID_SHOULD_PASS, CorrelationAttributeNormalizer.normalize(USBID_TYPE_ID, goodIdSeven).equals(goodIdSeven.toLowerCase()));
|
||||
} catch (CorrelationAttributeNormalizationException ex) {
|
||||
Exceptions.printStackTrace(ex);
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
try {
|
||||
assertTrue(THIS_USB_ID_SHOULD_PASS, CorrelationAttributeNormalizer.normalize(USBID_TYPE_ID, goodIdEight).equals(goodIdEight.toLowerCase()));
|
||||
} catch (CorrelationAttributeNormalizationException ex) {
|
||||
Exceptions.printStackTrace(ex);
|
||||
fail(ex.getMessage());
|
||||
Assert.fail(ex.getMessage());
|
||||
}
|
||||
}
|
||||
private static final String THIS_USB_ID_SHOULD_PASS = "This USB ID should pass.";
|
||||
|
Loading…
x
Reference in New Issue
Block a user