From f9d71e827d4f3dd300e044d8cd13bde96fe80e18 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 9 Nov 2022 14:48:19 +0530 Subject: feat(crypto-pgpainless): add PGPKeyManager test for keys with shared email --- .../app/passwordstore/crypto/PGPKeyManagerTest.kt | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'crypto-pgpainless/src/test/kotlin') 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>(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>(keyManager.addKey(alice)) + assertIs>(keyManager.addKey(bobby)) + + keyManager.getAllKeys().apply { + assertIs>>(this) + assertEquals(2, this.value.size) + } + + val longKeyIds = + arrayOf( + KeyId(-7087927403306410599), // Alice + KeyId(-961222705095032109), // Bobby + ) + val userIds = + arrayOf( + UserId("Alice "), + UserId("Bobby "), + ) + + for (idCollection in arrayOf(longKeyIds, userIds)) { + val alice1 = keyManager.getKeyById(idCollection[0]) + val bobby1 = keyManager.getKeyById(idCollection[1]) + assertIs>(alice1) + assertIs>(bobby1) + assertNotEquals(alice1.value.contents, bobby1.value.contents) + } + } + } } -- cgit v1.2.3