From f08ad35d2e26b3f222cca4f973a865bdd815eeb3 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Tue, 22 Feb 2022 14:33:03 +0530 Subject: Expand tests for multiple identity keys (#1743) --- .../test/kotlin/dev/msfjarvis/aps/crypto/KeyUtilsTest.kt | 2 ++ .../kotlin/dev/msfjarvis/aps/crypto/PGPKeyManagerTest.kt | 15 +++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'crypto-pgpainless') diff --git a/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/KeyUtilsTest.kt b/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/KeyUtilsTest.kt index 80c14254..14ac2263 100644 --- a/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/KeyUtilsTest.kt +++ b/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/KeyUtilsTest.kt @@ -4,6 +4,7 @@ import dev.msfjarvis.aps.crypto.KeyUtils.tryGetId import dev.msfjarvis.aps.crypto.KeyUtils.tryParseKeyring import dev.msfjarvis.aps.crypto.TestUtils.getArmoredPrivateKeyWithMultipleIdentities import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertIs import kotlin.test.assertNotNull import org.bouncycastle.openpgp.PGPSecretKeyRing @@ -18,5 +19,6 @@ class KeyUtilsTest { val keyId = tryGetId(key) assertNotNull(keyId) assertIs(keyId) + assertEquals("b950ae2813841585", keyId.toString()) } } diff --git a/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManagerTest.kt b/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManagerTest.kt index 24b27ef8..650f3d89 100644 --- a/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManagerTest.kt +++ b/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManagerTest.kt @@ -4,10 +4,12 @@ import com.github.michaelbull.result.unwrap import com.github.michaelbull.result.unwrapError import dev.msfjarvis.aps.crypto.GpgIdentifier.KeyId import dev.msfjarvis.aps.crypto.GpgIdentifier.UserId +import dev.msfjarvis.aps.crypto.TestUtils.getArmoredPrivateKeyWithMultipleIdentities import java.io.File import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test +import kotlin.test.assertContentEquals import kotlin.test.assertEquals import kotlin.test.assertIs import kotlin.test.assertNotNull @@ -168,4 +170,17 @@ class PGPKeyManagerTest { val singleKeyList = keyManager.getAllKeys().unwrap() assertEquals(1, singleKeyList.size) } + + @Test + fun testGettingMultipleIdentityKeyWithBothUserIDs() { + scope.runTest { + val key = PGPKey(getArmoredPrivateKeyWithMultipleIdentities()) + keyManager.addKey(key).unwrap() + + val johnKey = keyManager.getKeyById(UserId("john@doe.org")).unwrap() + val janeKey = keyManager.getKeyById(UserId("jane@doe.org")).unwrap() + + assertContentEquals(johnKey.contents, janeKey.contents) + } + } } -- cgit v1.2.3