From bbbcc76d6562531502ffc4db7831ab34acddbacf Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 21 Feb 2022 20:12:19 +0530 Subject: Add failing test for multiple identities (#1741) --- .../dev/msfjarvis/aps/crypto/KeyUtilsTest.kt | 22 ++++++++++++++++++++++ .../kotlin/dev/msfjarvis/aps/crypto/TestUtils.kt | 5 +++++ 2 files changed, 27 insertions(+) create mode 100644 crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/KeyUtilsTest.kt (limited to 'crypto-pgpainless/src/test/kotlin') 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 new file mode 100644 index 00000000..80c14254 --- /dev/null +++ b/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/KeyUtilsTest.kt @@ -0,0 +1,22 @@ +package dev.msfjarvis.aps.crypto + +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.assertIs +import kotlin.test.assertNotNull +import org.bouncycastle.openpgp.PGPSecretKeyRing + +class KeyUtilsTest { + @Test + fun `parse GPG key with multiple identities`() { + val key = PGPKey(getArmoredPrivateKeyWithMultipleIdentities()) + val keyring = tryParseKeyring(key) + assertNotNull(keyring) + assertIs(keyring) + val keyId = tryGetId(key) + assertNotNull(keyId) + assertIs(keyId) + } +} diff --git a/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/TestUtils.kt b/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/TestUtils.kt index ab9b6bf1..d002180d 100644 --- a/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/TestUtils.kt +++ b/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/TestUtils.kt @@ -2,10 +2,15 @@ * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. * SPDX-License-Identifier: GPL-3.0-only */ +@file:Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") package dev.msfjarvis.aps.crypto object TestUtils { fun getArmoredPrivateKey() = this::class.java.classLoader.getResource("private_key").readBytes() fun getArmoredPublicKey() = this::class.java.classLoader.getResource("public_key").readBytes() + fun getArmoredPrivateKeyWithMultipleIdentities() = + this::class.java.classLoader.getResource("private_key_multiple_identities").readBytes() + fun getArmoredPublicKeyWithMultipleIdentities() = + this::class.java.classLoader.getResource("public_key_multiple_identities").readBytes() } -- cgit v1.2.3