mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-09-02 23:35:08 +00:00
Add missing asserts to PGPainlessCryptoHandler tests (#2010)
Add missing asserts
This commit is contained in:
@@ -7,6 +7,7 @@ package app.passwordstore.crypto
|
|||||||
|
|
||||||
import app.passwordstore.crypto.errors.IncorrectPassphraseException
|
import app.passwordstore.crypto.errors.IncorrectPassphraseException
|
||||||
import com.github.michaelbull.result.Err
|
import com.github.michaelbull.result.Err
|
||||||
|
import com.github.michaelbull.result.Ok
|
||||||
import com.github.michaelbull.result.getError
|
import com.github.michaelbull.result.getError
|
||||||
import com.google.testing.junit.testparameterinjector.TestParameter
|
import com.google.testing.junit.testparameterinjector.TestParameter
|
||||||
import com.google.testing.junit.testparameterinjector.TestParameterInjector
|
import com.google.testing.junit.testparameterinjector.TestParameterInjector
|
||||||
@@ -35,29 +36,35 @@ class PGPainlessCryptoHandlerTest {
|
|||||||
@Test
|
@Test
|
||||||
fun encryptAndDecrypt() {
|
fun encryptAndDecrypt() {
|
||||||
val ciphertextStream = ByteArrayOutputStream()
|
val ciphertextStream = ByteArrayOutputStream()
|
||||||
|
val encryptRes =
|
||||||
cryptoHandler.encrypt(
|
cryptoHandler.encrypt(
|
||||||
encryptionKey.keySet,
|
encryptionKey.keySet,
|
||||||
CryptoConstants.PLAIN_TEXT.byteInputStream(Charsets.UTF_8),
|
CryptoConstants.PLAIN_TEXT.byteInputStream(Charsets.UTF_8),
|
||||||
ciphertextStream,
|
ciphertextStream,
|
||||||
)
|
)
|
||||||
|
assertIs<Ok<Unit>>(encryptRes)
|
||||||
val plaintextStream = ByteArrayOutputStream()
|
val plaintextStream = ByteArrayOutputStream()
|
||||||
|
val decryptRes =
|
||||||
cryptoHandler.decrypt(
|
cryptoHandler.decrypt(
|
||||||
privateKey,
|
privateKey,
|
||||||
CryptoConstants.KEY_PASSPHRASE,
|
CryptoConstants.KEY_PASSPHRASE,
|
||||||
ciphertextStream.toByteArray().inputStream(),
|
ciphertextStream.toByteArray().inputStream(),
|
||||||
plaintextStream,
|
plaintextStream,
|
||||||
)
|
)
|
||||||
|
assertIs<Ok<Unit>>(decryptRes)
|
||||||
assertEquals(CryptoConstants.PLAIN_TEXT, plaintextStream.toString(Charsets.UTF_8))
|
assertEquals(CryptoConstants.PLAIN_TEXT, plaintextStream.toString(Charsets.UTF_8))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun decryptWithWrongPassphrase() {
|
fun decryptWithWrongPassphrase() {
|
||||||
val ciphertextStream = ByteArrayOutputStream()
|
val ciphertextStream = ByteArrayOutputStream()
|
||||||
|
val encryptRes =
|
||||||
cryptoHandler.encrypt(
|
cryptoHandler.encrypt(
|
||||||
encryptionKey.keySet,
|
encryptionKey.keySet,
|
||||||
CryptoConstants.PLAIN_TEXT.byteInputStream(Charsets.UTF_8),
|
CryptoConstants.PLAIN_TEXT.byteInputStream(Charsets.UTF_8),
|
||||||
ciphertextStream,
|
ciphertextStream,
|
||||||
)
|
)
|
||||||
|
assertIs<Ok<Unit>>(encryptRes)
|
||||||
val plaintextStream = ByteArrayOutputStream()
|
val plaintextStream = ByteArrayOutputStream()
|
||||||
val result =
|
val result =
|
||||||
cryptoHandler.decrypt(
|
cryptoHandler.decrypt(
|
||||||
|
Reference in New Issue
Block a user