From 0d9db2bdd39bedf108d3b98f93e0fac5d45b7894 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 20 Jan 2023 14:37:58 +0100 Subject: [PATCH] Add tests for extracting certs from known keys --- .../sop/external/ExternalExtractCertTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java b/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java index 559316f..98111f2 100644 --- a/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java +++ b/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java @@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets; import static org.junit.jupiter.api.Assertions.assertFalse; import static sop.external.JUtils.arrayStartsWith; import static sop.external.JUtils.assertArrayStartsWith; +import static sop.external.JUtils.assertAsciiArmorEquals; @EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled") public class ExternalExtractCertTest extends AbstractExternalSOPTest { @@ -32,6 +33,30 @@ public class ExternalExtractCertTest extends AbstractExternalSOPTest { assertArrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES); } + @Test + public void extractAliceCertFromAliceKeyTest() throws IOException { + byte[] armoredCert = getSop().extractCert() + .key(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .getBytes(); + assertAsciiArmorEquals(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8), armoredCert); + } + + @Test + public void extractBobsCertFromBobsKeyTest() throws IOException { + byte[] armoredCert = getSop().extractCert() + .key(TestKeys.BOB_KEY.getBytes(StandardCharsets.UTF_8)) + .getBytes(); + assertAsciiArmorEquals(TestKeys.BOB_CERT.getBytes(StandardCharsets.UTF_8), armoredCert); + } + + @Test + public void extractCarolsCertFromCarolsKeyTest() throws IOException { + byte[] armoredCert = getSop().extractCert() + .key(TestKeys.CAROL_KEY.getBytes(StandardCharsets.UTF_8)) + .getBytes(); + assertAsciiArmorEquals(TestKeys.CAROL_CERT.getBytes(StandardCharsets.UTF_8), armoredCert); + } + @Test public void extractUnarmoredCertFromArmoredKeyTest() throws IOException { InputStream keyIn = getSop().generateKey()