mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-01-31 00:24:00 +00:00
removing unit test dependency on other unit test; comments cleanup
This commit is contained in:
parent
5bf7661e56
commit
aad508fdb9
@ -6,8 +6,6 @@ import hirs.attestationca.persist.entity.userdefined.info.*;
|
||||
import hirs.attestationca.persist.entity.userdefined.report.DeviceInfoReport;
|
||||
import hirs.attestationca.persist.entity.userdefined.report.DeviceInfoReportTest;
|
||||
import hirs.attestationca.persist.enums.AppraisalStatus;
|
||||
import hirs.attestationca.persist.enums.HealthStatus;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -26,7 +24,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Class with common functions for Userdefined Entity object tests.
|
||||
* Class with definitions and functions common to multiple Userdefined Entity object tests.
|
||||
*
|
||||
*/
|
||||
public class AbstractUserdefinedEntityTest {
|
||||
@ -54,15 +52,19 @@ public class AbstractUserdefinedEntityTest {
|
||||
public static final String FAKE_ROOT_CA_SUBJECT_KEY_IDENTIFIER_HEX =
|
||||
"58ec313a1699f94c1c8c4e2c6412402b258f0177";
|
||||
|
||||
/**
|
||||
* Location of a test identity certificate.
|
||||
*/
|
||||
private static final String TEST_IDENTITY_CERT = "/tpm/sample_identity_cert.cer";
|
||||
|
||||
private final NetworkInfo networkInfo = createTestNetworkInfo();
|
||||
private final OSInfo osInfo = createTestOSInfo();
|
||||
private final FirmwareInfo firmwareInfo = createTestFirmwareInfo();
|
||||
private final HardwareInfo hardwareInfo = createTestHardwareInfo();
|
||||
private final TPMInfo tpmInfo = createTPMInfo();
|
||||
// private final NetworkInfo networkInfo = createTestNetworkInfo();
|
||||
// private final OSInfo osInfo = createTestOSInfo();
|
||||
// private final FirmwareInfo firmwareInfo = createTestFirmwareInfo();
|
||||
// private final HardwareInfo hardwareInfo = createTestHardwareInfo();
|
||||
// private final TPMInfo tpmInfo = createTPMInfo();
|
||||
private static final Logger LOGGER = LogManager.getLogger(DeviceInfoReportTest.class);
|
||||
|
||||
public static final String VALIDATION_MESSAGE = "Some message.";
|
||||
|
||||
/**
|
||||
* Construct a test certificate from the given parameters.
|
||||
@ -137,12 +139,6 @@ public class AbstractUserdefinedEntityTest {
|
||||
);
|
||||
}
|
||||
|
||||
public static Device getTestDevice(final String name) {
|
||||
final DeviceInfoReport deviceInfo = AbstractUserdefinedEntityTest.getTestDeviceInfoReport();
|
||||
return new Device(name, deviceInfo, HealthStatus.UNKNOWN, AppraisalStatus.Status.UNKNOWN, null, false, null, null);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DeviceInfoReport instance usable for testing.
|
||||
*
|
||||
@ -153,7 +149,6 @@ public class AbstractUserdefinedEntityTest {
|
||||
createTestNetworkInfo(), createTestOSInfo(), createTestFirmwareInfo(),
|
||||
createTestHardwareInfo(), createTPMInfo()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -248,4 +243,23 @@ public class AbstractUserdefinedEntityTest {
|
||||
return certificateValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a SupplyChainValidation for use in tests according to the provided parameters.
|
||||
*
|
||||
* @param type the type of validation
|
||||
* @param result the appraisal result
|
||||
* @param certificates the certificates related to this validation
|
||||
* @return the resulting SupplyChainValidation object
|
||||
*/
|
||||
public static SupplyChainValidation getTestSupplyChainValidation(
|
||||
final SupplyChainValidation.ValidationType type,
|
||||
final AppraisalStatus.Status result,
|
||||
final List<ArchivableEntity> certificates) {
|
||||
return new SupplyChainValidation(
|
||||
type,
|
||||
result,
|
||||
certificates,
|
||||
VALIDATION_MESSAGE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -27,17 +27,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
* This class tests functionality of the {@link Certificate} class.
|
||||
*/
|
||||
public class CertificateTest extends AbstractUserdefinedEntityTest {
|
||||
// /**
|
||||
// * Location of a test (fake) root CA certificate.
|
||||
// */
|
||||
// //j
|
||||
// public static final String FAKE_ROOT_CA_FILE = "/certificates/fakeRootCA.cer";
|
||||
|
||||
// /**
|
||||
// * Location of a test (fake) Intel intermediate CA certificate.
|
||||
// */
|
||||
// public static final String FAKE_INTEL_INT_CA_FILE =
|
||||
// "/certificates/fakeIntelIntermediateCA.cer";
|
||||
|
||||
/**
|
||||
* Location of a test (fake) Intel intermediate CA certificate.
|
||||
@ -45,11 +34,6 @@ public class CertificateTest extends AbstractUserdefinedEntityTest {
|
||||
public static final String INTEL_INT_CA_FILE =
|
||||
"/validation/platform_credentials/intel_chain/root/intermediate2.cer";
|
||||
|
||||
// /**
|
||||
// * Location of a test (fake) SGI intermediate CA certificate.
|
||||
// */
|
||||
// public static final String FAKE_SGI_INT_CA_FILE = "/certificates/fakeSGIIntermediateCA.cer";
|
||||
|
||||
/**
|
||||
* Location of another test self-signed certificate.
|
||||
*/
|
||||
@ -75,13 +59,6 @@ public class CertificateTest extends AbstractUserdefinedEntityTest {
|
||||
* Location of the GlobalSign Root CA certificate.
|
||||
*/
|
||||
public static final String GS_ROOT_CA = "/certificates/stMicroCaCerts/gstpmroot.crt";
|
||||
//
|
||||
// /**
|
||||
// * Hex-encoded subject key identifier for the FAKE_ROOT_CA_FILE.
|
||||
// */
|
||||
// //j
|
||||
// public static final String FAKE_ROOT_CA_SUBJECT_KEY_IDENTIFIER_HEX =
|
||||
// "58ec313a1699f94c1c8c4e2c6412402b258f0177";
|
||||
|
||||
/**
|
||||
* Location of a test STM endorsement credential.
|
||||
|
@ -1,7 +1,6 @@
|
||||
package hirs.attestationca.persist.entity.userdefined;
|
||||
|
||||
import hirs.attestationca.persist.entity.userdefined.report.DeviceInfoReport;
|
||||
import hirs.attestationca.persist.entity.userdefined.report.DeviceInfoReportTest;
|
||||
import hirs.attestationca.persist.enums.AppraisalStatus;
|
||||
import hirs.attestationca.persist.enums.HealthStatus;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -15,18 +14,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
*
|
||||
*/
|
||||
public final class DeviceTest extends AbstractUserdefinedEntityTest {
|
||||
/**
|
||||
* Utility method for getting a <code>Device</code> that can be used for
|
||||
* testing.
|
||||
*
|
||||
* @param name name for the <code>Device</code>
|
||||
*
|
||||
* @return device
|
||||
*/
|
||||
public static Device getTestDevice(final String name) {
|
||||
final DeviceInfoReport deviceInfo = getTestDeviceInfoReport();
|
||||
return new Device(name, deviceInfo, HealthStatus.UNKNOWN, AppraisalStatus.Status.UNKNOWN, null, false, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the device constructor can take a name.
|
||||
|
@ -1,7 +1,9 @@
|
||||
package hirs.attestationca.persist.entity.userdefined;
|
||||
|
||||
import hirs.attestationca.persist.entity.ArchivableEntity;
|
||||
import hirs.attestationca.persist.entity.userdefined.report.DeviceInfoReport;
|
||||
import hirs.attestationca.persist.enums.AppraisalStatus;
|
||||
import hirs.attestationca.persist.enums.HealthStatus;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import java.util.*;
|
||||
@ -11,26 +13,34 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* Integration test that tests the functionality in SupplyChainValidationSummary,
|
||||
* as well as the persistence of SupplyChainValidationSummary and SupplyChainValidation.
|
||||
* Tests the functionality in SupplyChainValidationSummary.
|
||||
*/
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class SupplyChainValidationSummaryTest {
|
||||
public class SupplyChainValidationSummaryTest extends AbstractUserdefinedEntityTest {
|
||||
|
||||
/**
|
||||
* Test device
|
||||
*
|
||||
*/
|
||||
private Device device;
|
||||
|
||||
/**
|
||||
* List of test certificates
|
||||
*
|
||||
*/
|
||||
private List<ArchivableEntity> certificates;
|
||||
|
||||
/**
|
||||
* Create a session factory to use for persistence testing and persist some certificates
|
||||
* for use by these tests.
|
||||
* Create a set of certificates and a device for use by these tests.
|
||||
*
|
||||
* @throws Exception if there is a problem deserializing certificates or creating test device
|
||||
*/
|
||||
@BeforeAll
|
||||
public void setup() throws Exception {
|
||||
|
||||
certificates = CertificateTest.getAllTestCertificates();
|
||||
device = AbstractUserdefinedEntityTest.getTestDevice("TestDevice");
|
||||
certificates = getAllTestCertificates();
|
||||
device = getTestDevice("TestDevice");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,6 +153,20 @@ public class SupplyChainValidationSummaryTest {
|
||||
assertNotNull(twoBadValidations.getCreateTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method for getting a <code>Device</code> that can be used for
|
||||
* testing.
|
||||
*
|
||||
* @param name name for the <code>Device</code>
|
||||
*
|
||||
* @return device
|
||||
*/
|
||||
public static Device getTestDevice(final String name) {
|
||||
final DeviceInfoReport deviceInfo = getTestDeviceInfoReport();
|
||||
return new Device(name, deviceInfo, HealthStatus.UNKNOWN, AppraisalStatus.Status.UNKNOWN, null, false, null, null);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -1,21 +1,18 @@
|
||||
package hirs.attestationca.persist.entity.userdefined;
|
||||
|
||||
import hirs.attestationca.persist.entity.ArchivableEntity;
|
||||
import hirs.attestationca.persist.enums.AppraisalStatus;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Simple tests for the {@link SupplyChainValidation} class. Tests for the persistence of this
|
||||
* class are located in { SupplyChainValidationSummaryTest}.
|
||||
*/
|
||||
class SupplyChainValidationTest extends AbstractUserdefinedEntityTest {
|
||||
private static final String MESSAGE = "Some message.";
|
||||
|
||||
/**
|
||||
* Test that this class' getter methods work properly.
|
||||
@ -33,7 +30,7 @@ class SupplyChainValidationTest extends AbstractUserdefinedEntityTest {
|
||||
validation.getCertificatesUsed(),
|
||||
getAllTestCertificates()
|
||||
);
|
||||
assertEquals(validation.getMessage(), MESSAGE);
|
||||
assertEquals(validation.getMessage(), VALIDATION_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,7 +45,7 @@ class SupplyChainValidationTest extends AbstractUserdefinedEntityTest {
|
||||
null,
|
||||
AppraisalStatus.Status.PASS,
|
||||
getAllTestCertificates(),
|
||||
MESSAGE
|
||||
VALIDATION_MESSAGE
|
||||
));
|
||||
}
|
||||
|
||||
@ -64,7 +61,7 @@ class SupplyChainValidationTest extends AbstractUserdefinedEntityTest {
|
||||
SupplyChainValidation.ValidationType.ENDORSEMENT_CREDENTIAL,
|
||||
AppraisalStatus.Status.PASS,
|
||||
null,
|
||||
MESSAGE
|
||||
VALIDATION_MESSAGE
|
||||
));
|
||||
}
|
||||
|
||||
@ -79,7 +76,7 @@ class SupplyChainValidationTest extends AbstractUserdefinedEntityTest {
|
||||
SupplyChainValidation.ValidationType.ENDORSEMENT_CREDENTIAL,
|
||||
AppraisalStatus.Status.PASS,
|
||||
getAllTestCertificates(),
|
||||
MESSAGE
|
||||
VALIDATION_MESSAGE
|
||||
);
|
||||
}
|
||||
|
||||
@ -98,24 +95,4 @@ class SupplyChainValidationTest extends AbstractUserdefinedEntityTest {
|
||||
getAllTestCertificates()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a SupplyChainValidation for use in tests according to the provided parameters.
|
||||
*
|
||||
* @param type the type of validation
|
||||
* @param result the appraisal result
|
||||
* @param certificates the certificates related to this validation
|
||||
* @return the resulting SupplyChainValidation object
|
||||
*/
|
||||
public static SupplyChainValidation getTestSupplyChainValidation(
|
||||
final SupplyChainValidation.ValidationType type,
|
||||
final AppraisalStatus.Status result,
|
||||
final List<ArchivableEntity> certificates) {
|
||||
return new SupplyChainValidation(
|
||||
type,
|
||||
result,
|
||||
certificates,
|
||||
MESSAGE
|
||||
);
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package hirs.attestationca.persist.entity.userdefined.certificate;
|
||||
|
||||
import hirs.attestationca.persist.entity.userdefined.AbstractUserdefinedEntityTest;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -12,13 +11,11 @@ import java.net.URISyntaxException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.cert.CertificateException;
|
||||
import hirs.attestationca.persist.entity.manager.CertificateRepository;
|
||||
|
||||
/**
|
||||
* Tests that CertificateAuthorityCredential properly parses its fields.
|
||||
*/
|
||||
public class CertificateAuthorityCredentialTest extends AbstractUserdefinedEntityTest {
|
||||
private static final CertificateRepository CERT_MAN = mock(CertificateRepository.class);
|
||||
|
||||
/**
|
||||
* Tests that a CertificateAuthorityCredential can be created from an X.509 certificate and
|
||||
|
@ -7,17 +7,12 @@ import hirs.attestationca.persist.entity.userdefined.info.NetworkInfo;
|
||||
import hirs.attestationca.persist.entity.userdefined.info.HardwareInfo;
|
||||
import hirs.attestationca.persist.entity.userdefined.info.FirmwareInfo;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* DeviceInfoReportTest is a unit test class for DeviceInfoReports.
|
||||
* Unit test class for DeviceInfoReports.
|
||||
*/
|
||||
public class DeviceInfoReportTest extends AbstractUserdefinedEntityTest {
|
||||
private final NetworkInfo networkInfo = createTestNetworkInfo();
|
||||
@ -26,8 +21,6 @@ public class DeviceInfoReportTest extends AbstractUserdefinedEntityTest {
|
||||
private final HardwareInfo hardwareInfo = createTestHardwareInfo();
|
||||
private final TPMInfo tpmInfo = createTPMInfo();
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DeviceInfoReportTest.class);
|
||||
|
||||
private static final String EXPECTED_CLIENT_VERSION = "Test.Version";
|
||||
|
||||
/**
|
||||
@ -96,66 +89,4 @@ public class DeviceInfoReportTest extends AbstractUserdefinedEntityTest {
|
||||
assertEquals(tpmInfo, deviceInfoReport.getTpmInfo());
|
||||
assertEquals(EXPECTED_CLIENT_VERSION, deviceInfoReport.getClientApplicationVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DeviceInfoReport instance usable for testing.
|
||||
*
|
||||
* @return a test DeviceInfoReport
|
||||
*/
|
||||
public static DeviceInfoReport getTestReport() {
|
||||
return new DeviceInfoReport(
|
||||
createTestNetworkInfo(), createTestOSInfo(), createTestFirmwareInfo(),
|
||||
createTestHardwareInfo(), createTPMInfo()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test instance of NetworkInfo.
|
||||
*
|
||||
* @return network information for a fake device
|
||||
*/
|
||||
public static NetworkInfo createTestNetworkInfo() {
|
||||
try {
|
||||
final String hostname = "test.hostname";
|
||||
final InetAddress ipAddress =
|
||||
InetAddress.getByAddress(new byte[] {127, 0, 0, 1});
|
||||
final byte[] macAddress = new byte[] {11, 22, 33, 44, 55, 66};
|
||||
return new NetworkInfo(hostname, ipAddress, macAddress);
|
||||
|
||||
} catch (UnknownHostException e) {
|
||||
LOGGER.error("error occurred while creating InetAddress");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test instance of OSInfo.
|
||||
*
|
||||
* @return OS information for a fake device
|
||||
*/
|
||||
public static OSInfo createTestOSInfo() {
|
||||
return new OSInfo("test os name", "test os version", "test os arch",
|
||||
"test distribution", "test distribution release");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test instance of FirmwareInfo.
|
||||
*
|
||||
* @return Firmware information for a fake device
|
||||
*/
|
||||
public static FirmwareInfo createTestFirmwareInfo() {
|
||||
return new FirmwareInfo("test bios vendor", "test bios version", "test bios release date");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test instance of HardwareInfo.
|
||||
*
|
||||
* @return Hardware information for a fake device
|
||||
*/
|
||||
public static HardwareInfo createTestHardwareInfo() {
|
||||
return new HardwareInfo("test manufacturer", "test product name", "test version",
|
||||
"test really long serial number with many characters", "test really long chassis "
|
||||
+ "serial number with many characters",
|
||||
"test really long baseboard serial number with many characters");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user