From d4a4ac06ed419221d3a1f967ca3a66b1e163ddb8 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 27 Apr 2022 22:32:36 +0530 Subject: crypto-pgpainless: prepare for error handling (#1877) --- .../aps/crypto/PGPainlessCryptoHandlerTest.kt | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'crypto-pgpainless/src/test/kotlin') diff --git a/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPainlessCryptoHandlerTest.kt b/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPainlessCryptoHandlerTest.kt index 9b4cb664..a9484317 100644 --- a/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPainlessCryptoHandlerTest.kt +++ b/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPainlessCryptoHandlerTest.kt @@ -5,10 +5,14 @@ package dev.msfjarvis.aps.crypto +import com.github.michaelbull.result.Err +import com.github.michaelbull.result.getError +import dev.msfjarvis.aps.crypto.errors.IncorrectPassphraseException import java.io.ByteArrayOutputStream import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse +import kotlin.test.assertIs import kotlin.test.assertTrue class PGPainlessCryptoHandlerTest { @@ -35,6 +39,26 @@ class PGPainlessCryptoHandlerTest { assertEquals(CryptoConstants.PLAIN_TEXT, plaintextStream.toString(Charsets.UTF_8)) } + @Test + fun decryptWithWrongPassphrase() { + val ciphertextStream = ByteArrayOutputStream() + cryptoHandler.encrypt( + listOf(publicKey), + CryptoConstants.PLAIN_TEXT.byteInputStream(Charsets.UTF_8), + ciphertextStream, + ) + val plaintextStream = ByteArrayOutputStream() + val result = + cryptoHandler.decrypt( + privateKey, + "very incorrect passphrase", + ciphertextStream.toByteArray().inputStream(), + plaintextStream, + ) + assertIs>(result) + assertIs(result.getError()) + } + @Test fun canHandleFiltersFormats() { assertFalse { cryptoHandler.canHandle("example.com") } -- cgit v1.2.3