From 33c20e8c70d360886d72cbea97c7e97a921ccc03 Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Tue, 4 Aug 2020 13:25:50 -0400 Subject: [PATCH] Fix classpath error causing broken unit tests --- tools/tcg_rim_tool/privateRimKey.pem | 28 ------------------- .../java/hirs/swid/TestSwidTagGateway.java | 22 +++++++++------ .../src/test/resources/RimSignCert.pem | 25 +++++++++-------- 3 files changed, 26 insertions(+), 49 deletions(-) delete mode 100644 tools/tcg_rim_tool/privateRimKey.pem diff --git a/tools/tcg_rim_tool/privateRimKey.pem b/tools/tcg_rim_tool/privateRimKey.pem deleted file mode 100644 index afe282c4..00000000 --- a/tools/tcg_rim_tool/privateRimKey.pem +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCndZVhpEkbsQAG -NsB2oNhlcVJNXWcdj06X0Dn5by3nHAFcGvJkIZbEREavkCvIpY/F36rOOP5wWnHG -Qzo3XyMSFAjH8IRl48QmqmW4E7nDbBMQ57uGq0xq2qAMMx4NHFS4ik/wsY/TS+HX -DIMUV7D3R3129Pdtwu8WHdrdqn1tObpoGo+6nkJenOvAhTbBl+CQPK1hUGb7xseQ -xpSuCk3Iz7kECDbOX8WrDSqi2Noavs/Nsf66sK9oZsosw+haRUsiAATxDD3wdN+h -hIUcLtVhDJKvMiKdo4EVKBWJHvaQd6YfaVaMNB4eJjRUig+KT+NVUimNZ7rPN5nZ -LrpD8uaNAgMBAAECggEAcnG8npd9U0x7HMQMcsZoPaPdwHvF/gCzkLNA+8RM1bZh -A4ZzA5WlCQs0V8Wq9pyXjn7Wp8txsG1PdlT5k2AUgsVoXuR0R4IKyvYHQG9StEjH -GvWURmwJdLlnSg8hSYqEJ/52taNUDO6+MI8fgiaQDd8w0ryF4OCpLy9GJdnfkGYZ -Ayemb3USFUdj/S67NVqxnvAfFMM5FqkKGhkoy7wBR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swid/TestSwidTagGateway.java b/tools/tcg_rim_tool/src/test/java/hirs/swid/TestSwidTagGateway.java index ce3ff320..b715356c 100644 --- a/tools/tcg_rim_tool/src/test/java/hirs/swid/TestSwidTagGateway.java +++ b/tools/tcg_rim_tool/src/test/java/hirs/swid/TestSwidTagGateway.java @@ -20,17 +20,17 @@ public class TestSwidTagGateway { private final String DEFAULT_OUTPUT = "generated_swidTag.swidtag"; private final String DEFAULT_WITH_CERT = "generated_with_cert.swidtag"; private final String DEFAULT_NO_CERT = "generated_no_cert.swidtag"; - private final String certificateFile = "RimSignCert.pem"; - private final String privateKeyFile = "privateRimKey.pem"; - private final String supportRimFile = "TpmLog.bin"; + 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 SUPPORT_RIM_FILE = TestSwidTagGateway.class.getClassLoader().getResource("TpmLog.bin").getPath(); private InputStream expectedFile; @BeforeClass public void setUp() throws Exception { gateway = new SwidTagGateway(); - gateway.setRimEventLog(supportRimFile); + gateway.setRimEventLog(SUPPORT_RIM_FILE); validator = new SwidTagValidator(); - validator.setRimEventLog(supportRimFile); + validator.setRimEventLog(SUPPORT_RIM_FILE); } @AfterClass @@ -48,8 +48,8 @@ public class TestSwidTagGateway { @Test public void testCreateBaseWithCert() throws URISyntaxException { gateway.setDefaultCredentials(false); - gateway.setPemCertificateFile(certificateFile); - gateway.setPemPrivateKeyFile(privateKeyFile); + gateway.setPemCertificateFile(SIGNING_CERT_FILE); + gateway.setPemPrivateKeyFile(PRIVATE_KEY_FILE); gateway.generateSwidTag(DEFAULT_OUTPUT); expectedFile = (InputStream) TestSwidTagGateway.class.getClassLoader().getResourceAsStream(DEFAULT_WITH_CERT); Assert.assertTrue(compareFileBytesToExpectedFile(DEFAULT_OUTPUT)); @@ -73,11 +73,15 @@ public class TestSwidTagGateway { */ @Test public void testValidateSwidTag() { + String filepath = TestSwidTagGateway.class.getClassLoader().getResource(DEFAULT_WITH_CERT).getPath(); + System.out.println("Validating file at " + filepath); try { - Assert.assertTrue(validator.validateSwidTag(TestSwidTagGateway.class.getClassLoader().getResource(DEFAULT_WITH_CERT).getPath())); + Assert.assertTrue(validator.validateSwidTag(filepath)); } catch (IOException e) { Assert.fail("Invalid swidtag!"); - } + } catch (NullPointerException e) { + Assert.fail("Cannot find file: " + filepath); + } } /** diff --git a/tools/tcg_rim_tool/src/test/resources/RimSignCert.pem b/tools/tcg_rim_tool/src/test/resources/RimSignCert.pem index 9d37a2fa..40aa4386 100644 --- a/tools/tcg_rim_tool/src/test/resources/RimSignCert.pem +++ b/tools/tcg_rim_tool/src/test/resources/RimSignCert.pem @@ -1,8 +1,8 @@ -----BEGIN CERTIFICATE----- -MIIDoTCCAomgAwIBAgIJAPB+r6VBhBn5MA0GCSqGSIb3DQEBCwUAMFMxCzAJBgNV +MIID2jCCAsKgAwIBAgIJAP0uwoNdwZDFMA0GCSqGSIb3DQEBCwUAMFMxCzAJBgNV BAYTAlVTMQswCQYDVQQIDAJWQTEQMA4GA1UECgwHRXhhbXBsZTERMA8GA1UECwwI -UENDbGllbnQxEjAQBgNVBAMMCUV4YW1wbGVDQTAeFw0yMDAzMTExODExMjJaFw0z -MDAxMTgxODExMjJaMFwxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJWQTEQMA4GA1UE +UENDbGllbnQxEjAQBgNVBAMMCUV4YW1wbGVDQTAeFw0yMDA3MjEyMTQ1MDBaFw0z +MDA1MzAyMTQ1MDBaMFwxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJWQTEQMA4GA1UE CgwHRXhhbXBsZTERMA8GA1UECwwIUENDbGllbnQxGzAZBgNVBAMMEmV4YW1wbGUu UklNLnNpZ25lcjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKd1lWGk SRuxAAY2wHag2GVxUk1dZx2PTpfQOflvLeccAVwa8mQh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