Migrate CertificateTest class to HIRS_Utils and update unit test dependencies following migration

This commit is contained in:
chubtub 2023-10-18 09:46:42 -04:00
parent f96fa87138
commit 55f80fe0e6
13 changed files with 156 additions and 67 deletions
HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/entity/userdefined
HIRS_Utils/src/test

@ -3,11 +3,16 @@ package hirs.attestationca.persist.entity.userdefined;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import hirs.attestationca.persist.entity.ArchivableEntity;
import hirs.utils.ArchivableEntity;
import hirs.utils.CertificateAuthorityCredential;
import hirs.attestationca.persist.enums.AppraisalStatus;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
/**
@ -17,6 +22,40 @@ import java.util.List;
class SupplyChainValidationTest {
private static final String MESSAGE = "Some message.";
/**
* Location of a test (fake) root CA certificate.
*/
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) SGI intermediate CA certificate.
*/
public static final String FAKE_SGI_INT_CA_FILE = "/certificates/fakeSGIIntermediateCA.cer";
private static final List<ArchivableEntity> allTestCertificates =
new ArrayList<ArchivableEntity>(3);
@BeforeAll
private static void setAllTestCertificates() throws URISyntaxException, IOException {
allTestCertificates.add(
new CertificateAuthorityCredential(
Paths.get(SupplyChainValidationTest.class.getResource(
FAKE_SGI_INT_CA_FILE).toURI())));
allTestCertificates.add(
new CertificateAuthorityCredential(
Paths.get(SupplyChainValidationTest.class.getResource(
FAKE_INTEL_INT_CA_FILE).toURI())));
allTestCertificates.add(
new CertificateAuthorityCredential(
Paths.get(SupplyChainValidationTest.class.getResource(
FAKE_ROOT_CA_FILE).toURI())));
}
/**
* Test that this class' getter methods work properly.
*
@ -31,7 +70,7 @@ class SupplyChainValidationTest {
);
assertEquals(
validation.getCertificatesUsed(),
CertificateTest.getAllTestCertificates()
allTestCertificates
);
assertEquals(validation.getMessage(), MESSAGE);
}
@ -47,7 +86,7 @@ class SupplyChainValidationTest {
new SupplyChainValidation(
null,
AppraisalStatus.Status.PASS,
CertificateTest.getAllTestCertificates(),
allTestCertificates,
MESSAGE
));
}
@ -78,7 +117,7 @@ class SupplyChainValidationTest {
new SupplyChainValidation(
SupplyChainValidation.ValidationType.ENDORSEMENT_CREDENTIAL,
AppraisalStatus.Status.PASS,
CertificateTest.getAllTestCertificates(),
allTestCertificates,
MESSAGE
);
}
@ -95,7 +134,7 @@ class SupplyChainValidationTest {
return getTestSupplyChainValidation(
SupplyChainValidation.ValidationType.ENDORSEMENT_CREDENTIAL,
AppraisalStatus.Status.PASS,
CertificateTest.getAllTestCertificates()
allTestCertificates
);
}

@ -1,6 +1,7 @@
package hirs.attestationca.persist.entity.userdefined.certificate;
import hirs.attestationca.persist.entity.userdefined.Certificate;
import hirs.utils.Certificate;
import hirs.utils.CertificateAuthorityCredential;
import hirs.attestationca.persist.entity.userdefined.certificate.attributes.ComponentIdentifier;
import hirs.attestationca.persist.entity.userdefined.certificate.attributes.PlatformConfiguration;
import hirs.attestationca.persist.entity.userdefined.certificate.attributes.PlatformProperty;

@ -1,6 +1,4 @@
package hirs.attestationca.persist.entity.userdefined;
import hirs.attestationca.persist.entity.ArchivableEntity;
package hirs.utils;
import java.io.FileInputStream;
import java.io.IOException;
@ -29,6 +27,30 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
* This class tests functionality of the {@link Certificate} class.
*/
public class CertificateTest {
/**
* Location of another, slightly different platform attribute cert.
*/
public static final String TEST_PLATFORM_CERT_3 =
"/validation/platform_credentials/Intel_pc3.cer";
/**
* Platform cert with comma separated baseboard and chassis serial number.
*/
public static final String TEST_PLATFORM_CERT_4 =
"/validation/platform_credentials/Intel_pc4.pem";
/**
* Another platform cert with comma separated baseboard and chassis serial number.
*/
public static final String TEST_PLATFORM_CERT_5 =
"/validation/platform_credentials/Intel_pc5.pem";
/**
* Location of another, slightly different platform attribute cert.
*/
public static final String TEST_PLATFORM_CERT_6 =
"/validation/platform_credentials/TPM_INTC_Platform_Cert_RSA.txt";
/**
* Location of a test (fake) root CA certificate.
*/
@ -51,59 +73,8 @@ public class CertificateTest {
*/
public static final String FAKE_SGI_INT_CA_FILE = "/certificates/fakeSGIIntermediateCA.cer";
/**
* Location of another test self-signed certificate.
*/
public static final String ANOTHER_SELF_SIGNED_FILE =
"/certificates/fakeSelfSigned.cer";
/**
* Location of the NUC EC.
*/
public static final String STM_NUC1_EC = "/certificates/nuc-1/tpmcert.pem";
/**
* Location of the ST Micro Intermediate 02 CA certificate.
*/
public static final String STM_INT_02_CA = "/certificates/stMicroCaCerts/stmtpmekint02.crt";
/**
* Location of the ST Micro Root CA certificate.
*/
public static final String STM_ROOT_CA = "/certificates/stMicroCaCerts/stmtpmekroot.crt";
/**
* 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.
*/
public static final String FAKE_ROOT_CA_SUBJECT_KEY_IDENTIFIER_HEX =
"58ec313a1699f94c1c8c4e2c6412402b258f0177";
/**
* Location of a test STM endorsement credential.
*/
public static final String TEST_EC = "/certificates/ab21ccf2-tpmcert.pem";
/**
* Location of a test client cert.
*/
public static final String ISSUED_CLIENT_CERT =
"/tpm/sample_identity_cert.cer";
private static final String INT_CA_CERT02 = "/certificates/fakestmtpmekint02.pem";
private static final String RDN_COMMA_SEPARATED =
"CN=STM TPM EK Intermediate CA 02, O=STMicroelectronics NV, C=CH";
private static final String RDN_MULTIVALUE =
"CN=Nuvoton TPM Root CA 2010+O=Nuvoton Technology Corporation+C=TW";
private static final String RDN_COMMA_SEPARATED_ORGANIZATION = "STMicroelectronics NV";
private static final String RDN_MULTIVALUE_ORGANIZATION = "Nuvoton Technology Corporation";
private static final String EK_CERT_WITH_PADDED_BYTES =
"/certificates/ek_cert_with_padded_bytes.cer";
@ -197,11 +168,11 @@ public class CertificateTest {
assertNotEquals(getTestCertificate(
PlatformCredential.class,
PlatformCredentialTest.TEST_PLATFORM_CERT_3).getCertificateType(),
TEST_PLATFORM_CERT_3).getCertificateType(),
Certificate.CertificateType.X509_CERTIFICATE);
assertEquals(getTestCertificate(
PlatformCredential.class,
PlatformCredentialTest.TEST_PLATFORM_CERT_3).getCertificateType(),
TEST_PLATFORM_CERT_3).getCertificateType(),
Certificate.CertificateType.ATTRIBUTE_CERTIFICATE);
}
@ -215,7 +186,7 @@ public class CertificateTest {
@Test
public void testImportPem() throws IOException {
Certificate platformCredential = getTestCertificate(
PlatformCredential.class, PlatformCredentialTest.TEST_PLATFORM_CERT_4
PlatformCredential.class, TEST_PLATFORM_CERT_4
);
assertEquals(platformCredential.getCertificateType(),
@ -226,7 +197,7 @@ public class CertificateTest {
);
platformCredential = getTestCertificate(
PlatformCredential.class, PlatformCredentialTest.TEST_PLATFORM_CERT_5
PlatformCredential.class, TEST_PLATFORM_CERT_5
);
assertEquals(platformCredential.getCertificateType(),
@ -286,12 +257,12 @@ public class CertificateTest {
public void testX509AttributeCertificateParsing() throws IOException, URISyntaxException {
Certificate platformCert = getTestCertificate(
PlatformCredential.class,
PlatformCredentialTest.TEST_PLATFORM_CERT_3
TEST_PLATFORM_CERT_3
);
X509AttributeCertificateHolder attrCertHolder = new X509AttributeCertificateHolder(
Files.readAllBytes(Paths.get(this.getClass().getResource(
PlatformCredentialTest.TEST_PLATFORM_CERT_3
TEST_PLATFORM_CERT_3
).toURI()))
);
@ -321,7 +292,7 @@ public class CertificateTest {
public void testX509AttributeCertificateParsingExtended()
throws IOException, URISyntaxException {
Certificate platformCert = getTestCertificate(
PlatformCredential.class, PlatformCredentialTest.TEST_PLATFORM_CERT_6);
PlatformCredential.class, TEST_PLATFORM_CERT_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