From d9ab91516d9f7d9cdf267c5360df151dcf1c9541 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Tue, 13 Jun 2023 15:43:48 +0200 Subject: [PATCH] Add encrypt-decrypt roundtrip test for rfc4880 profile to cli tests --- .../RoundTripEncryptDecryptCmdTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pgpainless-cli/src/test/java/org/pgpainless/cli/commands/RoundTripEncryptDecryptCmdTest.java b/pgpainless-cli/src/test/java/org/pgpainless/cli/commands/RoundTripEncryptDecryptCmdTest.java index 8c294e59..3caa81ae 100644 --- a/pgpainless-cli/src/test/java/org/pgpainless/cli/commands/RoundTripEncryptDecryptCmdTest.java +++ b/pgpainless-cli/src/test/java/org/pgpainless/cli/commands/RoundTripEncryptDecryptCmdTest.java @@ -644,4 +644,30 @@ public class RoundTripEncryptDecryptCmdTest extends CLITest { int exitCode = executeCommand("decrypt"); assertEquals(SOPGPException.MissingArg.EXIT_CODE, exitCode); } + + @Test + public void testEncryptDecryptWithFreshRSAKey() throws IOException { + // Generate key + File passwordFile = writeFile("password", "sw0rdf1sh"); + File keyFile = pipeStdoutToFile("key.asc"); + assertSuccess(executeCommand("generate-key", "--profile=rfc4880", "--with-key-password", passwordFile.getAbsolutePath(), "Alice ")); + + File certFile = pipeStdoutToFile("cert.asc"); + pipeFileToStdin(keyFile); + assertSuccess(executeCommand("extract-cert")); + + // Write plaintext + File plaintextFile = writeFile("msg.txt", "Hello, World!\n"); + + // Encrypt + File ciphertextFile = pipeStdoutToFile("msg.asc"); + pipeFileToStdin(plaintextFile); + assertSuccess(executeCommand("encrypt", "--profile=rfc4880", certFile.getAbsolutePath())); + + ByteArrayOutputStream decrypted = pipeStdoutToStream(); + pipeFileToStdin(ciphertextFile); + assertSuccess(executeCommand("decrypt", "--with-key-password", passwordFile.getAbsolutePath(), keyFile.getAbsolutePath())); + + assertEquals("Hello, World!\n", decrypted.toString()); + } }