Add tests for extracting certs from known keys

This commit is contained in:
Paul Schaub 2023-01-20 14:37:58 +01:00
parent ffc5b26c0d
commit 0d9db2bdd3
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static sop.external.JUtils.arrayStartsWith; import static sop.external.JUtils.arrayStartsWith;
import static sop.external.JUtils.assertArrayStartsWith; import static sop.external.JUtils.assertArrayStartsWith;
import static sop.external.JUtils.assertAsciiArmorEquals;
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled") @EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
public class ExternalExtractCertTest extends AbstractExternalSOPTest { public class ExternalExtractCertTest extends AbstractExternalSOPTest {
@ -32,6 +33,30 @@ public class ExternalExtractCertTest extends AbstractExternalSOPTest {
assertArrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES); 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 @Test
public void extractUnarmoredCertFromArmoredKeyTest() throws IOException { public void extractUnarmoredCertFromArmoredKeyTest() throws IOException {
InputStream keyIn = getSop().generateKey() InputStream keyIn = getSop().generateKey()