SOP: Test profile support of encrypt subcommand

This commit is contained in:
Paul Schaub 2023-06-12 14:37:33 +02:00
parent 08ce7c099c
commit ea9b0d68fb
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 28 additions and 0 deletions

View File

@ -546,4 +546,32 @@ public class EncryptDecryptRoundTripTest {
.toByteArrayAndResult()
);
}
@Test
public void encryptWithUnsupportedProfileFails() {
assertThrows(SOPGPException.UnsupportedProfile.class, () -> sop
.encrypt()
.profile("Unknown"));
}
@Test
public void encryptWithSupportedProfileTest() throws IOException {
byte[] encrypted = sop.encrypt()
.profile("rfc4880")
.withCert(bobCert)
.plaintext(message)
.getBytes();
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
.withKey(bobKey)
.ciphertext(encrypted)
.toByteArrayAndResult();
ByteArrayOutputStream decrypted = new ByteArrayOutputStream();
Streams.pipeAll(bytesAndResult.getInputStream(), decrypted);
assertArrayEquals(message, decrypted.toByteArray());
DecryptionResult result = bytesAndResult.getResult();
assertTrue(result.getSessionKey().isPresent());
}
}