mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-04-07 11:26:51 +00:00
Fixed expected/actual order in tests, added ExaminableRecord tests to TPMMeasurementRecordTest
This commit is contained in:
parent
09284caa57
commit
18a8f42699
@ -21,11 +21,9 @@ public final class DeviceTest {
|
||||
*
|
||||
* @param name name for the <code>Device</code>
|
||||
*
|
||||
* @throws Exception in case there are errors getting a report
|
||||
*
|
||||
* @return device
|
||||
*/
|
||||
public static Device getTestDevice(final String name) throws Exception {
|
||||
public static Device getTestDevice(final String name) {
|
||||
final DeviceInfoReport deviceInfo = DeviceInfoReportTest.getTestReport();
|
||||
return new Device(name, deviceInfo, HealthStatus.UNKNOWN, AppraisalStatus.Status.UNKNOWN, null, false, null, null);
|
||||
}
|
||||
@ -43,13 +41,9 @@ public final class DeviceTest {
|
||||
/**
|
||||
* Tests that a name and device info report can be passed into the
|
||||
* constructor.
|
||||
*
|
||||
* @throws Exception
|
||||
* in case there are errors getting a report
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testDeviceNameAndInfo() throws Exception {
|
||||
public void testDeviceNameAndInfo() {
|
||||
final String name = "my-laptop";
|
||||
final DeviceInfoReport deviceInfo = DeviceInfoReportTest.getTestReport();
|
||||
new Device(name, deviceInfo, HealthStatus.UNKNOWN, AppraisalStatus.Status.UNKNOWN, null, false, null, null);
|
||||
@ -67,63 +61,50 @@ public final class DeviceTest {
|
||||
|
||||
/**
|
||||
* Tests that get device info report returns the device info report.
|
||||
*
|
||||
* @throws Exception
|
||||
* in case there are errors getting a report
|
||||
*/
|
||||
@Test
|
||||
public void testGetDeviceInfo() throws Exception {
|
||||
public void testGetDeviceInfo() {
|
||||
final String name = "my-laptop";
|
||||
final DeviceInfoReport deviceInfo = DeviceInfoReportTest.getTestReport();
|
||||
final Device device = new Device(name, deviceInfo, HealthStatus.UNKNOWN, AppraisalStatus.Status.UNKNOWN, null, false, null, null);
|
||||
assertEquals(device.getDeviceInfo(), deviceInfo);
|
||||
assertEquals(deviceInfo, device.getDeviceInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that device info can be set.
|
||||
*
|
||||
* @throws Exception
|
||||
* in case there are errors getting a report
|
||||
*/
|
||||
@Test
|
||||
public void testSetDeviceInfo() throws Exception {
|
||||
public void testSetDeviceInfo() {
|
||||
final String name = "my-laptop";
|
||||
final Device device = new Device(name, null, HealthStatus.UNKNOWN, AppraisalStatus.Status.UNKNOWN, null, false, null, null);
|
||||
assertNull(device.getDeviceInfo());
|
||||
final DeviceInfoReport deviceInfo = DeviceInfoReportTest.getTestReport();
|
||||
device.setDeviceInfo(deviceInfo);
|
||||
assertEquals(device.getDeviceInfo(), deviceInfo);
|
||||
assertEquals(deviceInfo, device.getDeviceInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that get device info report returns the device info report.
|
||||
*
|
||||
* @throws Exception
|
||||
* in case there are errors getting a report
|
||||
*/
|
||||
@Test
|
||||
public void testSetNullDeviceInfo() throws Exception {
|
||||
public void testSetNullDeviceInfo() {
|
||||
final String name = "my-laptop";
|
||||
final DeviceInfoReport deviceInfo = DeviceInfoReportTest.getTestReport();
|
||||
final Device device = new Device(name, deviceInfo, HealthStatus.UNKNOWN, AppraisalStatus.Status.UNKNOWN, null, false, null, null);
|
||||
assertEquals(device.getDeviceInfo(), deviceInfo);
|
||||
assertEquals(deviceInfo, device.getDeviceInfo());
|
||||
device.setDeviceInfo(null);
|
||||
assertNull(device.getDeviceInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that retrieving a null LastReportTimestamp will not trigger an exception.
|
||||
*
|
||||
* @throws Exception
|
||||
* In case there is an error getting a report
|
||||
*/
|
||||
@Test
|
||||
public void testNullLastReportTimeStamp() throws Exception {
|
||||
public void testNullLastReportTimeStamp() {
|
||||
final String name = "my-laptop";
|
||||
final DeviceInfoReport deviceInfo = DeviceInfoReportTest.getTestReport();
|
||||
final Device device = new Device(name, deviceInfo, HealthStatus.UNKNOWN, AppraisalStatus.Status.UNKNOWN, null, false, null, null);
|
||||
assertNull(device.getLastReportTimestamp());
|
||||
//Successful if test does not throw Exception
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,12 +119,9 @@ public final class DeviceTest {
|
||||
|
||||
/**
|
||||
* Tests equals returns true for two devices that have the same name.
|
||||
*
|
||||
* @throws Exception
|
||||
* in case there are errors getting a report
|
||||
*/
|
||||
@Test
|
||||
public void testDeviceEquals() throws Exception {
|
||||
public void testDeviceEquals() {
|
||||
final String name = "my-laptop";
|
||||
final String otherName = "my-laptop";
|
||||
final DeviceInfoReport deviceInfo = DeviceInfoReportTest.getTestReport();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package hirs.attestationca.persist.entity.userdefined.record;
|
||||
|
||||
import hirs.attestationca.persist.entity.userdefined.ExaminableRecord;
|
||||
import hirs.utils.digest.Digest;
|
||||
import hirs.utils.digest.DigestAlgorithm;
|
||||
import org.apache.commons.codec.DecoderException;
|
||||
@ -25,6 +26,7 @@ public class TPMMeasurementRecordTest {
|
||||
private static final int DEFAULT_PCR_ID = 3;
|
||||
private static final String DEFAULT_HASH =
|
||||
"3d5f3c2f7f3003d2e4baddc46ed4763a4954f648";
|
||||
private static final ExaminableRecord.ExamineState DEFAULT_STATE = ExaminableRecord.ExamineState.UNEXAMINED;
|
||||
|
||||
/**
|
||||
* Tests instantiation of new <code>PCRMeasurementRecord</code>.
|
||||
@ -90,6 +92,15 @@ public class TPMMeasurementRecordTest {
|
||||
assertNotNull(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that <code>getExamineState</code> returns the correct state.
|
||||
*/
|
||||
@Test
|
||||
public final void getExamineState() {
|
||||
final TPMMeasurementRecord record = getDefaultRecord();
|
||||
assertEquals(DEFAULT_STATE, record.getExamineState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that two <code>IMAMeasurementRecord</code>s are equal if they have
|
||||
* the same name and the same path.
|
||||
@ -214,6 +225,48 @@ public class TPMMeasurementRecordTest {
|
||||
TPMMeasurementRecord.checkForValidPcrId(pcrId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the ExamineState can be successfully set to EXAMINED.
|
||||
*/
|
||||
@Test
|
||||
public final void testSetExamineStateExamined() {
|
||||
final ExaminableRecord.ExamineState state = ExaminableRecord.ExamineState.EXAMINED;
|
||||
TPMMeasurementRecord r1 = getDefaultRecord();
|
||||
r1.setExamineState(state);
|
||||
assertEquals(state, r1.getExamineState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the ExamineState can be successfully set to IGNORED.
|
||||
*/
|
||||
@Test
|
||||
public final void testSetExamineStateIgnored() {
|
||||
final ExaminableRecord.ExamineState state = ExaminableRecord.ExamineState.IGNORED;
|
||||
TPMMeasurementRecord r1 = getDefaultRecord();
|
||||
r1.setExamineState(state);
|
||||
assertEquals(state, r1.getExamineState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the ExamineState is successfully initialized to UNEXAMINED.
|
||||
*/
|
||||
@Test
|
||||
public final void testSetExamineStateInitial() {
|
||||
TPMMeasurementRecord r1 = getDefaultRecord();
|
||||
assertEquals(ExaminableRecord.ExamineState.UNEXAMINED, r1.getExamineState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that setting the ExamineState to UNEXAMINED throws an IllegalArgumentException.
|
||||
*/
|
||||
@Test
|
||||
public final void testSetExamineStateUnexamined() {
|
||||
final ExaminableRecord.ExamineState state = ExaminableRecord.ExamineState.UNEXAMINED;
|
||||
TPMMeasurementRecord r1 = getDefaultRecord();
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
r1.setExamineState(state));
|
||||
}
|
||||
|
||||
private TPMMeasurementRecord getDefaultRecord() {
|
||||
return new TPMMeasurementRecord(DEFAULT_PCR_ID,
|
||||
getDigest(DEFAULT_HASH));
|
||||
|
@ -94,13 +94,12 @@ public class DeviceInfoReportTest {
|
||||
public final void testGetters() {
|
||||
DeviceInfoReport deviceInfoReport =
|
||||
new DeviceInfoReport(networkInfo, osInfo, firmwareInfo, hardwareInfo, tpmInfo);
|
||||
assertEquals(deviceInfoReport.getNetworkInfo(), networkInfo);
|
||||
assertEquals(deviceInfoReport.getOSInfo(), osInfo);
|
||||
assertEquals(deviceInfoReport.getFirmwareInfo(), firmwareInfo);
|
||||
assertEquals(deviceInfoReport.getHardwareInfo(), hardwareInfo);
|
||||
assertEquals(deviceInfoReport.getTpmInfo(), tpmInfo);
|
||||
assertEquals(deviceInfoReport.getClientApplicationVersion(),
|
||||
EXPECTED_CLIENT_VERSION);
|
||||
assertEquals(networkInfo, deviceInfoReport.getNetworkInfo());
|
||||
assertEquals(osInfo, deviceInfoReport.getOSInfo());
|
||||
assertEquals(firmwareInfo, deviceInfoReport.getFirmwareInfo());
|
||||
assertEquals(hardwareInfo, deviceInfoReport.getHardwareInfo());
|
||||
assertEquals(tpmInfo, deviceInfoReport.getTpmInfo());
|
||||
assertEquals(EXPECTED_CLIENT_VERSION, deviceInfoReport.getClientApplicationVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user