mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-03-14 08:16:26 +00:00
issue_896: Placed test task in the root build.gradle. Made more fixes to the test classes.
Some checks are pending
Dotnet Provisioner Unit Tests / Restore and Run Unit Tests (ubuntu-20.04) (push) Waiting to run
Dotnet Provisioner Unit Tests / Restore and Run Unit Tests (windows-2022) (push) Waiting to run
Dotnet Provisioner Unit Tests / Evaluate Tests (push) Blocked by required conditions
HIRS Build and Unit Test / ACA_Provisioner_Unit_Tests (push) Waiting to run
HIRS System Tests / DockerTests (push) Waiting to run
Some checks are pending
Dotnet Provisioner Unit Tests / Restore and Run Unit Tests (ubuntu-20.04) (push) Waiting to run
Dotnet Provisioner Unit Tests / Restore and Run Unit Tests (windows-2022) (push) Waiting to run
Dotnet Provisioner Unit Tests / Evaluate Tests (push) Blocked by required conditions
HIRS Build and Unit Test / ACA_Provisioner_Unit_Tests (push) Waiting to run
HIRS System Tests / DockerTests (push) Waiting to run
This commit is contained in:
parent
3cbaa26d29
commit
a5a0fc7391
@ -70,8 +70,4 @@ sourceSets {
|
||||
srcDir '../HIRS_Provisioner.NET/hirs/Resources'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
}
|
@ -19,11 +19,11 @@ import java.io.Serializable;
|
||||
public class FirmwareInfo implements Serializable {
|
||||
|
||||
@XmlElement
|
||||
@Column(length = DeviceInfoEnums.LONG_STRING_LENGTH, nullable = false)
|
||||
@Column(nullable = false)
|
||||
private final String biosVendor;
|
||||
|
||||
@XmlElement
|
||||
@Column(length = DeviceInfoEnums.LONG_STRING_LENGTH, nullable = false)
|
||||
@Column(nullable = false)
|
||||
private final String biosVersion;
|
||||
|
||||
@XmlElement
|
||||
|
@ -21,11 +21,11 @@ import java.io.Serializable;
|
||||
public class OSInfo implements Serializable {
|
||||
|
||||
@XmlElement
|
||||
@Column(length = DeviceInfoEnums.LONG_STRING_LENGTH, nullable = false)
|
||||
@Column(nullable = false)
|
||||
private final String osName;
|
||||
|
||||
@XmlElement
|
||||
@Column(length = DeviceInfoEnums.LONG_STRING_LENGTH, nullable = false)
|
||||
@Column(nullable = false)
|
||||
private final String osVersion;
|
||||
|
||||
@XmlElement
|
||||
@ -33,11 +33,11 @@ public class OSInfo implements Serializable {
|
||||
private final String osArch;
|
||||
|
||||
@XmlElement
|
||||
@Column(length = DeviceInfoEnums.SHORT_STRING_LENGTH, nullable = true)
|
||||
@Column(length = DeviceInfoEnums.SHORT_STRING_LENGTH)
|
||||
private final String distribution;
|
||||
|
||||
@XmlElement
|
||||
@Column(length = DeviceInfoEnums.SHORT_STRING_LENGTH, nullable = true)
|
||||
@Column(length = DeviceInfoEnums.SHORT_STRING_LENGTH)
|
||||
private final String distributionRelease;
|
||||
|
||||
/**
|
||||
|
@ -30,23 +30,23 @@ public class TPMInfo implements Serializable {
|
||||
private static final int MAX_BLOB_SIZE = 65535;
|
||||
|
||||
@XmlElement
|
||||
@Column(length = DeviceInfoEnums.MED_STRING_LENGTH, nullable = true)
|
||||
@Column(length = DeviceInfoEnums.MED_STRING_LENGTH)
|
||||
private String tpmMake;
|
||||
|
||||
@XmlElement
|
||||
@Column(nullable = true)
|
||||
@Column
|
||||
private short tpmVersionMajor;
|
||||
|
||||
@XmlElement
|
||||
@Column(nullable = true)
|
||||
@Column
|
||||
private short tpmVersionMinor;
|
||||
|
||||
@XmlElement
|
||||
@Column(nullable = true)
|
||||
@Column
|
||||
private short tpmVersionRevMajor;
|
||||
|
||||
@XmlElement
|
||||
@Column(nullable = true)
|
||||
@Column
|
||||
private short tpmVersionRevMinor;
|
||||
|
||||
/**
|
||||
@ -60,13 +60,13 @@ public class TPMInfo implements Serializable {
|
||||
@JsonIgnore
|
||||
private X509Certificate identityCertificate;
|
||||
|
||||
@Column(nullable = true, columnDefinition = "blob")
|
||||
@Column(columnDefinition = "blob")
|
||||
private byte[] pcrValues;
|
||||
|
||||
@Column(nullable = true, columnDefinition = "blob")
|
||||
@Column(columnDefinition = "blob")
|
||||
private byte[] tpmQuoteHash;
|
||||
|
||||
@Column(nullable = true, columnDefinition = "blob")
|
||||
@Column(columnDefinition = "blob")
|
||||
private byte[] tpmQuoteSignature;
|
||||
|
||||
/**
|
||||
|
@ -35,9 +35,12 @@ import org.bouncycastle.operator.ContentSigner;
|
||||
import org.bouncycastle.operator.OperatorCreationException;
|
||||
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@ -203,17 +206,21 @@ public class SupplyChainCredentialValidatorTest {
|
||||
private static final String NEW_NUC1 =
|
||||
"/validation/platform_credentials/Intel_pc3.cer";
|
||||
|
||||
private static HardwareInfo hardwareInfo;
|
||||
|
||||
private static KeyStore keyStore;
|
||||
|
||||
private static KeyStore emptyKeyStore;
|
||||
|
||||
@Mock
|
||||
private ComponentResultRepository componentResultRepository;
|
||||
|
||||
@Mock
|
||||
private ComponentAttributeRepository componentAttributeRepository;
|
||||
|
||||
/**
|
||||
* Holds the AutoCloseable instance returned by openMocks.
|
||||
*/
|
||||
private AutoCloseable mocks;
|
||||
|
||||
/**
|
||||
* Sets up a KeyStore for testing.
|
||||
*
|
||||
@ -358,6 +365,26 @@ public class SupplyChainCredentialValidatorTest {
|
||||
return cert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup mocks.
|
||||
*/
|
||||
@BeforeEach
|
||||
public void setUpBeforeEach() {
|
||||
mocks = MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the mock instances.
|
||||
*
|
||||
* @throws Exception if there are any issues closing down mock instances
|
||||
*/
|
||||
@AfterEach
|
||||
public void tearDownAfterEach() throws Exception {
|
||||
if (mocks != null) {
|
||||
mocks.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new RSA 1024-bit KeyPair using a Bouncy Castle Provider.
|
||||
*
|
||||
@ -382,8 +409,23 @@ public class SupplyChainCredentialValidatorTest {
|
||||
*
|
||||
* @return device info report
|
||||
*/
|
||||
private DeviceInfoReport setupDeviceInfoReport() {
|
||||
hardwareInfo = new HardwareInfo(
|
||||
private DeviceInfoReport setupDeviceInfoReport() throws UnknownHostException {
|
||||
|
||||
// setup network info
|
||||
final byte[] byteAddress = new byte[] {127, 0, 0, 1};
|
||||
InetAddress inetAddress = InetAddress.getByAddress(byteAddress);
|
||||
NetworkInfo networkInfo = new NetworkInfo("the-device", inetAddress, new byte[] {1, 0, 1, 0, 1, 0});
|
||||
|
||||
// setup os info
|
||||
OSInfo osInfo = new OSInfo("Windows", "11.0", "Not Specified",
|
||||
"Not Specified", "Not Specified");
|
||||
|
||||
// setup firmware info
|
||||
FirmwareInfo firmwareInfo = new FirmwareInfo("Dell Inc", "A11",
|
||||
"03/12/2013");
|
||||
|
||||
// setup hardware info
|
||||
HardwareInfo hardwareInfo = new HardwareInfo(
|
||||
"ACME",
|
||||
"anvil",
|
||||
"3.0",
|
||||
@ -391,9 +433,9 @@ public class SupplyChainCredentialValidatorTest {
|
||||
"567",
|
||||
"890");
|
||||
|
||||
DeviceInfoReport deviceInfoReport = mock(DeviceInfoReport.class);
|
||||
when(deviceInfoReport.getHardwareInfo()).thenReturn(hardwareInfo);
|
||||
return deviceInfoReport;
|
||||
TPMInfo tpmInfo = new TPMInfo();
|
||||
|
||||
return new DeviceInfoReport(networkInfo, osInfo, firmwareInfo, hardwareInfo, tpmInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -429,7 +471,7 @@ public class SupplyChainCredentialValidatorTest {
|
||||
DeviceInfoReport deviceInfoReport = setupDeviceInfoReport();
|
||||
URL url = SupplyChainCredentialValidator.class.getResource(paccorOutputResource);
|
||||
String paccorOutputString = IOUtils.toString(url, StandardCharsets.UTF_8);
|
||||
when(deviceInfoReport.getPaccorOutputString()).thenReturn(paccorOutputString);
|
||||
deviceInfoReport.setPaccorOutputString(paccorOutputString);
|
||||
return deviceInfoReport;
|
||||
}
|
||||
|
||||
@ -453,7 +495,6 @@ public class SupplyChainCredentialValidatorTest {
|
||||
"00060001", "2.23.133.18.3.5"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method that returns an IP Address.
|
||||
*
|
||||
@ -1407,25 +1448,41 @@ public class SupplyChainCredentialValidatorTest {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that mocks out the Platform Credential object used for this class' test methods.
|
||||
*
|
||||
* @param deviceInfoReport device info report
|
||||
* @return mocked out Platform Credential
|
||||
* @throws IOException is thrown if there are any issues using the provided device info report's
|
||||
* information
|
||||
*/
|
||||
private PlatformCredential setupMatchingPlatformCredential(
|
||||
final DeviceInfoReport deviceInfoReport) throws IOException {
|
||||
PlatformCredential platformCredential = mock(PlatformCredential.class);
|
||||
|
||||
when(platformCredential.getCredentialType()).thenReturn(
|
||||
PlatformCredential.CERTIFICATE_TYPE_2_0);
|
||||
|
||||
when(platformCredential.getManufacturer())
|
||||
.thenReturn(hardwareInfo.getManufacturer());
|
||||
.thenReturn(deviceInfoReport.getHardwareInfo().getManufacturer());
|
||||
|
||||
when(platformCredential.getModel())
|
||||
.thenReturn(hardwareInfo.getProductName());
|
||||
.thenReturn(deviceInfoReport.getHardwareInfo().getProductName());
|
||||
|
||||
when(platformCredential.getPlatformSerial())
|
||||
.thenReturn(hardwareInfo.getBaseboardSerialNumber());
|
||||
.thenReturn(deviceInfoReport.getHardwareInfo().getBaseboardSerialNumber());
|
||||
|
||||
when(platformCredential.getVersion())
|
||||
.thenReturn(hardwareInfo.getVersion());
|
||||
.thenReturn(deviceInfoReport.getHardwareInfo().getVersion());
|
||||
|
||||
when(platformCredential.getSerialNumber()).thenReturn(
|
||||
new BigInteger(deviceInfoReport.getHardwareInfo().getSystemSerialNumber()));
|
||||
|
||||
List<ComponentInfo> deviceInfoComponents
|
||||
= SupplyChainCredentialValidator.getComponentInfoFromPaccorOutput(
|
||||
deviceInfoReport.getNetworkInfo().getHostname(),
|
||||
deviceInfoReport.getPaccorOutputString());
|
||||
|
||||
List<ComponentIdentifier> componentIdentifierList = new ArrayList<>();
|
||||
for (ComponentInfo deviceInfoComponent : deviceInfoComponents) {
|
||||
DERUTF8String serial = null;
|
||||
@ -1459,16 +1516,19 @@ public class SupplyChainCredentialValidatorTest {
|
||||
*
|
||||
* @throws IOException if unable to set up DeviceInfoReport from resource file
|
||||
*/
|
||||
//@Test TODO esacost
|
||||
@Test
|
||||
public final void testValidatePlatformCredentialAttributesV2p0NoComponentsPass()
|
||||
throws IOException {
|
||||
DeviceInfoReport deviceInfoReport = setupDeviceInfoReport();
|
||||
|
||||
PlatformCredential platformCredential = setupMatchingPlatformCredential(deviceInfoReport);
|
||||
|
||||
List<ComponentInfo> componentInfoList = retrieveListOfComponentInfos();
|
||||
|
||||
AppraisalStatus appraisalStatus = CertificateAttributeScvValidator
|
||||
.validatePlatformCredentialAttributesV2p0(platformCredential, deviceInfoReport,
|
||||
componentResultRepository, componentAttributeRepository,
|
||||
Collections.emptyList(), UUID.randomUUID(), false);
|
||||
componentInfoList, UUID.randomUUID(), false);
|
||||
assertEquals(AppraisalStatus.Status.PASS,
|
||||
appraisalStatus.getAppStatus());
|
||||
assertEquals(SupplyChainCredentialValidator.PLATFORM_ATTRIBUTES_VALID,
|
||||
@ -1481,16 +1541,19 @@ public class SupplyChainCredentialValidatorTest {
|
||||
*
|
||||
* @throws IOException if unable to set up DeviceInfoReport from resource file
|
||||
*/
|
||||
// @Test
|
||||
@Test
|
||||
public final void testValidatePlatformCredentialAttributesV2p0WithComponentsPass()
|
||||
throws IOException {
|
||||
DeviceInfoReport deviceInfoReport = setupDeviceInfoReportWithComponents();
|
||||
|
||||
PlatformCredential platformCredential = setupMatchingPlatformCredential(deviceInfoReport);
|
||||
|
||||
List<ComponentInfo> componentInfoList = retrieveListOfComponentInfos();
|
||||
|
||||
AppraisalStatus appraisalStatus = CertificateAttributeScvValidator
|
||||
.validatePlatformCredentialAttributesV2p0(platformCredential, deviceInfoReport,
|
||||
componentResultRepository, componentAttributeRepository,
|
||||
Collections.emptyList(), UUID.randomUUID(), false);
|
||||
componentInfoList, UUID.randomUUID(), false);
|
||||
assertEquals(AppraisalStatus.Status.PASS, appraisalStatus.getAppStatus());
|
||||
assertEquals(SupplyChainCredentialValidator.PLATFORM_ATTRIBUTES_VALID,
|
||||
appraisalStatus.getMessage());
|
||||
@ -1503,44 +1566,51 @@ public class SupplyChainCredentialValidatorTest {
|
||||
*
|
||||
* @throws IOException if unable to set up DeviceInfoReport from resource file
|
||||
*/
|
||||
// @Test
|
||||
@Test
|
||||
public final void testValPCAttributesV2p0WithComponentsPassPlatformSerialWithSystemSerial()
|
||||
throws IOException {
|
||||
DeviceInfoReport deviceInfoReport = setupDeviceInfoReportWithComponents();
|
||||
|
||||
PlatformCredential platformCredential = setupMatchingPlatformCredential(deviceInfoReport);
|
||||
|
||||
List<ComponentInfo> componentInfoList = retrieveListOfComponentInfos();
|
||||
|
||||
when(platformCredential.getPlatformSerial())
|
||||
.thenReturn(hardwareInfo.getSystemSerialNumber());
|
||||
.thenReturn(deviceInfoReport.getHardwareInfo().getSystemSerialNumber());
|
||||
|
||||
AppraisalStatus appraisalStatus = CertificateAttributeScvValidator
|
||||
.validatePlatformCredentialAttributesV2p0(platformCredential, deviceInfoReport,
|
||||
componentResultRepository, componentAttributeRepository,
|
||||
Collections.emptyList(), UUID.randomUUID(), false);
|
||||
componentInfoList, UUID.randomUUID(), false);
|
||||
assertEquals(AppraisalStatus.Status.PASS, appraisalStatus.getAppStatus());
|
||||
assertEquals(SupplyChainCredentialValidator.PLATFORM_ATTRIBUTES_VALID,
|
||||
appraisalStatus.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that TPM 2.0 Platform Credentials validate correctly against the device info report
|
||||
* Second test that tests that TPM 2.0 Platform Credentials validate correctly against the device info report
|
||||
* when there are components present, and when the PlatformSerial field holds the system's
|
||||
* serial number instead of the baseboard serial number.
|
||||
*
|
||||
* @throws IOException if unable to set up DeviceInfoReport from resource file
|
||||
* @throws URISyntaxException failed to read certificate
|
||||
*/
|
||||
// @Test
|
||||
@Test
|
||||
public final void testValPCAttributesV2p0WithComponentsPassPlatformSerialWithSystemSerial2()
|
||||
throws IOException, URISyntaxException {
|
||||
DeviceInfoReport deviceInfoReport = setupDeviceInfoReportWithNotSpecifiedComponents();
|
||||
|
||||
PlatformCredential platformCredential = new PlatformCredential(
|
||||
Files.readAllBytes(Paths.get(
|
||||
Objects.requireNonNull(SupplyChainCredentialValidator.class.getResource(
|
||||
SAMPLE_TEST_PACCOR_CERT)).toURI())));
|
||||
|
||||
List<ComponentInfo> componentInfoList = retrieveListOfComponentInfos();
|
||||
|
||||
AppraisalStatus appraisalStatus = CertificateAttributeScvValidator
|
||||
.validatePlatformCredentialAttributesV2p0(platformCredential, deviceInfoReport,
|
||||
componentResultRepository, componentAttributeRepository,
|
||||
Collections.emptyList(), UUID.randomUUID(), false);
|
||||
componentInfoList, UUID.randomUUID(), false);
|
||||
assertEquals(AppraisalStatus.Status.FAIL, appraisalStatus.getAppStatus());
|
||||
}
|
||||
|
||||
@ -1549,19 +1619,23 @@ public class SupplyChainCredentialValidatorTest {
|
||||
*
|
||||
* @throws IOException if unable to set up DeviceInfoReport from resource file
|
||||
*/
|
||||
// @Test
|
||||
//@Test todo ea
|
||||
public final void testValidatePlatformCredentialAttributesV2p0RequiredFieldsNull()
|
||||
throws IOException {
|
||||
DeviceInfoReport deviceInfoReport = setupDeviceInfoReportWithComponents();
|
||||
|
||||
PlatformCredential platformCredential = setupMatchingPlatformCredential(deviceInfoReport);
|
||||
|
||||
AppraisalStatus result = CertificateAttributeScvValidator
|
||||
.validatePlatformCredentialAttributesV2p0(platformCredential,
|
||||
deviceInfoReport, componentResultRepository, componentAttributeRepository,
|
||||
Collections.emptyList(), UUID.randomUUID(), false);
|
||||
|
||||
assertEquals(AppraisalStatus.Status.PASS, result.getAppStatus());
|
||||
|
||||
assertEquals(SupplyChainCredentialValidator.PLATFORM_ATTRIBUTES_VALID,
|
||||
result.getMessage());
|
||||
|
||||
when(platformCredential.getManufacturer()).thenReturn(null);
|
||||
result = CertificateAttributeScvValidator
|
||||
.validatePlatformCredentialAttributesV2p0(platformCredential,
|
||||
@ -1824,7 +1898,7 @@ public class SupplyChainCredentialValidatorTest {
|
||||
*
|
||||
* @throws IOException if unable to set up DeviceInfoReport from resource file
|
||||
*/
|
||||
// @Test
|
||||
@Test
|
||||
public final void testValidatePlatformCredentialAttributesV2p0ExtraComponentInDeviceInfo()
|
||||
throws IOException {
|
||||
PlatformCredential platformCredential = setupMatchingPlatformCredential(
|
||||
@ -1914,7 +1988,7 @@ public class SupplyChainCredentialValidatorTest {
|
||||
*
|
||||
* @throws IOException if unable to set up DeviceInfoReport from resource file
|
||||
*/
|
||||
// @Test
|
||||
@Test
|
||||
public final void testValidatePlatformCredentialAttributesV2p0RequiredComponentNoSerial()
|
||||
throws IOException {
|
||||
DeviceInfoReport deviceInfoReport = setupDeviceInfoReportWithComponents();
|
||||
@ -1946,10 +2020,11 @@ public class SupplyChainCredentialValidatorTest {
|
||||
*
|
||||
* @throws IOException if unable to set up DeviceInfoReport from resource file
|
||||
*/
|
||||
// @Test
|
||||
@Test
|
||||
public final void testValidatePlatformCredentialAttributesV2p0RequiredComponentNoRevision()
|
||||
throws IOException {
|
||||
DeviceInfoReport deviceInfoReport = setupDeviceInfoReportWithComponents();
|
||||
|
||||
PlatformCredential platformCredential = setupMatchingPlatformCredential(deviceInfoReport);
|
||||
|
||||
ArrayList<ComponentIdentifier> modifiedIdentifiers = new ArrayList<>();
|
||||
@ -1979,10 +2054,11 @@ public class SupplyChainCredentialValidatorTest {
|
||||
*
|
||||
* @throws IOException if unable to set up DeviceInfoReport from resource file
|
||||
*/
|
||||
// @Test
|
||||
@Test
|
||||
public final void testValPlatCredentialAttributesV2p0RequiredComponentNoSerialOrRevision()
|
||||
throws IOException {
|
||||
DeviceInfoReport deviceInfoReport = setupDeviceInfoReportWithComponents();
|
||||
|
||||
PlatformCredential platformCredential = setupMatchingPlatformCredential(deviceInfoReport);
|
||||
|
||||
ArrayList<ComponentIdentifier> modifiedIdentifiers = new ArrayList<>();
|
||||
|
@ -81,10 +81,6 @@ dependencies {
|
||||
testImplementation libs.xmlunit.core
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
task buildVersion() {
|
||||
doLast {
|
||||
def verFile = new File(projectDir, "build/VERSION")
|
||||
|
@ -13,10 +13,6 @@ dependencies {
|
||||
testAnnotationProcessor libs.lombok
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
//publishing {
|
||||
// publications {
|
||||
// maven(MavenPublication) {
|
||||
|
@ -42,10 +42,6 @@ dependencies {
|
||||
testAnnotationProcessor libs.lombok
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
jar {
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
manifest {
|
||||
|
17
build.gradle
17
build.gradle
@ -9,6 +9,7 @@ plugins {
|
||||
id 'com.github.spotbugs' version '6.0.13' apply false
|
||||
id 'org.owasp.dependencycheck' version '11.1.1'
|
||||
id 'java'
|
||||
id 'jacoco'
|
||||
}
|
||||
|
||||
// Global checkstyle file
|
||||
@ -19,6 +20,7 @@ subprojects {
|
||||
apply plugin: "java"
|
||||
apply plugin: "checkstyle"
|
||||
apply plugin: "org.owasp.dependencycheck"
|
||||
apply plugin: "jacoco"
|
||||
|
||||
repositories {
|
||||
flatDir { dirs "lib" }
|
||||
@ -31,6 +33,20 @@ subprojects {
|
||||
}
|
||||
}
|
||||
|
||||
jacoco {
|
||||
toolVersion = '0.8.12'
|
||||
}
|
||||
|
||||
if (project.name != 'tcg_rim_tool') // run tests on every subproject except for rim_tools
|
||||
test {
|
||||
useJUnitPlatform() // Use JUnit platform
|
||||
finalizedBy jacocoTestReport // Generate the JaCoCo report after running tests
|
||||
}
|
||||
|
||||
jacocoTestReport {
|
||||
dependsOn test // tests are required to run before generating the report
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
toolVersion = '10.20.0'
|
||||
configFile file("${rootDir}/config/checkstyle/checkstyle.xml")
|
||||
@ -61,7 +77,6 @@ subprojects {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
|
@ -1,45 +1,56 @@
|
||||
package hirs.swid;
|
||||
|
||||
import hirs.utils.rim.ReferenceManifestValidator;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.context.event.annotation.AfterTestClass;
|
||||
import org.springframework.test.context.event.annotation.BeforeTestClass;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
//TODO tests are broken
|
||||
public class TestSwidTagGateway {
|
||||
private static final String ATTRIBUTES_FILE = Objects.requireNonNull(
|
||||
TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("rim_fields.json")).getPath();
|
||||
|
||||
private static final String CA_CHAIN_FILE = Objects.requireNonNull(
|
||||
TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("RimCertChain.pem")).getPath();
|
||||
|
||||
private static final String SUPPORT_RIM_FILE = Objects.requireNonNull(
|
||||
TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("TpmLog.bin")).getPath();
|
||||
|
||||
private static SwidTagGateway gateway;
|
||||
|
||||
private static ReferenceManifestValidator validator;
|
||||
|
||||
private final String DEFAULT_OUTPUT = "generated_swidTag.swidtag";
|
||||
|
||||
private final String BASE_USER_CERT = "generated_user_cert.swidtag";
|
||||
private final String BASE_USER_CERT_EMBED = "generated_user_cert_embed.swidtag";
|
||||
private final String BASE_DEFAULT_CERT = "generated_default_cert.swidtag";
|
||||
private final String BASE_RFC3339_TIMESTAMP = "generated_timestamp_rfc3339.swidtag";
|
||||
private final String BASE_RFC3852_TIMESTAMP = "generated_timestamp_rfc3852.swidtag";
|
||||
private final String ATTRIBUTES_FILE = TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("rim_fields.json").getPath();
|
||||
private final String JKS_KEYSTORE_FILE = TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("keystore.jks").getPath();
|
||||
private final String SIGNING_CERT_FILE = TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("RimSignCert.pem").getPath();
|
||||
private final String PRIVATE_KEY_FILE = TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("privateRimKey.pem").getPath();
|
||||
private final String CA_CHAIN_FILE = TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("RimCertChain.pem").getPath();
|
||||
private final String SUPPORT_RIM_FILE = TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("TpmLog.bin").getPath();
|
||||
private final String RFC3852_COUNTERSIGNATURE_FILE = TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("counterSignature.file").getPath();
|
||||
private SwidTagGateway gateway;
|
||||
private ReferenceManifestValidator validator;
|
||||
|
||||
private final String JKS_KEYSTORE_FILE = Objects.requireNonNull(TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("keystore.jks")).getPath();
|
||||
|
||||
private final String SIGNING_CERT_FILE = Objects.requireNonNull(TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("RimSignCert.pem")).getPath();
|
||||
|
||||
private final String PRIVATE_KEY_FILE = Objects.requireNonNull(TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("privateRimKey.pem")).getPath();
|
||||
|
||||
private final String RFC3852_COUNTERSIGNATURE_FILE = Objects.requireNonNull(
|
||||
TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource("counterSignature.file")).getPath();
|
||||
|
||||
private InputStream expectedFile;
|
||||
|
||||
@BeforeTestClass
|
||||
public void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
gateway = new SwidTagGateway();
|
||||
gateway.setRimEventLog(SUPPORT_RIM_FILE);
|
||||
gateway.setAttributesFile(ATTRIBUTES_FILE);
|
||||
@ -48,7 +59,7 @@ public class TestSwidTagGateway {
|
||||
validator.setTrustStoreFile(CA_CHAIN_FILE);
|
||||
}
|
||||
|
||||
@AfterTestClass
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
if (expectedFile != null) {
|
||||
expectedFile.close();
|
||||
@ -87,6 +98,7 @@ public class TestSwidTagGateway {
|
||||
gateway.setPemPrivateKeyFile(PRIVATE_KEY_FILE);
|
||||
gateway.setEmbeddedCert(true);
|
||||
gateway.generateSwidTag(DEFAULT_OUTPUT);
|
||||
final String BASE_USER_CERT_EMBED = "generated_user_cert_embed.swidtag";
|
||||
expectedFile = TestSwidTagGateway.class.getClassLoader()
|
||||
.getResourceAsStream(BASE_USER_CERT_EMBED);
|
||||
assertTrue(compareFileBytesToExpectedFile(DEFAULT_OUTPUT));
|
||||
@ -103,6 +115,7 @@ public class TestSwidTagGateway {
|
||||
gateway.setDefaultCredentials(true);
|
||||
gateway.setJksTruststoreFile(JKS_KEYSTORE_FILE);
|
||||
gateway.generateSwidTag(DEFAULT_OUTPUT);
|
||||
final String BASE_DEFAULT_CERT = "generated_default_cert.swidtag";
|
||||
expectedFile = TestSwidTagGateway.class.getClassLoader()
|
||||
.getResourceAsStream(BASE_DEFAULT_CERT);
|
||||
assertTrue(compareFileBytesToExpectedFile(DEFAULT_OUTPUT));
|
||||
@ -121,6 +134,7 @@ public class TestSwidTagGateway {
|
||||
gateway.setTimestampFormat("RFC3339");
|
||||
gateway.setTimestampArgument("2023-01-01T00:00:00Z");
|
||||
gateway.generateSwidTag(DEFAULT_OUTPUT);
|
||||
final String BASE_RFC3339_TIMESTAMP = "generated_timestamp_rfc3339.swidtag";
|
||||
expectedFile = TestSwidTagGateway.class.getClassLoader()
|
||||
.getResourceAsStream(BASE_RFC3339_TIMESTAMP);
|
||||
assertTrue(compareFileBytesToExpectedFile(DEFAULT_OUTPUT));
|
||||
@ -139,6 +153,7 @@ public class TestSwidTagGateway {
|
||||
gateway.setTimestampFormat("RFC3852");
|
||||
gateway.setTimestampArgument(RFC3852_COUNTERSIGNATURE_FILE);
|
||||
gateway.generateSwidTag(DEFAULT_OUTPUT);
|
||||
final String BASE_RFC3852_TIMESTAMP = "generated_timestamp_rfc3852.swidtag";
|
||||
expectedFile = TestSwidTagGateway.class.getClassLoader()
|
||||
.getResourceAsStream(BASE_RFC3852_TIMESTAMP);
|
||||
assertTrue(compareFileBytesToExpectedFile(DEFAULT_OUTPUT));
|
||||
@ -150,10 +165,10 @@ public class TestSwidTagGateway {
|
||||
* This test corresponds to the arguments:
|
||||
* -v <path>
|
||||
*/
|
||||
|
||||
public void testvalidateSwidtagFile() {
|
||||
String filepath = TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource(BASE_USER_CERT).getPath();
|
||||
@Test
|
||||
public void testValidateSwidtagFile() {
|
||||
final String filepath = Objects.requireNonNull(TestSwidTagGateway.class.getClassLoader()
|
||||
.getResource(BASE_USER_CERT)).getPath();
|
||||
System.out.println("Validating file at " + filepath);
|
||||
validator.setRim(DEFAULT_OUTPUT);
|
||||
assertTrue(validator.validateRim(SIGNING_CERT_FILE));
|
||||
@ -178,13 +193,7 @@ public class TestSwidTagGateway {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (NullPointerException e) {
|
||||
} catch (IOException | NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
|
Loading…
x
Reference in New Issue
Block a user