aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/pgpainless/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/pgpainless/src/test')
-rw-r--r--crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt11
1 files changed, 11 insertions, 0 deletions
diff --git a/crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt b/crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt
index 0525c28a..81a666f4 100644
--- a/crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt
+++ b/crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt
@@ -9,6 +9,7 @@ import app.passwordstore.crypto.KeyUtils.tryGetId
import app.passwordstore.crypto.PGPIdentifier.KeyId
import app.passwordstore.crypto.PGPIdentifier.UserId
import app.passwordstore.crypto.errors.KeyAlreadyExistsException
+import app.passwordstore.crypto.errors.KeyDowngradeException
import app.passwordstore.crypto.errors.KeyNotFoundException
import app.passwordstore.crypto.errors.NoKeysAvailableException
import app.passwordstore.crypto.errors.UnusableKeyException
@@ -177,6 +178,16 @@ class PGPKeyManagerTest {
}
@Test
+ fun replaceSecretKeyWithPublicKeyIsRefusedEvenWithReplace() =
+ runTest(dispatcher) {
+ keyManager.addKey(secretKey).unwrap()
+ assertIs<KeyDowngradeException>(keyManager.addKey(publicKey, replace = true).unwrapError())
+ assertIs<KeyDowngradeException>(keyManager.addKey(publicKey, replace = false).unwrapError())
+ // The private key is still the stored one.
+ assertContentEquals(secretKey.contents, keyManager.getAllKeys().unwrap().single().contents)
+ }
+
+ @Test
fun replacePublicKeyWithSecretKey() =
runTest(dispatcher) {
assertTrue(keyManager.addKey(publicKey).isOk)