aboutsummaryrefslogtreecommitdiff
path: root/crypto-pgpainless/src/test/kotlin
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-11-09 14:48:19 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-11-09 14:59:42 +0530
commitf9d71e827d4f3dd300e044d8cd13bde96fe80e18 (patch)
tree783881a370edf82c0d31d9c1ce50aed261f7f4d6 /crypto-pgpainless/src/test/kotlin
parent53a6007cacfd8ad6dd904f01cce42af1cb56fbb9 (diff)
feat(crypto-pgpainless): add PGPKeyManager test for keys with shared email
Diffstat (limited to 'crypto-pgpainless/src/test/kotlin')
-rw-r--r--crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt37
1 files changed, 37 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 b491206b..1bb8553c 100644
--- a/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt
+++ b/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt
@@ -17,6 +17,7 @@ import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
import kotlin.test.assertIs
+import kotlin.test.assertNotEquals
import kotlin.test.assertNotNull
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -225,4 +226,40 @@ class PGPKeyManagerTest {
assertIs<Err<KeyAlreadyExistsException>>(keyManager.addKey(secretKey))
}
}
+
+ @Test
+ fun addMultipleKeysWithSameEmail() {
+ scope.runTest {
+ val alice =
+ PGPKey(this::class.java.classLoader.getResource("alice_owner@example_com")!!.readBytes())
+ val bobby =
+ PGPKey(this::class.java.classLoader.getResource("bobby_owner@example_com")!!.readBytes())
+ assertIs<Ok<PGPKey>>(keyManager.addKey(alice))
+ assertIs<Ok<PGPKey>>(keyManager.addKey(bobby))
+
+ keyManager.getAllKeys().apply {
+ assertIs<Ok<List<PGPKey>>>(this)
+ assertEquals(2, this.value.size)
+ }
+
+ val longKeyIds =
+ arrayOf(
+ KeyId(-7087927403306410599), // Alice
+ KeyId(-961222705095032109), // Bobby
+ )
+ val userIds =
+ arrayOf(
+ UserId("Alice <owner@example.com>"),
+ UserId("Bobby <owner@example.com>"),
+ )
+
+ for (idCollection in arrayOf(longKeyIds, userIds)) {
+ val alice1 = keyManager.getKeyById(idCollection[0])
+ val bobby1 = keyManager.getKeyById(idCollection[1])
+ assertIs<Ok<PGPKey>>(alice1)
+ assertIs<Ok<PGPKey>>(bobby1)
+ assertNotEquals(alice1.value.contents, bobby1.value.contents)
+ }
+ }
+ }
}