mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
Port ExtractCertCmdTest
This commit is contained in:
parent
5f3e1b4da3
commit
1e67447efd
1 changed files with 9 additions and 8 deletions
|
@ -12,8 +12,8 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.key.info.KeyRingInfo;
|
import org.pgpainless.key.info.KeyRingInfo;
|
||||||
|
@ -22,6 +22,8 @@ import sop.exception.SOPGPException;
|
||||||
|
|
||||||
public class ExtractCertCmdTest extends CLITest {
|
public class ExtractCertCmdTest extends CLITest {
|
||||||
|
|
||||||
|
private final PGPainless api = PGPainless.getInstance();
|
||||||
|
|
||||||
public ExtractCertCmdTest() {
|
public ExtractCertCmdTest() {
|
||||||
super(LoggerFactory.getLogger(ExtractCertCmdTest.class));
|
super(LoggerFactory.getLogger(ExtractCertCmdTest.class));
|
||||||
}
|
}
|
||||||
|
@ -29,18 +31,17 @@ public class ExtractCertCmdTest extends CLITest {
|
||||||
@Test
|
@Test
|
||||||
public void testExtractCert()
|
public void testExtractCert()
|
||||||
throws IOException {
|
throws IOException {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
OpenPGPKey key = api.generateKey()
|
||||||
.simpleEcKeyRing("Juliet Capulet <juliet@capulet.lit>")
|
.simpleEcKeyRing("Juliet Capulet <juliet@capulet.lit>");
|
||||||
.getPGPSecretKeyRing();
|
|
||||||
|
|
||||||
pipeBytesToStdin(secretKeys.getEncoded());
|
pipeBytesToStdin(key.getEncoded());
|
||||||
ByteArrayOutputStream out = pipeStdoutToStream();
|
ByteArrayOutputStream out = pipeStdoutToStream();
|
||||||
assertSuccess(executeCommand("extract-cert", "--armor"));
|
assertSuccess(executeCommand("extract-cert", "--armor"));
|
||||||
|
|
||||||
assertTrue(out.toString().startsWith("-----BEGIN PGP PUBLIC KEY BLOCK-----\n"));
|
assertTrue(out.toString().startsWith("-----BEGIN PGP PUBLIC KEY BLOCK-----\n"));
|
||||||
|
|
||||||
PGPPublicKeyRing publicKeys = PGPainless.readKeyRing().publicKeyRing(out.toByteArray());
|
OpenPGPCertificate certificate = api.readKey().parseCertificate(out.toByteArray());
|
||||||
KeyRingInfo info = PGPainless.inspectKeyRing(publicKeys);
|
KeyRingInfo info = api.inspect(certificate);
|
||||||
assertFalse(info.isSecretKey());
|
assertFalse(info.isSecretKey());
|
||||||
assertTrue(info.isUserIdValid("Juliet Capulet <juliet@capulet.lit>"));
|
assertTrue(info.isUserIdValid("Juliet Capulet <juliet@capulet.lit>"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue