diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-04-27 22:32:36 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-27 17:02:36 +0000 |
commit | d4a4ac06ed419221d3a1f967ca3a66b1e163ddb8 (patch) | |
tree | 8f501a3443e4fb422a213fc169f198f23e4fc511 /crypto-pgpainless/src/test/kotlin | |
parent | b8b069364289421a875bdc6227c8554161e26183 (diff) |
crypto-pgpainless: prepare for error handling (#1877)
Diffstat (limited to 'crypto-pgpainless/src/test/kotlin')
-rw-r--r-- | crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPainlessCryptoHandlerTest.kt | 24 |
1 files changed, 24 insertions, 0 deletions
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 { @@ -36,6 +40,26 @@ class PGPainlessCryptoHandlerTest { } @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<Err<Throwable>>(result) + assertIs<IncorrectPassphraseException>(result.getError()) + } + + @Test fun canHandleFiltersFormats() { assertFalse { cryptoHandler.canHandle("example.com") } assertTrue { cryptoHandler.canHandle("example.com.gpg") } |